-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathLottoRank.java
More file actions
49 lines (39 loc) · 1020 Bytes
/
LottoRank.java
File metadata and controls
49 lines (39 loc) · 1020 Bytes
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
package lotto;
import java.util.Arrays;
public enum LottoRank {
MISS(0, false, 0),
FIFTH(3, false, 5_000),
FOURTH(4, false, 50_000),
THIRD(5, false, 1_500_000),
SECOND(5, true, 30_000_000),
FIRST(6, false, 2_000_000_000);
private final int matchCount;
private final boolean hasBonus;
private final int prize;
LottoRank(int matchCount, boolean hasBonus, int prize) {
this.matchCount = matchCount;
this.hasBonus = hasBonus;
this.prize = prize;
}
public int matchCount() {
return matchCount;
}
public int prize() {
return prize;
}
public long prize(int count) {
return (long) prize * count;
}
public static LottoRank of(int matchCount, boolean hasBonus) {
return Arrays.stream(LottoRank.values())
.filter(rank -> rank.matchCount == matchCount && rank.hasBonus == hasBonus)
.findFirst()
.orElse(MISS);
}
public boolean isMiss() {
return this == MISS;
}
public boolean isSecond() {
return this == SECOND;
}
}