From 02917c792ab8486b9cd42b0b062e710c7609b72c Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 10 Jan 2026 14:18:28 +0900 Subject: [PATCH 1/7] =?UTF-8?q?docs:=20=EB=A6=AC=EB=93=9C=EB=AF=B8?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/README.md b/README.md index b168a180..4c58dde9 100644 --- a/README.md +++ b/README.md @@ -1 +1,27 @@ # javascript-planetlotto-precourse + +# javascript-planetlotto-precourse + +## ๐Ÿ›ก๏ธ (ํ–‰์„ฑ๋กœ๋˜) + +์„ค๋ช… : +์ฃผ์–ด์ง„ view๋ฅผ ๊ฐ€์ง€๊ณ  ์–ด๋–ป๊ฒŒ ๊ตฌํ˜„์„ ํ•  ๊ฒƒ์ธ๊ฐ€? + +๋‹ค๋ฅธ ์‚ฌ๋žŒ์ด ๋งŒ๋“ค์–ด ๋†“์€ ์ฝ”๋“œ๋ฅผ ๋ณด๊ณ  ์ดํ•ด๋ฅผ ํ•œ ๋’ค, ์–ด๋–ป๊ฒŒ ๊ทธ ๋‹ค์Œ์„ ์ด์–ด๋‚˜๊ฐˆ ๊ฒƒ์ธ๊ฐ€๊ฐ€ main ํฌ์ธํŠธ์ž„ +๋‚ฏ์„  ๋ฉ”์„œ๋“œ์— ๋Œ€ํ•ด์„œ ์ž˜ ์ ์‘ํ•ด๋ณด๋„๋ก ํ•˜์ž! + +### (๋ฉ”์„œ๋“œ์„ค๋ช…) + +- [x] **printPurchasedLottos ์„ค๋ช…:** ์ผ๊ธ‰ ์ปฌ๋ ‰์…˜์„ ์ด์šฉํ•ด์•ผํ•˜์ง€๋งŒ, ์บก์Аํ™”๋ฅผ ํ•˜๋ฉด ์•ˆ ๋จ + ์ˆซ์ž ๋ฐฐ์—ด์„ ๋ฌธ์ž์—ด๋กœ ๋งŒ๋“ค๊ธฐ ๋•Œ๋ฌธ์— ์กฐ์‹ฌํ•ด์•ผํ•จ +- [x] **printResult ์„ค๋ช…:** ๊ฒฐ๊ณผ๋ฅผ ๋‹ด๋Š” ๋ฐฐ์—ด์ด ์žˆ์–ด์•ผํ•จ + +- [x] **askWinningLotto ์„ค๋ช…:** ์ˆซ์ž ๋ฐฐ์—ด์ด๊ธฐ ๋–„๋ฌธ์— ๋น„๊ต์— ์œ ์˜ํ•˜์ž + +### (๋ฉ”์„œ๋“œ์„ค๋ช…) + +- [x] **1** ๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅ ๋ฐ›๋Š”๋‹ค. +- [x] **2** ๋กœ๋˜ ๋ฒˆํ˜ธ๋ฅผ ๋ฐ˜ํ™˜ํ•ด์„œ ์ผ๊ธ‰ ์ปฌ๋ ‰์…˜ํ™”๋ฅผ ์‹œ์ผœ ๋กœ๋˜ ํ‹ฐ์ผ“์„ ์ƒ์„ฑํ•œ๋‹ค. +- [x] **3** ํ˜•์‹์— ๋งž๊ฒŒ ๋‹น์ฒจ ๋ฒˆํ˜ธ์™€, ๋กœ๋˜ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•œ๋‹ค. +- [x] ๊ฒฐ๊ณผ๋ฅผ ๊ณ„์‚ฐํ•˜๋Š” ๊ฐ์ฒด๋ฅผ ๋งŒ๋“ค์–ด ๊ฒฐ๊ณผ๋ฅผ ์ €์žฅํ•œ๋‹ค. +- [x] ์ €์žฅํ•œ ๊ฒฐ๊ณผ์— ๋”ฐ๋ผ ์ถœ๋ ฅํ•œ๋‹ค. From 2d32abfc36fc612698b733180d3ce6afa47cfdca Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 10 Jan 2026 14:21:23 +0900 Subject: [PATCH 2/7] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EC=8B=9C?= =?UTF-8?q?=EB=8F=84=20=EA=B8=B0=EB=8A=A5=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 26 ++++++++++++++++++++++++- src/model/LottoManager.js | 41 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/model/LottoManager.js diff --git a/src/App.js b/src/App.js index 091aa0a5..bfc428ef 100644 --- a/src/App.js +++ b/src/App.js @@ -1,5 +1,29 @@ +import { InputView } from "./view.js"; +import { Console } from "@woowacourse/mission-utils"; +import LottoManager from "./model/LottoManager.js"; class App { - async run() {} + async run() { + // [1] ๊ตฌ์ž…๊ธˆ์•ก ์ž…๋ ฅ + while (true) { + try { + const purChaseMoney = await InputView.askAmount(); + const lottoManager = new LottoManager(); + const tryNumber = lottoManager.calculateTryNumber(purChaseMoney); + Console.print(tryNumber); + } catch (error) { + Console.print(error.message); + } + + //[2] ๊ตฌ์ž… ๊ธˆ์•ก์„ ๋ฐ”ํƒ•์œผ๋กœ ๋กœ๋˜ ๋ฒˆํ˜ธ ์ƒ์„ฑ + + // try { + // const inputView = await InputView.askWinningLotto(); + // Console.print(inputView); + // } catch (error) { + // Console.print(error.message); + // } + } + } } export default App; diff --git a/src/model/LottoManager.js b/src/model/LottoManager.js new file mode 100644 index 00000000..af0cae22 --- /dev/null +++ b/src/model/LottoManager.js @@ -0,0 +1,41 @@ +class LottoManager { + #tryNumber; + #lottoList; + constructor() { + this.#tryNumber; + this.#lottoList = []; + } + calculateTryNumber(purChaseMoney) { + this.validateMoney(purChaseMoney); + return purChaseMoney / 500; // ์ด๋”ฐ ์ˆ˜์ •ํ•ด์•ผํ•จ + } + makeLottoList() {} + getLottoList() { + return this.#lottoList; + } + + validateMoney(purChaseMoney) { + const testPurchaseMoney = purChaseMoney.toString().split(""); + if (!purChaseMoney) + throw new Error("[ERROR] ๊ตฌ์ž…๊ธˆ์•ก์€ ๋“ค์–ด์˜ค์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค."); + if (testPurchaseMoney[0] === "0") + throw new Error("[ERROR] ๋งจ ์•ž์ž๋ฆฌ์— 0์ด ์กด์žฌํ•˜๋ฉด ์•ˆ ๋ฉ๋‹ˆ๋‹ค."); + testPurchaseMoney.forEach((num) => { + if (Number.isNaN(Number(num))) + throw new Error("[ERROR] ๋ฌธ์ž๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค."); + }); + if (testPurchaseMoney.includes(" ")) + throw new Error("[ERROR] ๋ฌธ์ž์— ๊ณต๋ฐฑ์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค."); + const integerNumner = Number(purChaseMoney); + if (Number.isNaN(integerNumner)) + throw new Error("[ERROR] ๊ตฌ์ž…๊ธˆ์•ก์€ ์ˆซ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."); + if (!Number.isInteger(integerNumner)) + throw new Error("[ERROR] ๊ตฌ์ž…๊ธˆ์•ก์€ ์ •์ˆ˜์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."); + if (integerNumner <= 0) + throw new Error("[ERROR] ๊ตฌ์ž…๊ธˆ์•ก์€ 0๋ณด๋‹ค ์ปค์•ผํ•ฉ๋‹ˆ๋‹ค."); + if (integerNumner % 500 !== 0) { + throw new Error("[ERROR] ๊ตฌ์ž…๊ธˆ์•ก์€ 500์› ๋‹จ์œ„์—ฌ์•ผํ•ฉ๋‹ˆ๋‹ค."); + } + } +} +export default LottoManager; From b7bdb11bfb47e2c5c35970f0316fa63bc9139ef4 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 10 Jan 2026 14:32:58 +0900 Subject: [PATCH 3/7] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=EB=A5=BC=20?= =?UTF-8?q?=EC=82=B0=20=EA=B0=9C=EC=88=98=EC=97=90=20=EB=A7=9E=EC=B6=94?= =?UTF-8?q?=EC=96=B4=EC=84=9C=20=EB=A1=9C=EB=98=90=20=EB=B0=B0=EC=97=B4=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 17 +++++++++++++++-- src/model/LottoManager.js | 15 ++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/App.js b/src/App.js index bfc428ef..64eab219 100644 --- a/src/App.js +++ b/src/App.js @@ -1,15 +1,28 @@ import { InputView } from "./view.js"; +import { OutputView } from "./view.js"; import { Console } from "@woowacourse/mission-utils"; import LottoManager from "./model/LottoManager.js"; class App { async run() { - // [1] ๊ตฌ์ž…๊ธˆ์•ก ์ž…๋ ฅ while (true) { try { + // [1] ๊ตฌ์ž…๊ธˆ์•ก ์ž…๋ ฅ + const purChaseMoney = await InputView.askAmount(); const lottoManager = new LottoManager(); const tryNumber = lottoManager.calculateTryNumber(purChaseMoney); - Console.print(tryNumber); + + //[2] ๋กœ๋˜ ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑ + lottoManager.makeLottoList(tryNumber); + const lottoList = lottoManager.getLottoList(); + //[3] outputView๋ฅผ ํ™œ์šฉํ•ด์„œ ๋ช‡๊ฐœ๋ฅผ ์ถœ๋ ฅํ–ˆ๋Š”์ง€ ์ถœ๋ ฅ + Console.print(""); + OutputView.printPurchasedLottos(lottoList); + //[4] ์‚ฌ์šฉ์ž์—๊ฒŒ ๋กœ๋˜ ๋ฒˆํ˜ธ ์ž…๋ ฅ + + //[5] ์–ผ๋งˆ๋‚˜ ๋งž์ท„๋Š”์ง€ ๊ณ„์‚ฐ -> ๋ฆฌ์ŠคํŠธ๋กœ ๊ด€๋ฆฌ + + //[6] ๊ณ„์‚ฐ ๊ฒฐ๊ณผ ์ถœ๋ ฅ } catch (error) { Console.print(error.message); } diff --git a/src/model/LottoManager.js b/src/model/LottoManager.js index af0cae22..ba9c3dd4 100644 --- a/src/model/LottoManager.js +++ b/src/model/LottoManager.js @@ -1,3 +1,5 @@ +import { Random } from "@woowacourse/mission-utils"; + class LottoManager { #tryNumber; #lottoList; @@ -9,11 +11,22 @@ class LottoManager { this.validateMoney(purChaseMoney); return purChaseMoney / 500; // ์ด๋”ฐ ์ˆ˜์ •ํ•ด์•ผํ•จ } - makeLottoList() {} + makeLottoList(tryNumber) { + for (let index = 0; index < tryNumber; index++) { + this.#lottoList[index] = this.makeRandomVariavle(); + } + } getLottoList() { return this.#lottoList; } + makeRandomVariavle() { + const lottoNumber = Random.pickUniqueNumbersInRange(1, 30, 5).sort( + (a, b) => a - b + ); + return lottoNumber; + } + validateMoney(purChaseMoney) { const testPurchaseMoney = purChaseMoney.toString().split(""); if (!purChaseMoney) From d119e7cccf7bb977d968bf70d56f279c30ca9aeb Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 10 Jan 2026 14:52:58 +0900 Subject: [PATCH 4/7] =?UTF-8?q?feat:=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=EC=97=90=EA=B2=8C=20=EC=88=AB=EC=9E=90=20=EB=B0=B0=EC=97=B4=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=20=EB=B0=9B=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 30 +++++++++++++++--------------- src/model/Validate.js | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 src/model/Validate.js diff --git a/src/App.js b/src/App.js index 64eab219..57217cad 100644 --- a/src/App.js +++ b/src/App.js @@ -2,41 +2,41 @@ import { InputView } from "./view.js"; import { OutputView } from "./view.js"; import { Console } from "@woowacourse/mission-utils"; import LottoManager from "./model/LottoManager.js"; +import Validate from "./model/Validate.js"; class App { async run() { while (true) { try { // [1] ๊ตฌ์ž…๊ธˆ์•ก ์ž…๋ ฅ - const purChaseMoney = await InputView.askAmount(); const lottoManager = new LottoManager(); const tryNumber = lottoManager.calculateTryNumber(purChaseMoney); - //[2] ๋กœ๋˜ ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑ lottoManager.makeLottoList(tryNumber); const lottoList = lottoManager.getLottoList(); //[3] outputView๋ฅผ ํ™œ์šฉํ•ด์„œ ๋ช‡๊ฐœ๋ฅผ ์ถœ๋ ฅํ–ˆ๋Š”์ง€ ์ถœ๋ ฅ Console.print(""); OutputView.printPurchasedLottos(lottoList); - //[4] ์‚ฌ์šฉ์ž์—๊ฒŒ ๋กœ๋˜ ๋ฒˆํ˜ธ ์ž…๋ ฅ - + break; //[5] ์–ผ๋งˆ๋‚˜ ๋งž์ท„๋Š”์ง€ ๊ณ„์‚ฐ -> ๋ฆฌ์ŠคํŠธ๋กœ ๊ด€๋ฆฌ - //[6] ๊ณ„์‚ฐ ๊ฒฐ๊ณผ ์ถœ๋ ฅ } catch (error) { Console.print(error.message); + continue; + } + } + while (true) { + try { + //[4] ์‚ฌ์šฉ์ž์—๊ฒŒ ๋กœ๋˜ ๋ฒˆํ˜ธ ์ž…๋ ฅ + const winningLottoNumber = await InputView.askWinningLotto(); + Validate.winningNumber(winningLottoNumber); + Console.print(`ํ…Œ์ŠคํŠธ ์œ„๋‹๋„˜๋ฒ„ : ${winningLottoNumber}`); + break; + } catch (error) { + Console.print(error.message); + continue; } - - //[2] ๊ตฌ์ž… ๊ธˆ์•ก์„ ๋ฐ”ํƒ•์œผ๋กœ ๋กœ๋˜ ๋ฒˆํ˜ธ ์ƒ์„ฑ - - // try { - // const inputView = await InputView.askWinningLotto(); - // Console.print(inputView); - // } catch (error) { - // Console.print(error.message); - // } } } } - export default App; diff --git a/src/model/Validate.js b/src/model/Validate.js new file mode 100644 index 00000000..3c873b05 --- /dev/null +++ b/src/model/Validate.js @@ -0,0 +1,21 @@ +class Validate { + static winningNumber(winningNumber) { + winningNumber.forEach((num) => { + if (num < 0 || num > 30) + throw new Error("[ERROR] ์ˆซ์ž ๋ฒ”์œ„๊ฐ€ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค."); + if (Number.isNaN(num)) + throw new Error("[ERROR] ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๋ฌธ์ž๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค."); + if (!Number.isInteger(num)) { + throw new Error("[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” ์ •์ˆ˜๋กœ ์ž…๋ ฅ๋ฐ›์•„์•ผ ํ•ฉ๋‹ˆ๋‹ค."); + } + }); + if (winningNumber.includes("")) + throw new Error(`[ERROR] ๊ณต๋ฐฑ์„ ํฌํ•จํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.`); + if (winningNumber.length !== 6) + throw new Error(`[ERROR] 6์ž๋ฆฌ ์ˆ˜๋ฅผ ์ž…๋ ฅ ๋ฐ›์•„์•ผํ•ฉ๋‹ˆ๋‹ค.`); + const testSetNumber = new Set(winningNumber); + if (testSetNumber.size !== winningNumber.length) + throw new Error(`[ERROR] ์ค‘๋ณต๊ฐ’์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.`); + } +} +export default Validate; From 1b139ad50594694ab1490bc214a4831388b960a3 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 10 Jan 2026 15:30:58 +0900 Subject: [PATCH 5/7] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=20=EA=B3=84=EC=82=B0=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 13 ++++++++--- src/model/ResultManager.js | 45 ++++++++++++++++++++++++++++++++++++++ src/model/Validate.js | 12 ++++++++++ 3 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 src/model/ResultManager.js diff --git a/src/App.js b/src/App.js index 57217cad..2487e446 100644 --- a/src/App.js +++ b/src/App.js @@ -3,6 +3,7 @@ import { OutputView } from "./view.js"; import { Console } from "@woowacourse/mission-utils"; import LottoManager from "./model/LottoManager.js"; import Validate from "./model/Validate.js"; +import ResultManager from "./model/resultManager.js"; class App { async run() { while (true) { @@ -18,7 +19,6 @@ class App { Console.print(""); OutputView.printPurchasedLottos(lottoList); break; - //[5] ์–ผ๋งˆ๋‚˜ ๋งž์ท„๋Š”์ง€ ๊ณ„์‚ฐ -> ๋ฆฌ์ŠคํŠธ๋กœ ๊ด€๋ฆฌ //[6] ๊ณ„์‚ฐ ๊ฒฐ๊ณผ ์ถœ๋ ฅ } catch (error) { Console.print(error.message); @@ -27,10 +27,17 @@ class App { } while (true) { try { - //[4] ์‚ฌ์šฉ์ž์—๊ฒŒ ๋กœ๋˜ ๋ฒˆํ˜ธ ์ž…๋ ฅ + //[4] ์‚ฌ์šฉ์ž์—๊ฒŒ ๋กœ๋˜ ๋ฒˆํ˜ธ ์ž…๋ ฅ -> ์ˆซ์ž ๋ฐฐ์—ด๋กœ ์ž…๋ ฅ ๋จ const winningLottoNumber = await InputView.askWinningLotto(); Validate.winningNumber(winningLottoNumber); - Console.print(`ํ…Œ์ŠคํŠธ ์œ„๋‹๋„˜๋ฒ„ : ${winningLottoNumber}`); + // Console.print(`ํ…Œ์ŠคํŠธ ์œ„๋‹๋„˜๋ฒ„ : ${winningLottoNumber}`); + Console.print(""); + const bonusNumber = await InputView.askBonusNumber(); + Validate.bonusNumber(bonusNumber); + //[5] ์–ผ๋งˆ๋‚˜ ๋งž์ท„๋Š”์ง€ ๊ณ„์‚ฐ -> ๋ฆฌ์ŠคํŠธ๋กœ ๊ด€๋ฆฌ + const resultManager = new ResultManager(); + resultManager. + break; } catch (error) { Console.print(error.message); diff --git a/src/model/ResultManager.js b/src/model/ResultManager.js new file mode 100644 index 00000000..3fa4f961 --- /dev/null +++ b/src/model/ResultManager.js @@ -0,0 +1,45 @@ +class ResultManager { + #resultList; + + static lottoPrizeIndex = { + 2: { index: 0 }, + "2b": { index: 0 }, // ํ•„์š” + 3: { index: 1 }, + "3b": { index: 1 }, // ํ•„์š” + 4: { index: 2 }, // ํ•„์š” + "4b": { index: 3 }, // ํ•„์š” + 5: { index: 4 }, // 1๋“ฑ + }; + + constructor() { + this.#resultList = [0, 0, 0, 0, 0]; + } + calculateIncom(lottoList, winningNumber, bonusNumber) { + const integerBonus = Number(bonusNumber); + + for (const lotto of lottoList) { + const match = winningNumber.filter((num) => + lotto.getLotto().includes(num) + ).length; + + const prizeIndex = practice.lottoPrizeIndex(match); + if (prizeIndex.index === 2 && lottoList.includes(integerBonus)) { + this.#resultList[prizeIndex.index] += 1; + } else if (prizeIndex.index === 3 && lottoList.includes(integerBonus)) + this.#resultList[prizeIndex.index] += 1; + else if (prizeIndex.index === 4 && !lottoList.includes(integerBonus)) + this.#resultList[2] += 1; + else if (prizeIndex.index === 4 && lottoList.includes(integerBonus)) + this.#resultList[3] += 1; + else if (prizeIndex) { + this.#resultList[prizeIndex.index] += 1; + } + } + } + + getResultList() { + return this.#resultList; + } +} + +export default ResultManager; diff --git a/src/model/Validate.js b/src/model/Validate.js index 3c873b05..871d11be 100644 --- a/src/model/Validate.js +++ b/src/model/Validate.js @@ -17,5 +17,17 @@ class Validate { if (testSetNumber.size !== winningNumber.length) throw new Error(`[ERROR] ์ค‘๋ณต๊ฐ’์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.`); } + + static bonusNumber(winningNumber, number) { + const integerNumber = Number(number); + if (number < 0 || number > 46) + throw new Error("[ERROR] ์ˆซ์ž ๋ฒ”์œ„๊ฐ€ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค."); + if (winningNumber.includes(integerNumber)) + throw new Error("[ERROR] ๋ณด๋„ˆ์Šค๋ฒˆํ˜ธ๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค."); + if (!Number.isInteger(integerNumber)) { + throw new Error("[ERROR] ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋Š” ์ •์ˆ˜๋ฅผ ์ž…๋ ฅ ๋ฐ›์•„์•ผํ•ฉ๋‹ˆ๋‹ค."); + } + } } + export default Validate; From f0eaa5c13a8f33eb1f06062ed948c2041ba323f3 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 10 Jan 2026 16:40:11 +0900 Subject: [PATCH 6/7] =?UTF-8?q?feat:=20=EA=B3=84=EC=82=B0=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?=ED=9B=84=20=EC=B6=9C=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 47 +++++++++++++++++++++++++++++--------- src/model/ResultManager.js | 43 +++++++++++++++++++++------------- 2 files changed, 63 insertions(+), 27 deletions(-) diff --git a/src/App.js b/src/App.js index 2487e446..dc828e25 100644 --- a/src/App.js +++ b/src/App.js @@ -3,9 +3,27 @@ import { OutputView } from "./view.js"; import { Console } from "@woowacourse/mission-utils"; import LottoManager from "./model/LottoManager.js"; import Validate from "./model/Validate.js"; -import ResultManager from "./model/resultManager.js"; +import ResultManager from "./model/ResultManager.js"; class App { async run() { + const lottoList = await this.addPurChaseMoney(); + const winningNumber = await this.addWinningLottoNumber(lottoList); + const bonusNumber = await this.addbonusNumber(winningNumber); + //[5] ์–ผ๋งˆ๋‚˜ ๋งž์ท„๋Š”์ง€ ๊ณ„์‚ฐ -> ๋ฆฌ์ŠคํŠธ๋กœ ๊ด€๋ฆฌ + const resultManager = new ResultManager(); + resultManager.calculateIncom(lottoList, winningNumber, bonusNumber); + //[6] ๊ณ„์‚ฐ ๊ฒฐ๊ณผ ์ถœ๋ ฅ + const resultList = resultManager.getResultList(); + + // Console.print(`ํ…Œ์ŠคํŠธ์šฉ ์ถœ๋ ฅ: ${resultList}`); + + for (const num of resultList) { + OutputView.getCount(num); + } + OutputView.printResult(); + } + + async addPurChaseMoney() { while (true) { try { // [1] ๊ตฌ์ž…๊ธˆ์•ก ์ž…๋ ฅ @@ -18,30 +36,37 @@ class App { //[3] outputView๋ฅผ ํ™œ์šฉํ•ด์„œ ๋ช‡๊ฐœ๋ฅผ ์ถœ๋ ฅํ–ˆ๋Š”์ง€ ์ถœ๋ ฅ Console.print(""); OutputView.printPurchasedLottos(lottoList); - break; - //[6] ๊ณ„์‚ฐ ๊ฒฐ๊ณผ ์ถœ๋ ฅ + return lottoList; } catch (error) { Console.print(error.message); - continue; } } + } + + async addWinningLottoNumber() { while (true) { try { //[4] ์‚ฌ์šฉ์ž์—๊ฒŒ ๋กœ๋˜ ๋ฒˆํ˜ธ ์ž…๋ ฅ -> ์ˆซ์ž ๋ฐฐ์—ด๋กœ ์ž…๋ ฅ ๋จ + Console.print(""); const winningLottoNumber = await InputView.askWinningLotto(); Validate.winningNumber(winningLottoNumber); // Console.print(`ํ…Œ์ŠคํŠธ ์œ„๋‹๋„˜๋ฒ„ : ${winningLottoNumber}`); Console.print(""); - const bonusNumber = await InputView.askBonusNumber(); - Validate.bonusNumber(bonusNumber); - //[5] ์–ผ๋งˆ๋‚˜ ๋งž์ท„๋Š”์ง€ ๊ณ„์‚ฐ -> ๋ฆฌ์ŠคํŠธ๋กœ ๊ด€๋ฆฌ - const resultManager = new ResultManager(); - resultManager. + return winningLottoNumber; + } catch (error) { + Console.print(error.message); + } + } + } - break; + async addbonusNumber(lottoList, winningLottoNumber) { + while (true) { + try { + const bonusNumber = await InputView.askBonusNumber(); + Validate.bonusNumber(lottoList, bonusNumber); + return bonusNumber; } catch (error) { Console.print(error.message); - continue; } } } diff --git a/src/model/ResultManager.js b/src/model/ResultManager.js index 3fa4f961..bf9f771c 100644 --- a/src/model/ResultManager.js +++ b/src/model/ResultManager.js @@ -1,36 +1,47 @@ +import { Console } from "@woowacourse/mission-utils"; + class ResultManager { #resultList; static lottoPrizeIndex = { + 0: { index: 0 }, // ํ•„์š” + 1: { index: 0 }, // ํ•„์š” + 1: { index: 0 }, // ํ•„์š” 2: { index: 0 }, - "2b": { index: 0 }, // ํ•„์š” - 3: { index: 1 }, - "3b": { index: 1 }, // ํ•„์š” - 4: { index: 2 }, // ํ•„์š” + "2b": { index: 1 }, // ํ•„์š” + 3: { index: 0 }, + "3b": { index: 2 }, // ํ•„์š” + 4: { index: 3 }, // ํ•„์š” "4b": { index: 3 }, // ํ•„์š” - 5: { index: 4 }, // 1๋“ฑ + 5: { index: 4 }, // ํ•„์š” }; constructor() { - this.#resultList = [0, 0, 0, 0, 0]; + this.#resultList = [0, 0, 0, 0, 0, 0]; } - calculateIncom(lottoList, winningNumber, bonusNumber) { + calculateIncom(lottoList, inputWinningNumber, bonusNumber) { const integerBonus = Number(bonusNumber); + const winningNumber = inputWinningNumber.map(Number); + Console.print(`ํ™•์ธ์šฉ ${winningNumber}`); for (const lotto of lottoList) { - const match = winningNumber.filter((num) => - lotto.getLotto().includes(num) - ).length; + // const lotto = lottoString.split(", "); + const match = winningNumber.filter((num) => lotto.includes(num)).length; + + const prizeIndex = ResultManager.lottoPrizeIndex[match]; + + // Console.print(prizeIndex.index); - const prizeIndex = practice.lottoPrizeIndex(match); - if (prizeIndex.index === 2 && lottoList.includes(integerBonus)) { + if (!prizeIndex) continue; + else if (prizeIndex.index === 3 && lotto.includes(integerBonus)) { this.#resultList[prizeIndex.index] += 1; - } else if (prizeIndex.index === 3 && lottoList.includes(integerBonus)) + } else if (prizeIndex.index === 3 && lotto.includes(integerBonus)) this.#resultList[prizeIndex.index] += 1; - else if (prizeIndex.index === 4 && !lottoList.includes(integerBonus)) - this.#resultList[2] += 1; - else if (prizeIndex.index === 4 && lottoList.includes(integerBonus)) + else if (prizeIndex.index === 4 && !lotto.includes(integerBonus)) this.#resultList[3] += 1; + else if (prizeIndex.index === 4 && lotto.includes(integerBonus)) + this.#resultList[4] += 1; + else if (prizeIndex.index === 5) this.#resultList[5] += 1; else if (prizeIndex) { this.#resultList[prizeIndex.index] += 1; } From 31c4a0faf8c69fdd05a6d328ec4e4f4e9f481f62 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 10 Jan 2026 16:40:24 +0900 Subject: [PATCH 7/7] =?UTF-8?q?feat:=20=EA=B3=84=EC=82=B0=20=EA=B2=80?= =?UTF-8?q?=EC=A6=9D=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/Validate.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/model/Validate.js b/src/model/Validate.js index 871d11be..2e842412 100644 --- a/src/model/Validate.js +++ b/src/model/Validate.js @@ -11,18 +11,18 @@ class Validate { }); if (winningNumber.includes("")) throw new Error(`[ERROR] ๊ณต๋ฐฑ์„ ํฌํ•จํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.`); - if (winningNumber.length !== 6) - throw new Error(`[ERROR] 6์ž๋ฆฌ ์ˆ˜๋ฅผ ์ž…๋ ฅ ๋ฐ›์•„์•ผํ•ฉ๋‹ˆ๋‹ค.`); + if (winningNumber.length !== 5) + throw new Error(`[ERROR] 5์ž๋ฆฌ ์ˆ˜๋ฅผ ์ž…๋ ฅ ๋ฐ›์•„์•ผํ•ฉ๋‹ˆ๋‹ค.`); const testSetNumber = new Set(winningNumber); if (testSetNumber.size !== winningNumber.length) throw new Error(`[ERROR] ์ค‘๋ณต๊ฐ’์ด ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.`); } - static bonusNumber(winningNumber, number) { - const integerNumber = Number(number); - if (number < 0 || number > 46) + static bonusNumber(winningLottoNumber, bonusNumber) { + const integerNumber = Number(bonusNumber); + if (integerNumber < 0 || integerNumber > 46) throw new Error("[ERROR] ์ˆซ์ž ๋ฒ”์œ„๊ฐ€ ํ‹€๋ ธ์Šต๋‹ˆ๋‹ค."); - if (winningNumber.includes(integerNumber)) + if (winningLottoNumber.includes(integerNumber)) throw new Error("[ERROR] ๋ณด๋„ˆ์Šค๋ฒˆํ˜ธ๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค."); if (!Number.isInteger(integerNumber)) { throw new Error("[ERROR] ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋Š” ์ •์ˆ˜๋ฅผ ์ž…๋ ฅ ๋ฐ›์•„์•ผํ•ฉ๋‹ˆ๋‹ค.");