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

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs

hw05
fields
recording game results

Part (a)

Due Sep.21 (Fri): only hardcopy is needed.

  1. true or false?: Suppose PizzaServers have a field for their salary. If there are seven PizzaServer objects (instances), then there are seven different boxes labeled “salary” (one inside each object).
  2. For each of the following, indicate whether it's most appropriate to use a field (“f”), a named constant (“nc”), or a local variable (“lv”).
    1.                  A PizzaServer's social security number.
    2.                  the amount of topping on the pizza in a call to crustArea.
    3.                  The total number of hours ever worked by a PizzaServer.
    4.                  The diameter of an Extra-extra-large pizza, at Krusteaze Pizza Korp.
  3. A field is declared inside of                 , but outside of any                 .
  4. How many parameters does a setter method have?                 
  5. How many parameters does a getter method have?                 
  6. The Java keyword “void” can be used in the place of an actual type when you…
    1. declare a parameter
    2. specify a method's return type
    3. declare a local variable
    4. initialize a local variable
    (Circle zero or more, appropriately.)
  7. We've been drawing objects on the board as follows (reminiscent of BlueJ's "inspection" window for objects); here's a a before-and-after “snapshot”:
    A brand-new PizzaServer:               That same server, after calling:
                                                   work(10); 
                                                   setSalary(8.0);
                                                   work(1);
        PizzaServer                         PizzaServer                 
        +-----------------------+          +-----------------------+  
        |            _________  |          |            _________  | 
        |  salary   |___5.75__| |          |  salary   |___8.0___| | 
        |            _________  |          |            _________  |  
        |  balance  |____0.0__| |          |  balance  |__65.5___| | 
        |              _______  |          |              _______  |  
        |  isManager  |_false_| |          |  isManager  |_false_| | 
        |                       |          |                       |  
        +-----------------------+          +-----------------------+ 
    
    After sneaking a peek at the first five bullets for part hw05b below...
    1. Draw a picture for a brand new TeamStats object (“before”).
    2. Draw a second, “after” picture of what that same TeamStats object looks like after the two method-calls
      recordGame(true);
      recordGame(false);
      .
    Note that the name of the class is above your box, and the variable referring to the object (such as “jo”) is not included in the picture at all.

Part (b)

Due Sep.24 (Mon): You'll turn in two printouts: The html as usual (via Tools >Project Documentation), and double-click on your test class and print out that (auto-generated) code.

Part (c)

Due Sep.26 (Wed): implementation (Java code). Turn in hardcopy as usual.

Your code should use getters and setters, but not access any fields directly2.

Extra Credit

Due with the other work — Sep.24 (documentation & tests) and Sep.26 (implementation).

  1. Write a version of recordGame which accepts two inputs: the team's score and the opposing team's score. Note that this suddenly makes it possible to record ties, which means you might need to add another field to your class.
    You can update toString to include this info, if you like.
  2. Write a method winningPercentage which returns a number between 0.0 and 100.0 (inclusive).3 4

1Note that in a void method it's actually allowable to write “return;” (note the lack of expression before the semicolon).      

2except for the getters and setters themselves, of course.      

3 If no games have been played, the winning percentage does not exist. In that case it's reasonable to return “not a number” — Double.NaN — which is already the result of 0.0/0.0 (but not the result of 0/0).      

4Recall that you can convert an int m to a double either by casting — “(double)m” — or by calling functions: “(new Integer(m)).doubleValue()”. (Casting is easier to type, but its syntax is an off-the-wall way to just call a function.)      

homeinfoexamslectureslabshws
RecipeLawsliessyntaxjava.lang docsjava.util docs


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