Java Reference
In-Depth Information
Time t= new Time(5, 32);
Clock c= new Clock(t);
ClockWindow g= new ClockWindow(c, " test status ");
Designing the player and the game
Earlier, we identified these objects:
clock, time, face, minute hand, hour hand
player, name, score, level
label, clock window, clock game, input dialog box
We have taken care of those that have to do with the clock, time, and clock win-
dow, and we now design classes for those dealing with the player and the game
as a whole.
/** An instance is a time (hours and minutes) */
public class Time {
/** The number of hours in the time. */
private int hours;
/** The number of minutes in the time. */
private int minutes;
/** Constructor: an instance with h hours, m minutes */
public Time( int h, int m) {
hours= h;
minutes= m;
}
/** = the hours of this time */
public int getHours()
{ return hours; }
/** = the minutes of this time */
public int getMinutes()
{ return minutes; }
/** = a representation " hours:minutes " of this Time */
public String toString()
{ return hours + ":" + minutes; }
/** = this Time equals t */
public boolean equals(Time t)
{ return this.hours == t.hours && this.minutes == t.minutes; }
}
Figure 3.13:
Class Time
Search WWH ::




Custom Search