-
Notifications
You must be signed in to change notification settings - Fork 904
Expand file tree
/
Copy pathGameChecker.java
More file actions
31 lines (27 loc) · 1.1 KB
/
GameChecker.java
File metadata and controls
31 lines (27 loc) · 1.1 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
package baseboll.myTrial.second.checker;
public class GameChecker {
private NothingChecker nothingChecker;
private CorrectChecker correctChecker;
private StrikeChecker strikeChecker;
private BallChecker ballChecker;
public GameChecker() {
init();
}
private void init() {
this.ballChecker = new BallChecker();
this.correctChecker = new CorrectChecker();
this.nothingChecker = new NothingChecker();
this.strikeChecker = new StrikeChecker();
}
public String check(String input, String answer){
if (this.correctChecker.isCorrect(input, answer)) return "정답";
int strikeCount = strikeChecker.countStrike(input, answer);
int ballCount = ballChecker.countBall(input, answer, strikeCount);
if (nothingChecker.isNothing(strikeCount, ballCount)) return "낫싱";
String ball = ballCount + "볼";
if (strikeCount == 0 && ballCount != 0) return ball;
String strike = strikeCount + "스트라이크";
if (ballCount == 0 && strikeCount != 0) return strike;
return strike + ball;
}
}