previous | start | next

Example Class Type I

A StopWatch could be an concrete object in some application/problem context.

public class StopWatch {

  /* private instance members */
  private double start;

  /* public instance methods */
  /**
   * Initialize this stopwatch start time to present time
   */
  public StopWatch()
  {
    start = System.currentTimeMillis();
  }
        
  /**
   * Reset this stopwatch to the present time
   */
  public void reset()
  {
    start = System.currentTimeMillis();
  }
        
  /**
   * Returns the elapsed time in milliseconds since this 
   * stopwatch was created or since it was reset.
   */
  public double elapsedTime()
  {
    double now = System.currentTimeMillis();
    return (now - start);
  }
}


previous | start | next