edu.colorado.simulations
Class Clock

java.lang.Object
  extended by edu.colorado.simulations.Clock
Direct Known Subclasses:
Clock24, CuckooClock

public class Clock
extends java.lang.Object

A 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

See Also:
CuckooClock, Clock24

Constructor Summary
Clock()
          Construct a Clock that is initially set to midnight.
 
Method Summary
 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>
boolean
someMorning(java.util.Vector<T> clocks)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Clock

public Clock()
Construct a Clock that is initially set to midnight.

Parameters:
- - none
Postcondition:
This Clock has been initialized with an initial time of midnight.
Method Detail

advance

public void advance(int minutes)
Move this Clock's time by a given number of minutes.

Parameters:
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.

earlier

public static boolean earlier(Clock c1,
                              Clock c2)
Test whether the time on one clock is earlier than the time on another.

Parameters:
c1 - a Clock
c2 - another Clock
Returns:
Returns 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.

getHour

public int getHour()
Get the current hour of this Clock.

Parameters:
- - none
Returns:
the current hour (always in the range 1...12)

getMinute

public int getMinute()
Get the current minute of this Clock.

Parameters:
- - none
Returns:
the current minute (always in the range 0...59)

isMorning

public boolean isMorning()
Check whether this Clock's time is before noon.

Parameters:
- - none
Returns:
If this 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.

setTime

public void setTime(int hour,
                    int minute,
                    boolean morning)
Set the current time of this Clock.

Parameters:
hour - the hour to set this Clock to
minute - the minute to set this Clock to
morning - 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.
Throws:
java.lang.IllegalArgumentException - Indicates that the hour or minute is illegal.

someMorning

public static <T extends Clock> boolean someMorning(java.util.Vector<T> clocks)