-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathOutputView.java
More file actions
59 lines (47 loc) · 2.12 KB
/
OutputView.java
File metadata and controls
59 lines (47 loc) · 2.12 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package lotto.View;
import lotto.domain.Lottos;
import lotto.service.WinningRank;
import java.text.DecimalFormat;
import java.util.Map;
public class OutputView {
private static final String WINNING_DETAILS_MESSAGE = "%d개 일치 (%s원) - %d개\n";
private static final String WINNING_DETAILS_MESSAGE_WITH_BONUS_MASSAGE = "%d개 일치, 보너스 볼 일치 (%s원) - %d개\n";
public static void printHowManyLottoUserPurchased(int lottoQuantity) {
System.out.println(lottoQuantity + "개를 구매했습니다.");
}
public static void printLottos(Lottos lottos) {
lottos.getLottos()
.forEach(lotto -> System.out.println(lotto.getNumbers().toString()));
}
public static void printWinningDetails(Map<WinningRank, Integer> winningDetails) {
System.out.println("당첨 통계");
System.out.println("---");
winningDetails.entrySet().stream()
.filter(entry->entry.getKey()!=WinningRank.LAST_PLACE)
.forEach(entry->{
if (entry.getKey() == WinningRank.SECOND_PLACE){
printWinningDetailsWithBonus(entry);
}
printWinningDetails(entry);
});
}
public static void printProfitRate(double profitRate) {
System.out.printf("총 수익률은 %.1f%%입니다.\n", profitRate);
}
private static void printWinningDetails(Map.Entry<WinningRank, Integer> entry) {
System.out.printf(WINNING_DETAILS_MESSAGE,
entry.getKey().getMatchCount(),
getFormattingPrice(entry.getKey().getPrize()),
entry.getValue());
}
private static void printWinningDetailsWithBonus(Map.Entry<WinningRank, Integer> entry) {
System.out.printf(WINNING_DETAILS_MESSAGE_WITH_BONUS_MASSAGE,
entry.getKey().getMatchCount(),
getFormattingPrice(entry.getKey().getPrize()),
entry.getValue());
}
private static String getFormattingPrice(int prize) {
DecimalFormat df = new DecimalFormat("###,###");
return df.format(prize);
}
}