/*
  Designed to support the timing of events. For example, it 
  could be used to measure the running time of a piece of code as 
  is done below in main.
*/
public class StopWatch {
    private long startTime;
    private long stopTime;

    public void start() {
	startTime = System.currentTimeMillis();
    }

    public void stop() {
	stopTime = System.currentTimeMillis();
    }

    public long elapsed() {
	return stopTime - startTime;
    }

    public String toString() {
	return this.elapsed() + "";
    }

    public static void main(String[] args) {
	StopWatch timer;
	int i = 0;

	timer = new StopWatch();
	System.out.println("Calculate the time it takes to execute a loop" +
			   " 10000 times");
	timer.start();
	while (i < 10000) {
	    i = i + 1;
	}
	timer.stop();
	System.out.println(timer);
    }
}
