-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathReferee.java
More file actions
29 lines (24 loc) · 842 Bytes
/
Referee.java
File metadata and controls
29 lines (24 loc) · 842 Bytes
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
package baseball.domain;
import java.util.List;
import java.util.Objects;
public class Referee {
public static Score compare(List<Integer> computer, List<Integer> player) {
int strike = 0;
int ball = 0;
for (int i = 0; i < 3; i++) {
strike += countStrike(computer.get(i), player.get(i));
ball += countBall(computer, player, i);
}
return new Score(strike, ball);
}
private static int countStrike(int computerNum, int playerNum) {
if (computerNum == playerNum) return 1;
return 0;
}
private static int countBall(List<Integer> computer, List<Integer> player, int index) {
if (computer.contains(player.get(index)) && !Objects.equals(computer.get(index), player.get(index))) {
return 1;
}
return 0;
}
}