Advertisement
Guest User

AlarmClock

a guest
Sep 21st, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1.  
  2. /**
  3. * Write a description of class AlarmClock here.
  4. *
  5. * @author (your name)
  6. * @version (a version number or a date)
  7. */
  8. public class AlarmClock
  9. {
  10. private ClockDisplay12 currentTime;
  11. private Alarm alarmTime;
  12.  
  13. /**
  14. * Creates an AlarmClock object, with the current time set
  15. * to midnight, the alarm set to midnight, but the alarm is off.
  16. */
  17. public AlarmClock()
  18. {
  19. currentTime = new ClockDisplay12();
  20. alarmTime = new Alarm();
  21. }
  22.  
  23. /**
  24. * Creates an AlarmClock object, with a specified current time,
  25. * a specified alarm time, and specifies whether the alarm is set or not.
  26. */
  27. public AlarmClock(int hour, int minute, String amPm, int alarmHours, int alarmMinutes, String amPmAlarm, boolean alarmSet)
  28. {
  29. currentTime = new ClockDisplay12(hour, minute, amPm);
  30. alarmTime = new Alarm(alarmHours, alarmMinutes, amPmAlarm, alarmSet);
  31. }
  32.  
  33. /**
  34. * Sets the current time to another specified time.
  35. */
  36. public void setTime(int hour, int minute, String amOrPm)
  37. {
  38. currentTime.setTime(hour, minute, amOrPm);
  39. }
  40.  
  41. /**
  42. * Turns on the alarm.
  43. */
  44. public void setAlarm()
  45. {
  46. alarmTime.turnOn();
  47. }
  48.  
  49. /**
  50. * Turns off the alarm.
  51. */
  52. public void unsetAlarm()
  53. {
  54. alarmTime.turnOff();
  55. }
  56.  
  57. /**
  58. * Sets the time of the alarm.
  59. */
  60. public void setAlarmTime(int hours, int minutes, String amPm)
  61. {
  62. alarmTime.setTime(hours, minutes, amPm);
  63. }
  64.  
  65. /**
  66. * Moves the minutes ahead by 1, and rings the alarm
  67. * if it's time.
  68. */
  69. public void clockTick()
  70. {
  71. currentTime.timeTick();
  72. if (currentTime.getTime().equals(alarmTime.getTime()) && alarmTime.isSet()){
  73. System.out.println("RING RING RING");
  74. }
  75. }
  76.  
  77. /**
  78. * Returns the current time on the clock.
  79. */
  80. public String getTime()
  81. {
  82. return currentTime.getTime();
  83. }
  84.  
  85. /**
  86. * Returns the current time on the clock.
  87. */
  88. public String getAlarmTime()
  89. {
  90. return alarmTime.getTime();
  91. }
  92.  
  93. /**
  94. * Returns true if the alarm is set, false if it isn't set.
  95. */
  96. public boolean isAlarmSet()
  97. {
  98. return alarmTime.isSet();
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement