-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathLottoRank.java
More file actions
39 lines (32 loc) · 1.07 KB
/
LottoRank.java
File metadata and controls
39 lines (32 loc) · 1.07 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
package lotto;
import java.util.Arrays;
public enum LottoRank {
FIRST(6, false, 2_000_000_000),
SECOND(5, true, 30_000_000),
THIRD(5, false,1_500_000),
FOURTH(4, false, 50_000),
FIFTH(3, false, 5_000),
NONE(0, false, 0);
public final int matchCount;
public final boolean isBonusMatch;
public final int prize;
LottoRank(int matchCount, boolean isBonusMatch, int prize) {
this.matchCount = matchCount;
this.isBonusMatch = isBonusMatch;
this.prize = prize;
}
public int getPrize() {
return prize;
}
public static LottoRank fromMatchCount(int matchCount, boolean isBonusMatch) {
return Arrays.stream(values())
.filter(match -> match.matchCount == matchCount && match.isBonusMatch == isBonusMatch)
.findFirst()
.orElse(NONE);
}
@Override
public String toString() {
String bonusText = isBonusMatch ? ", 보너스 볼 일치" : "";
return String.format("%d개 일치%s (%,d원)", matchCount, bonusText, prize);
}
}