-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathReferee.java
More file actions
36 lines (26 loc) · 912 Bytes
/
Referee.java
File metadata and controls
36 lines (26 loc) · 912 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
package baseball.domain;
import java.util.List;
public class Referee {
// 해당 라운드 결과 산출
public Result getResult(List<Integer> computer, List<Integer> input) {
int strike = countStrike(computer, input);
int ball = countBall(computer, input);
return new Result(strike, ball);
}
// 스트라이크 갯수 세기
private int countStrike(List<Integer> computer, List<Integer> input) {
int strike = 0;
for (int i = 0; i < 3; i++) {
if (computer.get(i).equals(input.get(i))) strike ++;
}
return strike;
}
// 볼 갯수 세기
private int countBall(List<Integer> computer, List<Integer> input) {
int ball = 0;
for (int i = 0; i < 3; i++) {
if(!computer.get(i).equals(input.get(i)) && input.contains(computer.get(i))) ball ++;
}
return ball;
}
}