// CounterDriver.java // Written by DLK, based on an example in Decker and Hirshfield. // Modified and converted to Java by Scot Drysdale. // A driver program to exercise the Counter class. // Modified for SA 5 by THC. public class CounterDriver { public static void main(String args[]) { // Create variables that can reference two Counters. Counter c1, c2; c1 = new Counter(5); // Wraps at 5 c2 = new Counter(12); // Wraps at 12 final int TIMES = 50; // Show lots of Counter values. for (int i = 0; i < TIMES; i++) { c1.show(); // Print the value of the first Counter System.out.print("\t"); // A tab character between the Counters c2.show(); // Print the value of the second Counter System.out.println(); // Tick both Counters. c1.tick(); c2.tick(); } // Since the Counter referenced by c1 has limit 5 and we've ticked it 50 times, // it now has the value 0. c1.advance(3); // positive advance, no wraparound: value goes to 3 c1.show(); System.out.println(); c1.advance(6); // positive advance, with wraparound: value goes to 4 c1.show(); System.out.println(); c1.advance(-2); // negative advance, no wraparound: value goes to 2 c1.show(); System.out.println(); c1.advance(-4); // negative advance, with wraparound: value goes to 3 c1.show(); System.out.println(); } }