-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathTrialResult.java
More file actions
48 lines (38 loc) · 1.02 KB
/
TrialResult.java
File metadata and controls
48 lines (38 loc) · 1.02 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
package num3baseball.dataobject;
import num3baseball.exception.WrongNumberException;
public class TrialResult {
private int strike = 0;
private int ball = 0;
private final int size;
public TrialResult(int size){
this.size = size;
}
public int getStrike() {
return strike;
}
public int getBall() {
return ball;
}
public int getSize() {
return size;
}
public TrialResult(int strike, int ball, int size){
this.size = size;
chkValidNumber(strike, ball);
this.strike = strike;
this.ball = ball;
}
private void chkValidNumber(int strike, int ball){
if (strike<0 || ball<0){
throw new WrongNumberException();
}
if (strike+ball > size || (strike==size-1 && ball==1)){
throw new WrongNumberException();
}
}
public void setStrikeBall(int strike, int ball){
chkValidNumber(strike, ball);
this.strike = strike;
this.ball = ball;
}
}