java ''
/*
- Student Name: Peter Drakulic
- Lab Professor: Professor Daniel Cormier
- Due Date: June 16
- Description: This Java class retrieves and formats the current local time.
*/
package assignment2;
/** AlarmClock extends Clock and handles alarm functionality,
*including setting and checking alarm times.
-
@author - Peter Drakulic
-
@version 1.1
-
@since java 20
-
@see "Clock class for detail"
*/
public class AlarmClock extends Clock
{
//creates variables alarmHours and alarmMinutes
int alarmHours;
int alarmMinutes;/** This method sets the alarm time by assigning the provided values for hours
- and minutes to the corresponding variables.
- @param hours
- @param minutes
*/
public void setAlarm(int hours, int minutes)
{
alarmHours = hours;
alarmMinutes = minutes;
}/** * The provided code snippet retrieves the current time, * compares it to a set alarm time, and if the current time has reached or surpassed the alarm time, * it returns a string indicating the time followed by the word "Alarm." * @return String Return Hours and minutes and Alarm. */public String getTime()
{
String clockHours = getHours();
String clockMinutes = getMinutes();
int clockHoursInt = Integer.valueOf(clockHours);
int clockMinutesInt = Integer.valueOf(clockMinutes);/*This code checks the time and alarm, *resets the alarm if the condition is met, *and returns the time with or without the "Alarm" suffix. */ if (clockHoursInt >= alarmHours && clockMinutesInt >= alarmMinutes) { alarmHours = 0; alarmMinutes = 0; return clockHoursInt + ":" + clockMinutesInt + " Alarm"; } else { return clockHoursInt + ":" + clockMinutesInt; } }
}