RU beehive logo ITEC dept promo banner
ITEC 120
2007fall
ibarland,
jdymacek

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs

hw03
booleans, if
volleyball

Part (a), due Sep.07 (Fri):

Instructions: Submit on paper, at start of class(lab). (No Blackboard submission required, for (a).)
  1. Give a Java expression which determines whether the square-root of ten is bigger than (the named constant) Math.PI.
  2. In the lecture notes, how many open-curly-braces (‘{’) are part of an if-else statement?
  3. What does the following snippet initialize guess to?
    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";
        }
      }
    
    (Coloring is provided to help you see the structure.)
  4. Give the signature for a method isPrime which takes in an integer and returns whether or not it is a prime number.
  5. If startPage and endPage are both ints, write an expression which captures...
    1. endPage minus startPage is at least 5”.
    2. endPage minus startPage is at least 5, and endPage is at least 100”.
  6. true or false?: The following function compiles:
    boolean outOfBounds( int i ) {
      return ((i < 0) || (i >= 100));
      }
    
    What does this outOfBounds return, if given ...
    1. -50
    2. 0
    3. 50
    4. 100
    5. 150

Part (b), due Sep.10 (Mon):

Instructions: turn in a hard-copy of the html-documentation for the following functions (including test cases), and electronically submit (on WebCT) a copy of either the html file or the java file.

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.

  1. 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).

  2. The method isGameOver takes in two volleyball scores, and determines whether the game is still in progress.
    In your implementation (part (c)), call hadFirstTeamWin. (Hint: call it twice — perhaps with the inputs in a different order.)
  3. The method announceWinner takes in four inputs — a team's name, their current score, the opposing team's name, and the opposing team's score.1 Here are three test cases (assuming that vj is some instance of class VolleyballJudge):
    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."
    
    Include at least one additional test case, and make sure it involves a particularly simple input. (Hint: is the empty string ever a legal team name? Is 0 ever a legal volleyball score?)

Part (c), due Sep.12 (Wed):

Instructions: Write implementations of the functions above, and test your code. Turn in your Java source file for the functions, both hardcopy and in Blackboard > Assignments > hw03b > attach files.

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.      

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs


©2007, Ian Barland, Radford University
Last modified 2007.Sep.16 (Sun)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme