Java Reference
In-Depth Information
window appears, asking the player for the hours shown on the clock. If the play-
er types the wrong number, a window appears that says so, and the player is
asked to hit one of the buttons. If the player types the right number, a window
appears that says so and the score is incremented. When the player hits the OK
button, the time on the clock is changed to a new random time and the player is
again asked to type in the number of hours. The game continues in this fashion.
We explain the level.
Level 1 . The player is asked only for hours, and the clock always shows 0
minutes. At the other levels, the player is asked for the hours and then for
the minutes.
Level 2. The clock shows 0 , 15 , 30 , or 45 minutes.
Level 3. The clock shows minutes that are a multiple of 5 .
Level 4. The clock shows any minute in the range 0..59 .
The level is incremented whenever the score reaches a multiple of 5 and the level
is still less than 4 .
This ends the description of the game.
Identifying the objects of the game
We write down noun phrases that identify objects of the problem domain.
We can think of a clock , which has a time . The clock has a face , a minute hand ,
and an hour hand .
There is a player . The player has a name , has a score , and is playing at a par-
ticular level .
The text that appears under the clock is an object; we call it the player sta-
tus . And the whole window that contains the clock and status is an object; we call
it the clock window .
The game itself is an object; we call it the clock game .
/** An instance is a clock with a time, painted on a canvas */
public class Clock extends Canvas {
/** Constructor: a clock with time t */
public Clock(Time t) { }
/** = the time on the clock */
public Time getTime()
{ return null ; }
/** Set the clock time to t */
public void setTime(Time t) { }
/** Paint the clock using g*/
public void paint(Graphics g) { }
Figure 3.10:
Specification of class Clock
Search WWH ::

Custom Search