Define a derived class to represent an alarm clock.

Use the Clock class, created in number 2 above,
as your base class.


```
/**
An alarm clock should include a time to sound the alarm as well as methods
to set the alarm.
*/
public class AlarmClock extends Clock
{
public int alarmHour;
public int alarmMinute;
public int alarmSecond;
public AlarmClock()
{
super();
alarmHour = 0;
alarmMinute = 0;
alarmSecond = 0;
}
public AlarmClock(int theHour, int theMinute, int theSecond,
int alarmH, int alarmM, int alarmS)
{
super(theHour, theMinute, theSecond);
setAlarmHour(alarmH);
setAlarmMinute(alarmM);
setAlarmSecond(alarmS);
}
public void setAlarmHour(int alarmH)
{
if((alarmH >= 0) && (alarmH <= 24))
alarmHour = alarmH;
else
System.out.println("Fatal error: invalid alarm hour");
}
public void setAlarmMinute(int alarmM)
{
if((alarmM >= 0) && (alarmM <= 59))
alarmMinute = alarmM;
else
System.out.println("Fatal error: invalid alarm minute");
}
public void setAlarmSecond(int alarmS)
{
if((alarmS >= 0) && (alarmS <= 59))
alarmSecond = alarmS;
else
System.out.println("Fatal error: invalid alarm second");
}
public int getAlarmHour()
{
return alarmHour;
}
public int getAlarmMinute()
{
return alarmMinute;
}
public int getAlarmSecond()
{
return alarmSecond;
}
public String getCurrentAlarmTime()
{
return "The alarm is set to " + alarmHour + ":" + alarmMinute + ":" +
alarmSecond;
}
//Facilitators
public String toString()
{
return "The current time is " + getHour() + ":" + getMinute() + ":" +
getSecond() + "\nThe alarm is set to " + getAlarmHour() + ":" +
getAlarmMinute() + ":" + getAlarmSecond();
}
public boolean equals(Object o)
{
if(o == null)
return false;
else if(getClass() != o.getClass())
return false;
else
{
AlarmClock otherClock = (AlarmClock) o;
return((getHour() == otherClock.getHour()) && (getMinute() ==
otherClock.getMinute()) && (getSecond() ==
otherClock.getSecond()) && (alarmHour ==
otherClock.alarmHour) && (alarmMinute ==
otherClock.alarmMinute) &&
(alarmSecond == otherClock.alarmSecond));
}
}
}

```

Computer Science & Information Technology

You might also like to view...

List the five basic operations on a stack. You may assume that there is an integer variable named

What will be an ideal response?

Computer Science & Information Technology

Which of the following splay tree rotations in effect distinguishes it from rotate-to-root?

a. zig only b. zig-zag only c. zig-zig only d. zig-zig and zig-zag only e. all of the above

Computer Science & Information Technology

When inserting slides from the Reuse Slides task pane, you can insert individual slides or all slides from the selected presentation.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

____ are variables associated with an object.

A. Properties B. Components C. Elements D. Parameters

Computer Science & Information Technology