|
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
double weight = 10; boolean enjoysAnts = true; double mph = 30; String guess; if (weight > 100) { if (enjoysAnts) { guess = "aardvark"; } else { guess = "buffalo"; } } else { if (mph > 30) { guess = "cheetah"; } else { guess = "dik-dik"; } } |
boolean outOfBounds( int i ) { return ((i < 0) || (i >= 100)); } |
An easier way to print the documentation has been discovered: In BlueJ, from the project window, choose Tools > Project Documentation…. This will open a browser which is viewing the desired page; from there you can print. (Note that BlueJ can't generate documentation if your program isn't proper Java syntax, so you'll have to include stub function-bodies, so that your code at least compiles.)
We enter the world of competitive volleyball; for this problem make new class VolleyballJudge.
The method hasFirstTeamWon takes in two volleyball scores, and returns a true/false answer: whether or not the first team has won — that is, whether the score represents a completed game and the first team has a higher score. (So if hadFirstTeamWin returns false, it means that either the first team lost or the game is still be continuing.)
In volleyball, you keep playing until one team reaches 21 (or more) points, and the difference between the scores is two or more (that is, you can't win by just one point, and there are never ties).
vj.announceWinner( "beachfront boppers", 21, "valley volleyers", 15 ) = "beachfront boppers won!" vj.announceWinner( "beachfront boppers", 15, "valley volleyers", 21 ) = "valley volleyers won!" vj.announceWinner( "beachfront boppers", 21, "valley volleyers", 20 ) = "game still in progress." |
1 It is mildly unsatisfying, aesthetically, that we hand the judge four independent inputs, even though really we have in mind two name/score pairs. We'd prefer to somehow bundle together the name and score of each team, and then just hand the judge those two bundles. Don't worry, we'll see how to bundle related information together in a weeks 5-6. ↩
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
©2007, Ian Barland, Radford University Last modified 2007.Sep.16 (Sun) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |