/** * This second class will be called Counter, and this class will use three * instances of the Digit class to represent the odometer. * * Author John Sloan * Date: January 28, 2008. */ public class Counter { // We are using the class Digit to define the type. private Digit units; // We are using the class Digit to define the type. private Digit tens; // We are using the class Digit to define the type. private Digit hundreds; /** * The Constructor of this class will initialize the fields above by calling * the the constructor of Digit class in conjuction with the new operator. */ public Counter() { // initialising field by calling the constructor of digit class. units = new Digit(); // initialising field by calling the constructor of digit class. tens = new Digit(); // initialising field by calling the constructor of digit class. hundreds = new Digit(); } /** * This method uses a local variable (String displayString) to store the expression * into the identifier and print it to the terminal window. */ public void display () { //local varaiable. String displayString; //assignmnet staement storing expression into identifier. displayString = "Current Value: " + hundreds + tens + units; //printing contents of identifier to the terminal window. System.out.println ( displayString ); } /** * This method forces the units, tens, and hundreds to increment themselves * It is the most complex method of our assignment so far. I had to refwer back to Digit * class the make the "V" in get value a capital V to correct my error. * This is method is a nested if method. */ public void increment () { units.increment (); if ( units.getValue () == 0 ) { tens.increment (); if ( tens.getValue () == 0) { hundreds.increment (); } } } /** * This method uses a loop to call the increment method * many times. The number of times increment is called * is passed in as a parameter. */ public void increment( int numberOfTimes ) { while ( numberOfTimes > 0 ) { increment (); numberOfTimes = numberOfTimes - 1; } } /** This is a simple reste method used to reset the values displayed * in the terminal window. */ public void reset () { units.reset (); tens.reset (); hundreds.reset (); } }