Java Reference
In-Depth Information
Code 3.3
continued
Implementation of the
NumberDisplay
class
public int getValue()
{
return value;
}
/**
* 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.
*/
public void setValue( int replacementValue)
{
if ((replacementValue >= 0) &&
(replacementValue < limit)) {
value = replacementValue;
}
}
/**
* 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).
*/
public String getDisplayValue()
{
if (value < 10) {
return "0" + value;
}
else {
return "" + value;
}
}
/**
* Increment the display value by one, rolling over to zero if
* the limit is reached.
*/
public void increment()
{
value = (value + 1) % limit;
}
}
 
Search WWH ::




Custom Search