All Packages Class Hierarchy This Package Previous Next Index
Class structure.Clock
java.lang.Object
|
+----structure.Clock
- public class Clock
- extends Object
A simple object for measuring time.
This Clock allows one to measure time between events. Events may be
from several milliseconds to several seconds apart. When measuring
events that take considerable time (> 1/10th of a second) it is important
to counteract the effect of scheduling of other system processes.
A Clock has the following operations:
- reset - clear the clock and reset accumulated time to zero
- start - start the clock and accumulate time
- stop - stop the clock (and therefore stop accumulating time)
- read - read a stopped clock to get accumulated time in milliseconds.
typical use:
Clock timer = new Clock();
timer.start();
for (i = 0; i < 100000; i++);
timer.stop();
System.out.println("Time to count to 100000: "+timer.read()+" seconds.");
Clock()
- Constructs a stopwatch for timing events to the milliseconds.
read()
- Read the value on the stop watch.
reset()
- Resets the time on the clock to zero.
start()
- Start the clock running.
stop()
- Stop the clock.
toString()
- Generates string representation of clock.
Clock
public Clock()
- Constructs a stopwatch for timing events to the milliseconds.
- Postcondition:
- returns a stopped clock
start
public void start()
- Start the clock running.
- Postcondition:
- clock is stopped
- Precondition:
- starts clock, begins measuring possibly accumulated time
stop
public void stop()
- Stop the clock. Time does not accumulate.
- Precondition:
- clock is running
- Postcondition:
- stops clock, and accumulates time
read
public double read()
- Read the value on the stop watch.
- Precondition:
- clock is stopped.
- Postcondition:
- returns the accumulated time on the clock
- Returns:
- A double representing the number of seconds elapsed.
reset
public void reset()
- Resets the time on the clock to zero.
- Postcondition:
- stops running clock and clears the accumulated time.
toString
public String toString()
- Generates string representation of clock.
- Postcondition:
- returns a string representation of the clock
- Returns:
- A string representing this clock.
- Overrides:
- toString in class Object
All Packages Class Hierarchy This Package Previous Next Index