forked from JaeHongDev/java-baseball
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameResult.java
More file actions
39 lines (32 loc) · 1.09 KB
/
GameResult.java
File metadata and controls
39 lines (32 loc) · 1.09 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
38
39
package baseball.domain;
public class GameResult {
private static final int THE_NUMBER_OF_GAME_NUMBER = 3;
private final String value;
private final boolean isEnd;
private GameResult(String value, boolean isEnd) {
this.value = value;
this.isEnd = isEnd;
}
public static GameResult from(int strike, int ball, int theNumberOfGameNumber) {
if (strike == 0 && ball == 0) {
return new GameResult("낫싱", false);
}
StringBuilder result = new StringBuilder();
if (ball != 0) {
result.append(ball).append("볼 ");
}
if (strike != 0) {
result.append(strike).append("스트라이크");
}
if (strike == theNumberOfGameNumber) {
result.append("\n").append(theNumberOfGameNumber).append("개의 숫자를 모두 맞히셨습니다! 게임 종료");
}
return new GameResult(result.toString(), strike == THE_NUMBER_OF_GAME_NUMBER);
}
public String getValue() {
return value;
}
public boolean isEnd() {
return isEnd;
}
}