Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Write a description of class AlarmClock here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- public class AlarmClock
- {
- private ClockDisplay12 currentTime;
- private Alarm alarmTime;
- /**
- * Creates an AlarmClock object, with the current time set
- * to midnight, the alarm set to midnight, but the alarm is off.
- */
- public AlarmClock()
- {
- currentTime = new ClockDisplay12();
- alarmTime = new Alarm();
- }
- /**
- * Creates an AlarmClock object, with a specified current time,
- * a specified alarm time, and specifies whether the alarm is set or not.
- */
- public AlarmClock(int hour, int minute, String amPm, int alarmHours, int alarmMinutes, String amPmAlarm, boolean alarmSet)
- {
- currentTime = new ClockDisplay12(hour, minute, amPm);
- alarmTime = new Alarm(alarmHours, alarmMinutes, amPmAlarm, alarmSet);
- }
- /**
- * Sets the current time to another specified time.
- */
- public void setTime(int hour, int minute, String amOrPm)
- {
- currentTime.setTime(hour, minute, amOrPm);
- }
- /**
- * Turns on the alarm.
- */
- public void setAlarm()
- {
- alarmTime.turnOn();
- }
- /**
- * Turns off the alarm.
- */
- public void unsetAlarm()
- {
- alarmTime.turnOff();
- }
- /**
- * Sets the time of the alarm.
- */
- public void setAlarmTime(int hours, int minutes, String amPm)
- {
- alarmTime.setTime(hours, minutes, amPm);
- }
- /**
- * Moves the minutes ahead by 1, and rings the alarm
- * if it's time.
- */
- public void clockTick()
- {
- currentTime.timeTick();
- if (currentTime.getTime().equals(alarmTime.getTime()) && alarmTime.isSet()){
- System.out.println("RING RING RING");
- }
- }
- /**
- * Returns the current time on the clock.
- */
- public String getTime()
- {
- return currentTime.getTime();
- }
- /**
- * Returns the current time on the clock.
- */
- public String getAlarmTime()
- {
- return alarmTime.getTime();
- }
- /**
- * Returns true if the alarm is set, false if it isn't set.
- */
- public boolean isAlarmSet()
- {
- return alarmTime.isSet();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement