forked from knh4437/java-lotto
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLottoRank.java
More file actions
38 lines (31 loc) · 1.14 KB
/
LottoRank.java
File metadata and controls
38 lines (31 loc) · 1.14 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
package lotto.model;
import java.util.Arrays;
public enum LottoRank {
FIRST(6, 2_000_000_000, "6개 일치 (2,000,000,000원)"),
SECOND(5, 30_000_000, "5개 일치, 보너스 볼 일치 (30,000,000원)"),
THIRD(5, 1_500_000, "5개 일치 (1,500,000원)"),
FOURTH(4, 50_000, "4개 일치 (50,000원)"),
FIFTH(3, 5_000, "3개 일치 (5,000원)"),
NONE(0, 0, "");
private final int matchCount;
private final int prize;
private final String description;
LottoRank(int matchCount, int prize, String description) {
this.matchCount = matchCount;
this.prize = prize;
this.description = description;
}
public static LottoRank findMatchingRank(int count, boolean bonusMatch) {
return Arrays.stream(values()) //모든 LottoRank 값을 스트림으로 변환
.filter(rank -> rank.matchCount == count)
.filter(rank -> rank != SECOND || (rank == SECOND && bonusMatch))
.findFirst()
.orElse(NONE);
}
public String getDescription() {
return description;
}
public long getPrize() {
return prize;
}
}