Ask Question
21 October, 23:32

Include an Alarm feature in the Clock class. When setAlarm (hours, minutes), the clock stores the alarm. When you call getTime and the alarm time has been reached or exceeded, return the time followed by the string "Alarm" and clear the alarm.

+4
Answers (1)
  1. 21 October, 23:47
    0
    The solution code is written in Java:

    public void setAlarm (int hour, int minutes) { this. alarmHour = hour; this. alarmMinutes = minutes; } public String getAlarm () { if (this. currentHour > = this. alarmHour) { if (this. currentMinutes > = this. alarmMinutes) { this. alarmHour = 0; this. alarmMinutes = 0; return this. currentHour + ":" + this. currentMinutes + " Alarm!"; } } return this. currentHour + ":" + this. currentMinutes; }

    Explanation:

    The setAlarm () method can be written as in Line 1-4. This method will take input hour and minutes and set them to two private attributes, alarmHour and alarmMinutes.

    Next create another getAlarm () method that will check if the current hour and current minutes exceed or equal to the alarm hour and alarm minutes (Line 6-8). If so, reset alarmhour and alramMinutes to zero and return the time followed by string Alarm! (Line 9 - 11).

    If the current time doesn't not exceed or reach the alarm time, the program will just simply return the current time string (Line 15).
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Include an Alarm feature in the Clock class. When setAlarm (hours, minutes), the clock stores the alarm. When you call getTime and the ...” in 📗 Engineering if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers