-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBirdWatcher.java
More file actions
47 lines (37 loc) · 1.09 KB
/
Copy pathBirdWatcher.java
File metadata and controls
47 lines (37 loc) · 1.09 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
class BirdWatcher {
private final int[] birdsPerDay;
public BirdWatcher(int[] birdsPerDay) {
this.birdsPerDay = birdsPerDay.clone();
}
public int[] getLastWeek() {
return this.birdsPerDay;
}
public int getToday() {
return this.birdsPerDay[birdsPerDay.length -1];
}
public void incrementTodaysCount() {
this.birdsPerDay[6]++;
}
public boolean hasDayWithoutBirds() {
for (int birds : this.birdsPerDay){
if ( birds == 0 ) return true;
}
return false;
}
public int getCountForFirstDays(int numberOfDays) {
int total = 0;
int numberOfDaysLimiter = numberOfDays > 7 ? 7 : numberOfDays;
for (int i = 0; i < numberOfDaysLimiter; ++i) {
total += this.birdsPerDay[i];
}
return total;
}
public int getBusyDays() {
int totalBusyDays = 0;
for ( int birds : this.birdsPerDay){
if (birds >= 5){
totalBusyDays += 1;
}
} return totalBusyDays;
}
}