Ramdan51-062

NumberDisplay

Oct 5th, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. public class NumberDisplay
  2. {
  3.     private int limit;
  4.     private int value;
  5.    
  6.     public NumberDisplay(int rollOverLimit)
  7.     {
  8.         limit = rollOverLimit;
  9.         value = 0;
  10.     }
  11.    
  12.     public int getValue()
  13.     {
  14.         return value;
  15.     }
  16.    
  17.     public void setValue(int replacementValue)
  18.     {
  19.         if((replacementValue >= 0) && (replacementValue < limit))
  20.         {
  21.             value = replacementValue;
  22.         }
  23.     }
  24.    
  25.     public String getDisplayValue()
  26.     {
  27.         if(value < 10)
  28.         {
  29.             return "0" + value;
  30.         }
  31.         else
  32.         {
  33.             return "" + value;
  34.         }
  35.     }
  36.    
  37.     public void increment()
  38.     {
  39.         value = (value + 1) % limit;
  40.     }
  41. }
Add Comment
Please, Sign In to add comment