forked from next-step/java-lotto
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLottoResultReport.java
More file actions
42 lines (31 loc) · 1.13 KB
/
LottoResultReport.java
File metadata and controls
42 lines (31 loc) · 1.13 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
package step2.domain;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class LottoResultReport {
private Map<Rank, Integer> lottoResultReport;
public LottoResultReport() {
lottoResultReport = new HashMap<>();
}
public int recordRank(Rank rank) {
Integer value = lottoResultReport.getOrDefault(rank, 0);
lottoResultReport.put(rank, value + 1);
return lottoResultReport.get(rank);
}
public int findReportByMatchCount(Rank rank) {
return lottoResultReport.getOrDefault(rank, 0);
}
public double calculateProfit(int gameCount) {
long profit = sum();
long cost = gameCount * LottoCommonValue.DEFAULT_LOTTO_PRICE.value();
return calculateProfitRate(profit, cost);
}
long sum() {
Set<Map.Entry<Rank, Integer>> entries = lottoResultReport.entrySet();
return entries.stream().mapToLong(e -> e.getKey().prizeMoney() * e.getValue()).sum();
}
double calculateProfitRate(long profit, long cost) {
double rate = (profit - cost) * 1.0 / cost;
return Math.round(rate * 100) / 100.0;
}
}