-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCheckCounter.java
More file actions
36 lines (28 loc) · 975 Bytes
/
CheckCounter.java
File metadata and controls
36 lines (28 loc) · 975 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
package lotto.domain;
import java.util.Map;
import java.util.TreeMap;
public class CheckCounter {
private final Map<Integer, Integer> checkCounter;
public CheckCounter() {
this.checkCounter = new TreeMap<>();
}
public void setInitial(int key) {
this.checkCounter.put(key, 1);
}
public int get(int key) {
return this.checkCounter.getOrDefault(key, 0);
}
public boolean has(int key) {
return this.checkCounter.containsKey(key);
}
public void countUp(int key) {
int previousValue = this.checkCounter.get(key);
this.checkCounter.put(key, previousValue + 1);
}
public int getTotalWinningMoney() {
return (5_000 * this.checkCounter.getOrDefault(3, 0))
+ (50_000 * this.checkCounter.getOrDefault(4, 0))
+ (1_500_000 * this.checkCounter.getOrDefault(5, 0))
+ (2_000_000_000 * this.checkCounter.getOrDefault(6, 0));
}
}