I suggest that you start by extending the current ClockDisplay code so that it keeps track of the time in hours, minutes, and seconds, and wait to implement the alarm until you get the basic clock working. Your code must meet the following requirements for full credit:
setTime method should take three arguments as well, and set the clock to the specified hour, minute, and second.
updateDisplay method should build a string showing the seconds as well as the hours and minutes. (See below for examples.)
timeTick method should be changed so that it increments the seconds value each time it's called. The minutes field should increment each time the seconds field rolls over.
timeTick method is incrementing the seconds field, and it all rolls over as expected:
Your ClockDisplay must also implement an alarm function as well. The clock should remember a specified time (hour and minute), and print an alarm message if the clock's current time hits the alarm time. For full credit, you must do the following:> ClockDisplay clock = new ClockDisplay(23, 59, 58); > clock.getTime() "23:59:58" (String) > clock.timeTick(); > clock.getTime() "23:59:59" (String) > clock.timeTick(); > clock.getTime() "00:00:00" (String) > clock.timeTick(); > clock.getTime() "00:00:01" (String) > clock.setTime(0,0,59); > clock.getTime() "00:00:59" (String) > clock.timeTick(); > clock.getTime() "00:01:00" (String)
setAlarm that takes two integers as parameters, the hour and the minute specifying the time that the alarm should go off. (You'll want to save these values for later use.) No alarms should go off until this method is called to set an alarm.
clearAlarm that takes no arguments and that "clears" the current alarm. That is, no alarm should go off after calling clearAlarm regardless of the number of times timeTick is called. (There are multiple ways to make this work, but the easiest is probably to set the alarm hour and minute to values that will never occur.)
timeTick method so that it prints Alarm! to the terminal window if the time, after incrementing the number of seconds, matches the alarm hour and minute.
Alarm! lines are shown as part of the interactions in the codepad, but they should actually appear in the terminal window since they're being printed.) Notice that since the alarm is specified for a given hour and minute, alarm notices are printed for each tick after the hour and minute are hit, and would continue to be generated for each new second until the minute rolls over (in this case to "09:01:00").
> ClockDisplay clock = new ClockDisplay(8,59,58); > clock.getTime() "08:59:58" (String) > clock.setAlarm(9,0); > clock.timeTick(); > clock.getTime() "08:59:59" (String) > clock.timeTick(); Alarm! > clock.getTime() "09:00:00" (String) > clock.timeTick(); Alarm! > clock.getTime() "09:00:01" (String) > clock.timeTick(); Alarm! > clock.clearAlarm(); > clock.timeTick(); > clock.timeTick();
updateDisplay method so that the display string includes the alarm time, but only if an alarm is set.
minuteTick method that increments the minutes field without changing seconds. The hours should still increment if minutes roll over.