Class NumberDisplay
- java.lang.Object
-
- NumberDisplay
-
public class NumberDisplay extends java.lang.Object
The NumberDisplay class represents a digital number display that can hold values from zero to a given limit. The limit can be specified when creating the display. The values range from zero (inclusive) to limit-1. If used, for example, for the seconds on a digital clock, the limit would be 60, resulting in display values from 0 to 59. When incremented, the display automatically rolls over to zero when reaching the limit.- Version:
- 2016.02.29
- Author:
- Michael Kölling and David J. Barnes
-
-
Constructor Summary
Constructors Constructor Description NumberDisplay(int rollOverLimit)
Constructor for objects of class NumberDisplay.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getDisplayValue()
Return the display value (that is, the current value as a two-digit String.int
getValue()
Return the current value.void
increment()
Increment the display value by one, rolling over to zero if the limit is reached.void
setValue(int replacementValue)
Set the value of the display to the new specified value.
-
-
-
Method Detail
-
getValue
public int getValue()
Return the current value.
-
getDisplayValue
public java.lang.String getDisplayValue()
Return the display value (that is, the current value as a two-digit String. If the value is less than ten, it will be padded with a leading zero).
-
setValue
public void setValue(int replacementValue)
Set the value of the display to the new specified value. If the new value is less than zero or over the limit, do nothing.
-
increment
public void increment()
Increment the display value by one, rolling over to zero if the limit is reached.
-
-