GSculerlor

NumberDisplay.java

Oct 5th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. package ObjectInteraction;
  2.  
  3. public class NumberDisplay {
  4.  
  5.     private int limit;
  6.     private int value;
  7.    
  8.     /**
  9.      * Constructor for objects of class NumberDisplay
  10.      */
  11.     public NumberDisplay(int rollOverLimit) {
  12.         limit = rollOverLimit;
  13.         value = 0;
  14.     }
  15.    
  16.     /**
  17.      * Return the current value.
  18.      */
  19.     public int getValue() {
  20.         return value;
  21.     }
  22.    
  23.     /**
  24.      * Set the value of the display to the new specified
  25.      * value. If the new value is less than zero or over the
  26.      * limit, do nothing.
  27.      */
  28.     public void setValue(int replacementValue) {
  29.         if((replacementValue >= 0) && (replacementValue < limit)) {
  30.             value = replacementValue;
  31.         }
  32.     }
  33.    
  34.     /**
  35.      * Return the display value (that is, the current value
  36.      * as a two-digit String. If the value is less than ten,
  37.      * it will be padded with a leading zero).
  38.      */
  39.     public String getDisplayValue() {
  40.         if(value < 10) {
  41.             return "0" + value;
  42.         } else {
  43.             return "" + value;
  44.         }
  45.     }
  46.    
  47.     /**
  48.      * Increment the display value by one, rolling over to zero if
  49.      * the limit is reached.
  50.      */
  51.    
  52.     public void increment() {
  53.         value = (value + 1) % limit;
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment