/** * This class will represent a decimal digit. * Author John Sloan * Date: January 29, 2008 * Below is the first field declaration for lab 4 */ public class Digit { // This field is of type integer with the identifier value. private int value; /** * This constructor (page 2) of the lab assignment will take * no parameters. We are using the provide skeleton constructor * and making minor changes. * The identifier below is value. */ public Digit() { // initialising the value field to zero value = 0; } /** * Below is our first method. It is a accessor method * for the field value. * There is no formal parameters. * Return the sum of the expression of the assigment satement in the * constructor above "0" */ public int getValue() { // We want to return the value in the assignment statement above. return value; } /** * Below is our second method. It is a mutator method * for the field value. * There is no formal parameters. * It's purpose is to add one to the value field. */ public void increment() { // Add one to the field value (01234567890etc...) if (value == 9) { value = 0; } else { value = value + 1; } } /** * Below is our third method. It is a mutator method * for the field value. It resets the value at zero. * There is no formal parameters. */ public void reset() { // reset value field to zero. value = 0; } /** * The method allows us to display the digists of our odometer * to the terminal window. This is an accessor method * It will convert each digit to string. */ public String toString() { // reset value field to zero. return "" + value; } }