-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClockClient2.java
More file actions
67 lines (63 loc) · 2.21 KB
/
Copy pathClockClient2.java
File metadata and controls
67 lines (63 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* ClockClient2.java
*
* A sample client program for the Clock class you will define in PS 9.
*
* Do not open until after completing tasks a-h.
*/
public class ClockClient2 {
public static void main(String[] args) {
Clock c = new Clock(3, 15, true);
Time current = c.getCurrentTime();
System.out.println("Current time: " + current);
// No alarms
c.printAlarms();
System.out.print("Alarm ");
if (c.alarmShouldSound()) {
System.out.println("should sound");
} else {
System.out.println("should not sound");
}
System.out.println(c); // uses toString
System.out.println();
// 3 alarms -- none of which should sounding
c.addAlarm(new Time(5, 0, true));
c.addAlarm(new Time(9, 30, false));
c.addAlarm(new Time(7, 0, true));
int count = c.getAlarmCount();
System.out.println(count + " alarms");
c.printAlarms();
System.out.print("Alarm ");
if (c.alarmShouldSound()) {
System.out.println("should sound");
} else {
System.out.println("should not sound");
}
System.out.println(c); // uses toString
System.out.println();
// Remove one alarm
c.removeAlarm(0);
System.out.println(c.getAlarmCount() + " alarms");
c.printAlarms();
System.out.print("Alarm ");
if (c.alarmShouldSound()) {
System.out.println("should sound");
} else {
System.out.println("should not sound");
}
System.out.println(c); // uses toString
System.out.println();
// Add an alarm that should sound.
c.addAlarm(new Time(3, 15, true));
System.out.println(count + " alarms");
c.printAlarms();
System.out.print("Alarm ");
if (c.alarmShouldSound()) {
System.out.println("should sound");
} else {
System.out.println("should not sound");
}
System.out.println(c); // uses toString
System.out.println();
}
}