-
Notifications
You must be signed in to change notification settings - Fork 901
Expand file tree
/
Copy pathBall.java
More file actions
49 lines (36 loc) · 1.06 KB
/
Ball.java
File metadata and controls
49 lines (36 loc) · 1.06 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;
import java.util.Objects;
public class Ball {
private final int position;
private final int no;
public Ball(int position, int no) throws IllegalArgumentException {
if (!ValidationUtils.ValidNo(no)) {
throw new IllegalArgumentException("1 ~ 9 사이의 숫자를 입력하세요.");
}
this.position = position;
this.no = no;
}
public BallStatus play(Ball ball) {
if (this.equals(ball)) {
return BallStatus.STRIKE;
}
if (this.isMatchNo(ball.no)) {
return BallStatus.BALL;
}
return BallStatus.NOTHING;
}
private boolean isMatchNo(int no) {
return this.no == no;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Ball ball = (Ball) o;
return position == ball.position && no == ball.no;
}
@Override
public int hashCode() {
return Objects.hash(position, no);
}
}