blob: 2e083b9e88c52b1f4a6a94900001001633723683 (
plain) (
blame)
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
|
package design.model;
import com.fasterxml.jackson.annotation.JsonCreator;
import java.util.ArrayList;
import java.util.List;
public class Play {
private int holeNumber;
private final List<Swing> swings;
@JsonCreator
public Play(int holeNumber, List<Swing> swings) {
this.holeNumber = holeNumber;
this.swings = (swings != null) ? swings : new ArrayList<>();
}
public Play(int holeNumber) {
this.holeNumber = holeNumber;
this.swings = new ArrayList<>();
}
public int getHoleNumber() {
return holeNumber;
}
public void addSwing(Swing swing) {
swings.add(swing);
}
public Swing[] getSwings() {
return swings.toArray(Swing[]::new);
}
public int getSwingCount() {
return swings.size();
}
// Returns the sum of all swing distances
public int getDistance() {
int total = 0;
for (Swing s : swings) {
total += s.getDistance();
}
return total;
}
}
|