forked from woowacourse-precourse/java-lotto-6
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathLotto.java
More file actions
59 lines (53 loc) · 1.28 KB
/
Lotto.java
File metadata and controls
59 lines (53 loc) · 1.28 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
package lotto;
import java.util.ArrayList;
import java.util.List;
public class Lotto {
private final List<Integer> numbers;
public Lotto(){
numbers = new ArrayList<>();
}
public Lotto(List<Integer> numbers) {
validate(numbers);
this.numbers = numbers;
}
private void validate(List<Integer> numbers) {
if (numbers.size() != 6) {
throw new IllegalArgumentException();
}
}
public List<Integer> getNumbers(){
return numbers;
}
public int rankLotto(List<Integer> userNumbers, int bonus){
int rank;
int cnt=0;
boolean bonusFlag = false;
for(int userNum : userNumbers){
for(int num : numbers){
if(num == userNum) cnt++;
if(num == bonus) bonusFlag = true;
}
}
rank = checkRank(cnt, bonusFlag);
return rank;
}
public int checkRank(int cnt, boolean bonusFlag){
if(cnt==6){
return 1;
}
if(cnt==5&&bonusFlag){
return 2;
}
if(cnt==5){
return 3;
}
if(cnt==4){
return 4;
}
if(cnt==3){
return 5;
}
return 0;
}
// TODO: 추가 기능 구현
}