-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathLottoApplication.java
More file actions
51 lines (39 loc) · 1.62 KB
/
LottoApplication.java
File metadata and controls
51 lines (39 loc) · 1.62 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
package lotto;
import lotto.view.InputView;
import lotto.view.ResultView;
public class LottoApplication {
public static void main(String[] args) {
PurchaseAmount amount = createPurchaseAmount();
ManualLottoCount manualCount = createManualLottoCount(amount);
Lottos manualLottos = createManualLottos(manualCount);
Lottos autoLottos = LottoMachine.randomLottos(amount.autoCount(manualCount));
Lottos purchased = manualLottos.merge(autoLottos);
ResultView.printPurchasedLottos(purchased, manualCount);
WinningNumbers winningNumbers = createWinningNumbers();
LottoMatchResult matchResult = purchased.matchResult(winningNumbers);
ProfitRate profitRate = new ProfitRate(matchResult.totalPrize(), amount);
ResultView.printLottoResult(matchResult, profitRate);
}
private static PurchaseAmount createPurchaseAmount() {
return InputRetry.retry(() ->
new PurchaseAmount(InputView.readPurchaseAmount())
);
}
private static ManualLottoCount createManualLottoCount(PurchaseAmount amount) {
return InputRetry.retry(() ->
new ManualLottoCount(InputView.readManualLottoCount(), amount)
);
}
private static Lottos createManualLottos(ManualLottoCount manualCount) {
return InputRetry.retry(() ->
Lottos.manualLottos(InputView.readManualLottos(manualCount.count()))
);
}
private static WinningNumbers createWinningNumbers() {
return InputRetry.retry(() -> {
Lotto winning = new Lotto(InputView.readWinningNumbers());
LottoNumber bonus = LottoNumber.of(InputView.readBonusNumber());
return new WinningNumbers(winning, bonus);
});
}
}