forked from knh4437/java-lotto
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGameController.java
More file actions
42 lines (34 loc) · 1.48 KB
/
GameController.java
File metadata and controls
42 lines (34 loc) · 1.48 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
package lotto.controller;
import lotto.view.LottoInputView;
import lotto.view.LottoOutputView;
import lotto.model.Lotto;
import lotto.model.LottoResult;
import java.util.List;
import java.util.stream.Collectors;
public class GameController {
private final LottoInputView lottoInputView;
private final LottoController lottoService;
private final LottoOutputView lottoOutputView;
private static final int LOTTO_PRICE = 1000;
public GameController() {
this.lottoService = new LottoController();
this.lottoOutputView = new LottoOutputView();
this.lottoInputView = new LottoInputView();
}
/**
* 게임 시작
*/
public void start() {
int money = lottoInputView.receiveUserMoneyInput();
List<Lotto> lottoList = lottoService.generateLottoNumber(money / LOTTO_PRICE);
lottoOutputView.printLotto(lottoList.size(), lottoList.stream()
.map(Lotto::getNumbers)
.collect(Collectors.toList()));
List<Integer> winningNumbers = lottoInputView.receiveWinningNumberInput();
int bonusNumber = lottoInputView.receiveBonusNumberInput(winningNumbers);
LottoResult result = lottoService.checkWinningResult(lottoList, winningNumbers, bonusNumber);
lottoOutputView.printWinningStatistics(result.getRankDescriptions(), result.getRankCounts());
double profitRate = lottoService.calculateProfitRate(money, result);
lottoOutputView.printProfitRate(profitRate);
}
}