![]() |
![]() |
|
home—info—lects—labs—exams—hws
tutor/PIs—java.lang docs—java.util docs
Due at the start of class Nov.03 (Wed).
We enter the world of competitive volleyball; for this problem make
new
(4pts)
Write a method
(4pts)
Make a second, overloaded version of
(You don't need test cases for this.)
This function should call the previous version,
To make a random choice,
construct a
Extra credit:
Make the odds of winning a point proportional to the number of
vowels2in the team's name.
For example, if “Team VB!” (two vowels) plays
“Over the Top” (four vowels),
the probability3of the first team scoring is only 2/(2+4) = 1/3.
Be sure to use particularly good use of (tested) helper functions
if going for extra-credit points.
(4pts)
Write a method
In volleyball, a game is over when
one team reaches 21 (or more) points,
and the difference between the scores
is two or more
(that is: there are never ties, and you can't win by just one point).
Hint: some people use
Include sufficient test cases, including one for each type of unusual situation (“corner case”) you can think of.
(4pts)
The method
Since your code calls methos that are previously-tested (and are thus known to be correct), 3 test cases will suffice here.
(4pts)
Finally: write a function which
plays n games, and returns the fraction of times
the first team wins.
(We expect the answer to be around 0.5,
but of course it won't be exactly that.)
(4pts) As test cases, have your program print out the following table. Note that each time you run it, the table might give different results. Paste the result of three different runs into your program file (as a comment).
n | fraction of first-team wins | distance from 0.5 |
10 | ||
100 | ||
1000 | ||
10000 | ||
100000 |
Here is an example of somebody using the class:
vg = new VolleyballGame( "beachfront boppers", "valley volleyers" ); // At this point the score is 0-0. System.out.println( "Expect: " + "Game still in progress." ); System.out.println( "Actual: " + vg.makeAnnouncement() ); vg.playOnePoint(); // At this point the score is either 0-1 or 1-0 vg.playOnePoint(); // At this point the score is either 0-2, 1-1, or 2-0. vg.playManyPoints(18); // At this point, twenty points have been played: System.out.println( "Expect: " + "Game still in progress." ); System.out.println( "Actual: " + vg.makeAnnouncement() ); vg.playOnePoint(); System.out.println( "Expect most likely, unless somebody got skunked: " + "Game still in progress." ); System.out.println( "Actual: " + vg.makeAnnouncement() ); vg.playUntilOver(); System.out.println( "Expect that one side has definitely won: " ); System.out.println( "Actual: " + vg.makeAnnouncement() ); |
Expect: Game still in progress. Actual: Game still in progress. Expect: Game still in progress. Actual: Game still in progress. Expect: Game still in progress. Expect most likely, unless somebody got skunked: Game still in progress. Actual: Game still in progress. Expect that one side has definitely won: Actual: valley volleyers won! |
These aren't really test cases. In fact, it becomes difficult to test the nuances of testing whether a game is over (esp. when overtime is entered). I highly recommend writing some extra methods to test this. (For example, I made another constructor which took in two mid-game scores as well as the team names; then I could test my methods.)
1
2 It is left to your discretion, whether ‘Y’ counts as a vowel. ↩
3 If the probability is 2/(2+4), we say the odds are 2:4; so yes technically the odds really are proportional to the number of vowels, even though the probability isn't proportional. ↩
home—info—lects—labs—exams—hws
tutor/PIs—java.lang docs—java.util docs
©2010, Ian Barland, Radford University Last modified 2010.Nov.23 (Tue) |
Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |
![]() |