forked from next-step/java-baseball-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayResult.java
More file actions
43 lines (36 loc) · 1.15 KB
/
PlayResult.java
File metadata and controls
43 lines (36 loc) · 1.15 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
40
41
42
43
package baseball.core;
import java.util.Objects;
public class PlayResult {
private final int strikeCount;
private final int ballCount;
public PlayResult(int strikeCount, int ballCount) {
this.strikeCount = strikeCount;
this.ballCount = ballCount;
}
public boolean isFinished() {
return this.strikeCount == Balls.BALL_COUNT;
}
public String getResultMessage() {
if (0 < this.ballCount && 0 < this.strikeCount) {
return this.ballCount + "볼 " + this.strikeCount + "스트라이크";
}
if (0 < this.strikeCount) {
return this.strikeCount + "스트라이크";
}
if (0 < this.ballCount) {
return this.ballCount + "볼";
}
return "낫싱";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PlayResult that = (PlayResult) o;
return strikeCount == that.strikeCount && ballCount == that.ballCount;
}
@Override
public int hashCode() {
return Objects.hash(strikeCount, ballCount);
}
}