-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathResultView.java
More file actions
50 lines (42 loc) · 1.49 KB
/
ResultView.java
File metadata and controls
50 lines (42 loc) · 1.49 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
package lotto.view;
import lotto.LottoMatchResult;
import lotto.LottoRank;
import lotto.Lottos;
import lotto.ManualLottoCount;
import lotto.ProfitRate;
public class ResultView {
public static void printPurchasedLottos(Lottos lottos, ManualLottoCount manualCount) {
System.out.printf("수동으로 %d장, 자동으로 %d개를 구매했습니다.%n", manualCount.count(),
lottos.count() - manualCount.count());
for (String line : lottos.toDisplayStrings()) {
System.out.println(line);
}
System.out.println();
}
public static void printLottoResult(LottoMatchResult matchResult, ProfitRate profitRate) {
System.out.println("당첨 통계");
System.out.println("---------");
for (LottoRank rank : LottoRank.values()) {
printRank(matchResult, rank);
}
double rate = profitRate.value();
String status = "손해";
if (rate >= 1) {
status = "이익";
}
System.out.printf("총 수익률은 %.2f입니다.(기준이 1이기 때문에 결과적으로 %s라는 의미임)%n",
rate, status);
}
private static void printRank(LottoMatchResult matchResult, LottoRank rank) {
if (rank.isMiss()) {
return;
}
int count = matchResult.countMatches(rank);
int prize = rank.prize();
if (rank.isSecond()) {
System.out.printf("5개 일치, 보너스 볼 일치 (%d원) - %d개%n", prize, count);
return;
}
System.out.printf("%d개 일치 (%d원)- %d개%n", rank.matchCount(), prize, count);
}
}