Advertisement
Ramdan51-062

ClockDisplay

Oct 5th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1.  
  2. public class ClockDisplay
  3. {
  4.     private NumberDisplay hours;
  5.     private NumberDisplay minutes;
  6.     private String displayString;
  7.    
  8.     public ClockDisplay()
  9.     {
  10.         hours = new NumberDisplay(24);
  11.         minutes = new NumberDisplay(60);
  12.         updateDisplay();
  13.     }
  14.    
  15.     public ClockDisplay(int hour, int minute)
  16.     {
  17.         hours = new NumberDisplay(24);
  18.         minutes = new NumberDisplay(60);
  19.         setTime(hour, minute);
  20.     }
  21.    
  22.     public void timeTick()
  23.     {
  24.         minutes.increment();
  25.         if(minutes.getValue() == 0)
  26.         {
  27.             hours.increment();
  28.         }
  29.         updateDisplay();
  30.     }
  31.    
  32.     public void setTime(int hour, int minute)
  33.     {
  34.         hours.setValue(hour);
  35.         minutes.setValue(minute);
  36.         updateDisplay();
  37.     }
  38.    
  39.     public String getTime()
  40.     {
  41.         return displayString;
  42.     }
  43.    
  44.     private void updateDisplay()
  45.     {
  46.         displayString = hours.getDisplayValue() + ":" + minutes.getDisplayValue();
  47.     }
  48.    
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement