-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathResult.java
More file actions
35 lines (30 loc) · 950 Bytes
/
Result.java
File metadata and controls
35 lines (30 loc) · 950 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
package baseball.model.domain;
import static baseball.common.constant.Constants.BALL;
import static baseball.common.constant.Constants.NOTHING;
import static baseball.common.constant.Constants.STRIKE;
import static baseball.common.constant.Constants.WHITE_SPACE;
public class Result {
private final int strikes;
private final int balls;
public Result(int strikes, int balls) {
this.strikes = strikes;
this.balls = balls;
}
public boolean isCorrect() {
return strikes == 3;
}
@Override
public String toString() {
if (strikes == 0 && balls == 0) {
return NOTHING;
}
StringBuilder result = new StringBuilder();
if (balls > 0) {
result.append(BALL.formatted(balls)).append(WHITE_SPACE);
}
if (strikes > 0) {
result.append(STRIKE.formatted(strikes));
}
return result.toString().trim();
}
}