// CounterDriver.java // Written by THC to exercise the Counter class for Short Assignment #6. public class CounterDriver { public static void main(String args[]) { // Create variables that can reference four Counters. Counter c1 = null, c2 = null, c3 = null, c4 = null; c1 = new Counter(); // Wraps at 10, shows 1 digit c2 = new Counter(12); // Wraps at 12, shows 2 digits c3 = new Counter(12, 4); // Wraps at 12, shows 4 digits c4 = new Counter(12, 1); // Wraps at 12, shows 2 digits even though we ask for only 1 final int TIMES = 50; for (int i = 0; i < TIMES; i++) { // Show lots of Counter values, separated by tabs c1.show(); // Print the value of the first Counter System.out.print("\t"); c2.show(); // Print the value of the second Counter System.out.print("\t"); c3.show(); // Print the value of the third Counter System.out.print("\t"); c4.show(); // Print the value of the fourth Counter System.out.println(); // Tick all four Counters. c1.tick(); c2.tick(); c3.tick(); c4.tick(); } // Now for some getting of values and resetting. // These method calls should work. System.out.println("\n\nThe current value of c2 is " + c2.getValue()); c2.reset(5); System.out.println("\n\nThe new value of c2 is " + c2.getValue()); // And this method call should not. c2.reset(12); System.out.println("\n\nThe ultimate value of c2 is " + c2.getValue()); // Test toString. System.out.print(c2); // Should be the same as c2.show() System.out.println(); // Now test the constructor that makes a copy of a Counter. c3 = new Counter(c2); c3.tick(); System.out.println("\n\nAfter ticking c3, the value is " + c3 + " but the value of c2 is " + c2); } }