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:

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.");


Constructor Index

 o Clock()
Constructs a stopwatch for timing events to the milliseconds.

Method Index

 o read()
Read the value on the stop watch.
 o reset()
Resets the time on the clock to zero.
 o start()
Start the clock running.
 o stop()
Stop the clock.
 o toString()
Generates string representation of clock.

Constructors

 o Clock
public Clock()
Constructs a stopwatch for timing events to the milliseconds.

Postcondition:
returns a stopped clock

Methods

 o start
public void start()
Start the clock running.

Postcondition:
clock is stopped
Precondition:
starts clock, begins measuring possibly accumulated time

 o stop
public void stop()
Stop the clock. Time does not accumulate.

Precondition:
clock is running
Postcondition:
stops clock, and accumulates time

 o 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.
 o reset
public void reset()
Resets the time on the clock to zero.

Postcondition:
stops running clock and clears the accumulated time.

 o 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