Question: /** * The ClockDisplay class implements a digital clock display for a * European-style 24 hour clock. The clock shows hours and minutes. The *
/** * The ClockDisplay class implements a digital clock display for a * European-style 24 hour clock. The clock shows hours and minutes. The * range of the clock is 00:00 (midnight) to 23:59 (one minute before * midnight). * * The clock display receives "ticks" (via the timeTick method) every minute * and reacts by incrementing the display. This is done in the usual clock * fashion: the hour increments when the minutes roll over to zero. * * @author Michael Klling and David J. Barnes * @version 2016.02.29 */ public class ClockDisplay { private NumberDisplay hours; private NumberDisplay minutes; private String displayString; // simulates the actual display /** * Constructor for ClockDisplay objects. This constructor * creates a new clock set at 00:00. */ public ClockDisplay() { hours = new NumberDisplay(24); minutes = new NumberDisplay(60); updateDisplay(); }
/** * Constructor for ClockDisplay objects. This constructor * creates a new clock set at the time specified by the * parameters. */ public ClockDisplay(int hour, int minute) { hours = new NumberDisplay(24); minutes = new NumberDisplay(60); setTime(hour, minute); }
/** * This method should get called once every minute - it makes * the clock display go one minute forward. */ public void timeTick() { minutes.increment(); if(minutes.getValue() == 0) { // it just rolled over! hours.increment(); } updateDisplay(); }
/** * Set the time of the display to the specified hour and * minute. */ public void setTime(int hour, int minute) { hours.setValue(hour); minutes.setValue(minute); updateDisplay(); }
/** * Return the current time of this display in the format HH:MM. */ public String getTime() { return displayString; } /** * Update the internal string that represents the display. */ private void updateDisplay() { displayString = hours.getDisplayValue() + ":" + minutes.getDisplayValue(); } }
1. turnAlarmOn(int hour, int minute) - turns the alarm on and sets it to the given time; hour may be an integer from 0 - 23 representing 12am - 11pm. (Note: This method does not ring the alarm, it just sets it to 'on' and the given time so that when the clock ticks to that time, it will ring.)
2. turnAlarmOff() - turns the alarm off. (When the alarm is off, it should not ring, even if the clock ticks to the alarm time.)
3. When the clock is created, the alarm should start in the 'off' position.
4. When the clock ticks to the set alarm time, if the alarm is turned on, an alarm should ring. You can simulate the ring with a print message.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
