Answer:
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 ;
- }
Step-by-step 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).