-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathApp.js
More file actions
51 lines (42 loc) · 1.48 KB
/
App.js
File metadata and controls
51 lines (42 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
43
44
45
46
47
48
49
50
51
import LottoBundle from "./model/LottoBundle.js";
import LottoMachine from "./model/LottoMachine.js";
import LottoJudge from "./service/LottoJudge.js";
import Result from "./service/Result.js";
import Validator from "./util/Validate.js";
import { InputView, OutputView } from "./view.js";
class App {
async run() {
try {
const purchaseAmount = await InputView.askAmount();
Validator.validatePurchaseAmount(purchaseAmount);
const lottoMachine = new LottoMachine(purchaseAmount);
const lottoBundle = new LottoBundle(lottoMachine.getLottos());
console.log("");
OutputView.printPurchasedLottos(lottoBundle.getAll());
console.log("");
const winningNumbers = await InputView.askWinningLotto();
Validator.validateWinningNumbers(winningNumbers);
console.log("");
const bonusNumber = await InputView.askBonusNumber();
Validator.validateBonusNumber(bonusNumber);
console.log("");
const lottoJudge = new LottoJudge(winningNumbers, bonusNumber);
const result = new Result();
result.calculate(lottoBundle, lottoJudge);
const rankCounts = result.getRankCounts();
OutputView.printResult(
new Map([
[1, rankCounts[1]],
[2, rankCounts[2]],
[3, rankCounts[3]],
[4, rankCounts[4]],
[5, rankCounts[5]],
[0, rankCounts[6]],
])
);
} catch (error) {
OutputView.printErrorMessage(error.message);
}
}
}
export default App;