-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathLottoNumber.java
More file actions
38 lines (30 loc) · 924 Bytes
/
LottoNumber.java
File metadata and controls
38 lines (30 loc) · 924 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
36
37
38
package com.javabom.lotto.domain.ticket;
import java.util.Objects;
public class LottoNumber {
public static final int MIN_LOTTO_NUM = 1;
public static final int MAX_LOTTO_NUM = 45;
private final int number;
public LottoNumber(int number) {
validateNumber(number);
this.number = number;
}
private void validateNumber(int number) {
if (number < MIN_LOTTO_NUM || number > MAX_LOTTO_NUM) {
throw new IllegalArgumentException("로또 번호는 1~45 입니다.");
}
}
public int get() {
return number;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LottoNumber that = (LottoNumber) o;
return number == that.number;
}
@Override
public int hashCode() {
return Objects.hash(number);
}
}