clock
Make a clock class which has three int instance variables for hours, minutes and seconds.
It should also have a tick()
method that advances the time by adding to the seconds. If there is more than 59, it should go back to 0, and advance the minutes. If there are more than 59 minutes, it should go back to 0, and advance the hours. If there are more than 23 hours, it goes back to 0.
It needs a toString
method that returns a string that has leading zeros ( as in “00:07:05” )
The Clock tester class below can be used to check your work.
What else?
- Make a subclass of your
Clock
class calledFancyClock
that keeps track of days and/or milliseconds. ThetoString
method needs to be adjusted as well. - Make a subclass of your
Clock
class calledAlarmClock
. Thetick
method needs to be enhanced so it checks to see if the alarm should be turned on. There would also need to be instance variables for the Alarm time and whether the alarm is ringing. There would be also need to be methods so TheClockTester
class methodpaintComponent
needs to be modified to indicate the Alarm is active. YourAlarmClock
class would need accessor methods so that the ClockTester can see if it is ringing and to turn off the ringing. - Make a subclass of
Clock
calledCountdownTimer
which counts down to 00:00:00
clock.txt · Last modified: 2019/05/16 14:23 by frchris