-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathWinningStatistics.java
More file actions
39 lines (30 loc) · 1.11 KB
/
WinningStatistics.java
File metadata and controls
39 lines (30 loc) · 1.11 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 com.nextstep.camp.lotto.domain.entity;
import java.util.Map;
import com.nextstep.camp.lotto.domain.type.Rank;
import com.nextstep.camp.lotto.domain.vo.LottoAmount;
import com.nextstep.camp.lotto.domain.vo.RateOfReturn;
public class WinningStatistics {
private final Map<Rank, Integer> resultCounts;
private final LottoAmount spent;
private WinningStatistics(Map<Rank, Integer> resultCounts, LottoAmount spent) {
this.spent = spent;
this.resultCounts = resultCounts;
}
public static WinningStatistics of(Map<Rank, Integer> resultCounts, LottoAmount spent) {
return new WinningStatistics(resultCounts, spent);
}
public int totalPrize() {
return resultCounts.entrySet().stream()
.mapToInt(entry -> entry.getKey().getPrize() * entry.getValue())
.sum();
}
public RateOfReturn calculateRateOfReturn(LottoAmount spent) {
return RateOfReturn.of(totalPrize(), spent);
}
public Map<Rank, Integer> getResultCounts() {
return resultCounts;
}
public LottoAmount getSpent() {
return spent;
}
}