RU beehive logo ITEC dept promo banner
ITEC 120
2008spring
ibarland,
jdymacek

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs

hw03
booleans, if
volleyball

Part (a), due Feb.01 (Fri):

Instructions: Submit on paper, at start of class(lab). (No Blackboard submission required, for (a).)
  1. (1pt) What does it mean, if a returned homework is marked with...
    1. The proof-reading mark “”?
    2. τ (the greek letter tau)?
    (The homeworks page has a link to grading abbreviations, as well as common proofreading notations.)
  2. (1pt)
    1. Declare a local variable of type double, named dinnerPrice.                                         
    2. Then, as a separate statement, initialize dinnerPrice to be 7.5.                                         
  3. (1pt)
    1. Declare a local variable of type String, named royalTitle.                 
    2. Then, as a separate statement, initialize royalTitle to be "Her Royal Highness".                 
  4. (5pts) For the code below, which line number(s)…
    1. declare a function (that is, include a signature)?
    2. call a function? (that is, have an object-dot-methodname-openParen-arguments).
    3. declare a local variable?
    4. initialize a local variable?
    5. Use the value stored in a local variable1?
    6. Use the value stored in a parameter?
    (Each answer will be a list of numbers, e.g. “b. 7, 12.”)
     1    /** Calculate the are of *crust* on a pizza, given its diameter.
     2     *  Krusteaze pizza has 3" of crust all the way around.
     3     * @param diam The diameter of the pizza (in inches); must be 6 or more.
     4     * @return The amount of crust (in square inches)
     5     *  p.crustArea( 6) = p.pizzaArea( 6) - p.toppingArea( 6) =~  28.26
     6     *  p.crustArea(12) = p.pizzaArea(12) - p.toppingArea(12) =~  84.78
     7     *  p.crustArea(20) = p.pizzaArea(20) - p.toppingArea(20) =~ 160.14
     8     */
     9    double crustArea( double diam ) {
    10      double totalArea;
    11      totalArea = this.pizzaArea(diam);
    12  
    13      double innerArea;
    14      innerArea = this.toppingArea(diam);
    15  
    16      return (totalArea - innerArea);
    17      }
  5. (1pt) Give a Java expression which determines whether the square-root of ten is bigger than (the named constant) Math.PI.
  6. (1pt) Give the signature for a method isPrime which takes in an integer and returns whether or not it is a prime number.

Part (b), due Feb.04 (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 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.2 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 Feb.06 (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.

1Remember that while “local variable” and “parameter” are very similar concepts, they are technically different from each other.      

2 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


©2008, Ian Barland, Radford University
Last modified 2008.Feb.06 (Wed)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme