Class NumberDisplay
- java.lang.Object
-
- NumberDisplay
-
public class NumberDisplay extends java.lang.Object
We'll write our own version of the book's NumberDisplay class for practice. A NumberDisplay JUST keeps track of a two-digit number. We'll eventually use two of these in the clock -- one for hours and one for minutes.- Version:
- 1.0
- Author:
- Brad Richards
-
-
Constructor Summary
Constructors Constructor Description NumberDisplay(int rollOverLimit)
Constructor that creates a NumberDisplay with the specified upper limit.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getDisplayValue()
Returns a string version of the displayed value.int
getValue()
A "getter" that returns the current display value.void
increment()
Increment increases the value of the clock by one, wrapping around if necessary.void
setValue(int newValue)
Sets the display to the specified value, as long as the specified value is within the appropriate range.
-
-
-
Method Detail
-
increment
public void increment()
Increment increases the value of the clock by one, wrapping around if necessary.
-
getDisplayValue
public java.lang.String getDisplayValue()
Returns a string version of the displayed value. If it's a single digit, we stick an extra zero in front of it.- Returns:
- Returns current value as a two-character string.
-
getValue
public int getValue()
A "getter" that returns the current display value.- Returns:
- Current value of NumberDisplay.
-
setValue
public void setValue(int newValue)
Sets the display to the specified value, as long as the specified value is within the appropriate range. Otherwise we print an error message and leave the value unchanged.- Parameters:
newValue
- A new value that's >= 0 and < roll over limit.
-
-