forked from next-step/java-lotto
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLottoTicket.java
More file actions
59 lines (46 loc) · 1.46 KB
/
LottoTicket.java
File metadata and controls
59 lines (46 loc) · 1.46 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.domain;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* 로또 티켓을 관리하는 클래스 입니다.
*/
public class LottoTicket {
/** 로또 가격 */
public static final int LOTTO_PRICE = 1000;
/** 로또 숫자의 최솟값 */
public static final int MIN_LOTTO_NUMBER = 1;
/** 로또 숫자의 최댓값 */
public static final int MAX_LOTTO_NUMBER = 45;
/** 로또 번호 */
private final List<Integer> numbers;
public LottoTicket(List<Integer> numbers) {
this.numbers = numbers;
}
/**
* 로또 티켓을 반환 합니다.
*
* @return List<Integer>
*/
public List<Integer> get() {
return numbers;
}
/**
* 맞춘 결과를 반환 합니다.
*
* @param winningLottoTicket 당첨된 로또 티켓
* @param bonusNumber 보너스 번호
*
* @return LottoPrize
*/
public LottoPrize win(LottoTicket winningLottoTicket, int bonusNumber) {
Set<Integer> intersection = new HashSet<>(numbers);
intersection.retainAll(winningLottoTicket.get());
int winningCount = intersection.size();
int winningBonusNumberCount = (int) numbers.stream()
.filter(n -> n == bonusNumber)
.count();
boolean isWonBonusNumber = 1 == winningBonusNumberCount;
return LottoPrize.findByMatchesAndBonus(winningCount, isWonBonusNumber);
}
}