Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. public class NumberDisplay
  2. {
  3.     private int limit;
  4.     private int value;
  5.    
  6.     /**
  7.      * Constructor for objects of class NumberDisplay
  8.      */
  9.     public NumberDisplay(int rollOverLimit) {
  10.         limit = rollOverLimit;
  11.         value = 0;
  12.     }
  13.    
  14.     /**
  15.      * Return the current value.
  16.      */
  17.     public int getValue() {
  18.         return value;
  19.     }
  20.    
  21.     /**
  22.      * Set the value of the display to the new specified
  23.      * value. If the new value is less than zero or over the
  24.      * limit, do nothing.
  25.      */
  26.     public void setValue(int replacementValue) {
  27.         if((replacementValue >= 0) && (replacementValue < limit)) {
  28.             value = replacementValue;
  29.         }
  30.     }
  31.    
  32.     /**
  33.      * Return the display value (that is, the current value
  34.      * as a two-digit String. If the value is less than ten,
  35.      * it will be padded with a leading zero).
  36.      */
  37.     public String getDisplayValue() {
  38.         if(value < 10) {
  39.             return "0" + value;
  40.         } else {
  41.             return "" + value;
  42.         }
  43.     }
  44.    
  45.     /**
  46.      * Increment the display value by one, rolling over to zero if
  47.      * the limit is reached.
  48.      */
  49.    
  50.     public void increment() {
  51.         value = (value + 1) % limit;
  52.     }
  53. }