code alarm clock java

Solutions on MaxInterview for code alarm clock java by the best coders in the world

showing results for - "code alarm clock java"
Veronica
13 Jan 2019
1  1: /**
2  2: An alarm clock should include a time to sound the alarm as well as methods
3  3: to set the alarm.
4  4: */
5  5: public class AlarmClock extends Clock
6  6: {
7  7:         public int alarmHour;
8  8:         public int alarmMinute;
9  9:         public int alarmSecond;
10 10: 
11 11:         //Constructors
12 12:         public AlarmClock()
13 13:         {
14 14:                 super();
15 15:                 alarmHour = 0;
16 16:                 alarmMinute = 0;
17 17:                 alarmSecond = 0;
18 18:         }
19 19: 
20 20:         public AlarmClock(int theHour, int theMinute, int theSecond, int alarmH, int alarmM, int alarmS)
21 21:         {
22 22:                 super(theHour, theMinute, theSecond);
23 23:                 setAlarmHour(alarmH);
24 24:                 setAlarmMinute(alarmM);
25 25:                 setAlarmSecond(alarmS);
26 26:         }
27 27: 
28 28:         //Accessors
29 29:         public void setAlarmHour(int alarmH)
30 30:         {
31 31:                 if((alarmH >= 0) && (alarmH <= 24))
32 32:                         alarmHour = alarmH;
33 33:                 else
34 34:                         System.out.println("Fatal error: invalid alarm hour");
35 35:         }
36 36: 
37 37:         public void setAlarmMinute(int alarmM)
38 38:         {
39 39:                 if((alarmM >= 0) && (alarmM <= 59))
40 40:                         alarmMinute = alarmM;
41 41:                 else
42 42:                         System.out.println("Fatal error: invalid alarm minute");
43 43:         }
44 44: 
45 45:         public void setAlarmSecond(int alarmS)
46 46:         {
47 47:                 if((alarmS >= 0) && (alarmS <= 59))
48 48:                         alarmSecond = alarmS;
49 49:                 else
50 50:                         System.out.println("Fatal error: invalid alarm second");
51 51:         }
52 52:         //Mutators
53 53:         public int getAlarmHour()
54 54:         {
55 55:                 return alarmHour;
56 56:         }
57 57: 
58 58:         public int getAlarmMinute()
59 59:         {
60 60:                 return alarmMinute;
61 61:         }
62 62: 
63 63:         public int getAlarmSecond()
64 64:         {
65 65:                 return alarmSecond;
66 66:         }
67 67: 
68 68:         public String getCurrentAlarmTime()
69 69:         {
70 70:                 return "The alarm is set to " + alarmHour + ":" + alarmMinute + ":" + alarmSecond;
71 71:         }
72 72: 
73 73:         //Facilitators
74 74:         public String toString()
75 75:         {
76 76:                 return "The current time is " + getHour() + ":" + getMinute() + ":" +
77 77:                                 getSecond() + "\nThe alarm is set to " + getAlarmHour() + ":" +
78 78:                                 getAlarmMinute() + ":" + getAlarmSecond();
79 79:         }
80 80: 
81 81:         public boolean equals(Object o)
82 82:         {
83 83:                 if(o == null)
84 84:                         return false;
85 85:                 else if(getClass() != o.getClass())
86 86:                         return false;
87 87:                 else
88 88:                 {
89 89:                         AlarmClock otherClock = (AlarmClock) o;
90 90:                         return((getHour() == otherClock.getHour()) && (getMinute() == otherClock.getMinute())
91 91:                                         && (getSecond() == otherClock.getSecond()) && (alarmHour == otherClock.alarmHour)
92 92:                                         && (alarmMinute == otherClock.alarmMinute) && (alarmSecond == otherClock.alarmSecond));
93 93:                 }
94 94: 
95 95:         }
96 96: 
97 97: }
queries leading to this page
code alarm clock javacode alarm clock java