public class Clock
extends java.lang.Object
Clock
object holds one instance of a time value shuch as
9:48 P.M.
Java Source Code for this class:
http://www.cs.colorado.edu/~main/edu/colorado/simulations/Clock.java
CuckooClock
,
Clock24
Constructor and Description |
---|
Clock()
Construct a
Clock that is initially set to midnight. |
Modifier and Type | Method and Description |
---|---|
void |
advance(int minutes)
Move this
Clock 's time by a given number of minutes. |
static boolean |
earlier(Clock c1,
Clock c2)
Test whether the time on one clock is earlier than the time on another.
|
int |
getHour()
Get the current hour of this
Clock . |
int |
getMinute()
Get the current minute of this
Clock . |
boolean |
isMorning()
Check whether this
Clock 's time is before noon. |
void |
setTime(int hour,
int minute,
boolean morning)
Set the current time of this
Clock . |
static <T extends Clock> |
someMorning(java.util.Vector<T> clocks) |
public Clock()
Clock
that is initially set to midnight.
Postcondition:
This Clock
has been initialized with an initial time of
midnight.public void advance(int minutes)
Clock
's time by a given number of minutes.minutes
- the amount to move this Clock
's time
Postcondition:
This Clock
's time has been moved forward by the indicated
number of minutes. Note: A negative argument moves this
Clock
backward.public static boolean earlier(Clock c1, Clock c2)
c1
- a Clock
c2
- another Clock
true
if the time on c1
is earlier
than the time on c2
over a usual day (starting at midnight
and continuing through 11:59 P.M.); otherwise returns false
.public int getHour()
Clock
.public int getMinute()
Clock
.public boolean isMorning()
Clock
's time is before noon.Clock
's time lies from 12:00 midnight
to 11:59 A.M. (inclusive), then the return value is
true
; otherwise the return value is false
.public void setTime(int hour, int minute, boolean morning)
Clock
.hour
- the hour to set this Clock
tominute
- the minute to set this Clock
tomorning
- indication of whether the new time is before noon
Postcondition:
This Clock
's time has been set to the given hour and
minute (using the usual 12-hour notation). If the third parameter,
morning
, is true
, then this time is from
12:00 midnight to 11:59 A.M. Otherwise this time is from 12:00 noon
to 11:59 P.M.java.lang.IllegalArgumentException
- Indicates that the hour
or minute
is illegal.public static <T extends Clock> boolean someMorning(java.util.Vector<T> clocks)