Findryan

Untitled

Nov 10th, 2016
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. public class ClockDisplay
  2. {
  3. private NumberDisplay hours;
  4. private NumberDisplay minutes;
  5. private String displayString;
  6.  
  7. public ClockDisplay()
  8. {
  9. hours = new NumberDisplay(24);
  10. minutes = new NumberDisplay(60);
  11. updateDisplay();
  12.  
  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.  
  23. public void timeTick()
  24. {
  25. minutes.increment();
  26. if(minutes.getValue() == 0)
  27. {
  28. hours.increment();
  29.  
  30. }
  31. updateDisplay();
  32. }
  33.  
  34. public void setTime(int hour, int minute)
  35. {
  36. hours.setValue(hour);
  37. minutes.setValue(minute);
  38. updateDisplay();
  39. }
  40.  
  41. public String getTime()
  42. {
  43. return displayString;
  44. }
  45.  
  46. private void updateDisplay()
  47. {
  48. displayString = hours.getDisplayValue() + ":" + minutes.getDisplayValue();
  49. }
  50.  
  51. }
Add Comment
Please, Sign In to add comment