-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathReferee.java
More file actions
37 lines (31 loc) · 1.04 KB
/
Referee.java
File metadata and controls
37 lines (31 loc) · 1.04 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
package baseball.domain;
import baseball.constant.Constant;
public class Referee {
private final BaseballNumbers answer;
private final StrikeBallCount strikeBallCount;
private final int length = Constant.LENGTH.getValue();
public Referee(BaseballNumbers answer) {
this.answer = answer;
this.strikeBallCount = new StrikeBallCount();
}
public StrikeBallCount judge(BaseballNumbers userNumbers) {
strikeBallCount.resetCounts();
for (int index = 0; index < length; index++) {
int number = userNumbers.getNumberAt(index);
judgeOneNumber(index, number);
}
return strikeBallCount;
}
private void judgeOneNumber(int index, int number) {
if (answer.contains(number)) {
changeCount(index, number);
}
}
private void changeCount(int index, int number) {
if (index == answer.getIndex(number)) {
strikeBallCount.addStrikeCount();
return;
}
strikeBallCount.addBallCount();
}
}