-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathBaseballGameJudge.java
More file actions
37 lines (28 loc) · 926 Bytes
/
BaseballGameJudge.java
File metadata and controls
37 lines (28 loc) · 926 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
30
31
32
33
34
35
36
37
package model;
import model.exception.InvalidInputException;
import java.util.List;
import static model.exception.InputErrorCode.*;
public class BaseballGameJudge {
int countBall(List<Integer> answer, List<Integer> guess) {
int ball = 0;
for (int i = 0; i < guess.size(); i++) {
int num = guess.get(i);
if (answer.contains(num) && !answer.get(i).equals(num)) {
ball++;
}
}
return ball;
}
int countStrike(List<Integer> answer, List<Integer> guess) {
int strike = 0;
for (int i = 0; i < guess.size(); i++) {
if (answer.get(i).equals(guess.get(i))) {
strike++;
}
}
return strike;
}
public GameResult judge(List<Integer> answer, List<Integer> guess) {
return new GameResult(countBall(answer, guess), countStrike(answer, guess));
}
}