forked from next-step/java-lotto
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLottoApplication.java
More file actions
85 lines (62 loc) · 2.95 KB
/
LottoApplication.java
File metadata and controls
85 lines (62 loc) · 2.95 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package lotto;
import java.util.List;
import lotto.domain.LottoConsumer;
import lotto.domain.LottoPrize;
import lotto.domain.LottoTicket;
import lotto.domain.purchaseStrategy.AutoStrategy;
import lotto.domain.purchaseStrategy.ManualStrategy;
import lotto.dto.LottoPurchaseDto;
import lotto.factory.LottoApplicationFactory;
import lotto.service.LottoService;
import lotto.view.InputView;
import lotto.view.OutputView;
public class LottoApplication {
private final InputView inputView;
private final OutputView outputView;
private final LottoService lottoService;
public LottoApplication(InputView inputView, OutputView outputView, LottoService lottoService) {
this.inputView = inputView;
this.outputView = outputView;
this.lottoService = lottoService;
}
public void run() {
LottoConsumer consumer = new LottoConsumer();
// 로또 구매 금액 입력
int money = inputView.insertMoney();
// 수동 구매 로또 수 입력
int manuallyPurchasedLottoTicketCount = inputView.inputManuallyPurchasedLottoTicketCount();
// 수동 로또 번호 입력
List<String[]> manuallyPurchasedLottoNumbers = inputView.inputManuallyPurchasedLottoTicketNumbers(manuallyPurchasedLottoTicketCount);
// 구매 정보 DTO
LottoPurchaseDto purchaseDto = new LottoPurchaseDto(money, manuallyPurchasedLottoNumbers);
// 수동 구매로 전략 변경
lottoService.setPurchaseStrategy(new ManualStrategy());
// 수동 로또 티켓 구매
lottoService.buyLottoTicket(consumer, purchaseDto);
// 자동 구매로 전략 변경
lottoService.setPurchaseStrategy(new AutoStrategy());
// 자동 로또 티켓 구매
lottoService.buyLottoTicket(consumer, purchaseDto);
// 로또 구매 정보 출력
outputView.printLottoTicketsInformation(consumer);
// 지난 주 당첨번호 입력
String[] LastWeekWinningNumbers = inputView.inputLastWeekWinningLottoNumbers();
// 지난 주 보너스 번호 입력
int bonusNumber = inputView.inputBonusNumber();
// 지난 주 당첨 티켓 생성
LottoTicket winningTicket = lottoService.lottoNumberToTicket(LastWeekWinningNumbers);
// 맞춘 번호 개수와 맞춘 보너스 번호 결과
List<LottoPrize> winningResult = lottoService.calculate(consumer.getLottoTickets(), winningTicket, bonusNumber);
// 로또 결과 출력
outputView.printResultTitle();
lottoService.printWinningInformation(winningResult, outputView);
// 수익률 출력
double profit = lottoService.getProfit(winningResult, money);
outputView.printProfit(profit);
}
public static void main(String[] args) {
LottoApplicationFactory factory = new LottoApplicationFactory();
LottoApplication lottoApplication = factory.createLottoApplication();
lottoApplication.run();
}
}