Ask Question
12 January, 07:28

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.

+3
Answers (1)
  1. 12 January, 08:09
    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 you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers