forked from next-step/java-baseball-playground
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBaseballStatus.java
More file actions
49 lines (39 loc) · 1.03 KB
/
BaseballStatus.java
File metadata and controls
49 lines (39 loc) · 1.03 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
44
45
46
47
48
49
package baseball.domain;
public class BaseballStatus {
private final int ball;
private final int strike;
public BaseballStatus(int ball, int strike) throws Exception {
this.ball = ball;
this.strike = strike;
this.isValid();
}
private void isValid() throws Exception{
if (!this.existsBall() && !this.existsStrike() && !this.nothing())
throw new Exception("결과를 반환할 수 없습니다");
}
public int getBall() {
return ball;
}
public int getStrike() {
return strike;
}
@Override
public String toString() {
return "BaseballStatus{" +
"ball=" + ball +
", strike=" + strike +
'}';
}
public boolean nothing() {
return strike == 0 && ball == 0;
}
public boolean existsBall() {
return ball > 0;
}
public boolean existsStrike() {
return strike > 0;
}
public boolean exitGame() {
return getStrike() == 3;
}
}