-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathLotto.java
More file actions
78 lines (59 loc) · 2.16 KB
/
Copy pathLotto.java
File metadata and controls
78 lines (59 loc) · 2.16 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package lotto;
import java.util.List;
/**
* 로또 클래스의 역활은 우승자 티켓 검증과 생성 (보너스)
*/
public class Lotto {
public static Lotto instance;
private final List<Integer> numbers;
private Integer bonusNumber;
private static int useMoney;
public Lotto(List<Integer> numbers) {
validate(numbers);
this.numbers = numbers;
}
private void validate(List<Integer> numbers) {
if (numbers.size() != 6) {
throw new IllegalArgumentException("[ERROR] 입력이 잘못되었습니다.");
}
for (int i = 0; i < numbers.size(); i++) {
if (numbers.get(i) < 1) {
throw new IllegalArgumentException("[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다.");
} else if (numbers.get(i) > 45) {
throw new IllegalArgumentException("[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다.");
}
for (int j = 0; j < numbers.size(); j++) {
if (i != j && numbers.get(i).equals(numbers.get(j))) {
throw new IllegalArgumentException("[ERROR] 로또 번호가 중복 되었습니다.");
}
}
}
}
// TODO: 추가 기능 구현
public static Lotto getInstance(List<Integer> numbers) {
if (instance == null) {
instance = new Lotto(numbers);
}
return instance;
}
public List<Integer> getNumbers() {
return numbers;
}
public void setBonusNumber(Integer bonusNumber) {
if (bonusNumber < 1) {
throw new IllegalArgumentException("[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다.");
} else if (bonusNumber > 45) {
throw new IllegalArgumentException("[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다.");
}
this.bonusNumber = bonusNumber;
}
public Integer getBonusNumber() {
return bonusNumber;
}
public static void setUseMoney(Integer money) {
useMoney = money;
}
public static Integer getUseMoney() {
return useMoney;
}
}