-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuard.java
More file actions
55 lines (45 loc) · 1.19 KB
/
Copy pathGuard.java
File metadata and controls
55 lines (45 loc) · 1.19 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
/* Advent of Code Adaptation Day 4
* Guard.java
*/
import java.util.*;
public class Guard{
private int number;
private ArrayList<Shift> shifts;
String kek;
public Guard(int n, Shift s) {
number = n;
shifts = new ArrayList<Shift>();
shifts.add(s);
}
public String toString() {
/* returns a string form of the class for testing purposes */
int i = 1;
for(Shift shift: shifts) {
//prints all the shifts
System.out.println("Shift " + i + ": " + shift.napLength() + " minutes.");
i++;
}
//shows guard's number and amount of time slept
String s = Integer.toString(number) + " " + Integer.toString(this.totalHoursAsleep()); ;
return s;
}
public String getKek() {
return kek;
}
public int getNumber() {
/* returns the guards number */
return number;
}
public void addShift(Shift shift) {
/* add another Shift object to the shifts ArrayList */
shifts.add(shift);
}
public int totalHoursAsleep() {
/* calculate the total hours this guard has napped */
int total = 0;
for(Shift shift: shifts) {
total += shift.napLength();
}
return total;
}
}