From 208c893022d99cfe0712f6a4547c81837cdc7113 Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Sun, 3 Nov 2024 23:28:26 +0900 Subject: [PATCH 01/40] =?UTF-8?q?docs:=20=EA=B5=AC=ED=98=84=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EB=AA=A9=EB=A1=9D=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/README.md b/README.md index 15bb106b5..97021ebef 100644 --- a/README.md +++ b/README.md @@ -1 +1,62 @@ # javascript-lotto-precourse + +## 구현 기능 목록 + +### 입력 + +- [ ] 사용자로부터 로또 구입 금액을 입력 받는다. + - [ ] 1,000원으로 나누어 떨어지지 않으면 예외 처리 + - [ ] 숫자가 아닌 경우 예외 처리 +- [ ] 사용자로부터 당첨 번호를 입력 받는다. + - [ ] 1 ~ 45 범위에 존재하지 않으면 예외 처리 + - [ ] 중복되는 숫자가 존재하면 예외 처리 + - [ ] 숫자가 아닌 경우 예외 처리 + - [ ] 공백을 포함한 경우 예외 처리 +- [ ] 당첨 번호는 쉼표(,)를 기준으로 구분한다. + - [ ] 쉼표가 아닌 구분자가 존재하면 예외 처리 +- [ ] 사용자로부터 보너스 번호를 입력 받는다. + - [ ] 1 ~ 45 범위에 존재하지 않으면 예외 처리 + - [ ] 중복되는 숫자가 존재하면 예외 처리 + - [ ] 숫자가 아닌 경우 예외 처리 + +### 출력 + +- [ ] 로또 번호를 오름차순으로 정렬한다. + +- [ ] 발행한 로또 수량 및 번호를 출력한다. + ``` + 8개를 구매했습니다. + [8, 21, 23, 41, 42, 43] + [3, 5, 11, 16, 32, 38] + [7, 11, 16, 35, 36, 44] + [1, 8, 11, 31, 41, 42] + [13, 14, 16, 38, 42, 45] + [7, 11, 30, 40, 42, 43] + [2, 13, 22, 32, 38, 45] + [1, 3, 5, 14, 22, 45] + ``` + +- [ ] 당첨 내역을 출력한다. + ``` + 3개 일치 (5,000원) - 1개 + 4개 일치 (50,000원) - 0개 + 5개 일치 (1,500,000원) - 0개 + 5개 일치, 보너스 볼 일치 (30,000,000원) - 0개 + 6개 일치 (2,000,000,000원) - 0개 + ``` + +- [ ] 수익률을 소수점 둘째 자리에서 반올림해서 출력한다. + ``` + 총 수익률은 62.5%입니다. + ``` + +- [ ] 예외 상황 시 에러 문구를 출력한다. 반드시 `[ERROR]`로 시작한다. + ``` + [ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다. + ``` + +### 로또 추첨 + +- [ ] 구입 금액에 해당하는 만큼 로또를 발행한다. +- [ ] 로또 발행 시 중복되지 않는 6개의 숫자를 뽑는다. +- [ ] 추첨 시 중복되지 않는 숫자 6개와 보너스 번호 1개를 뽑는다. \ No newline at end of file From c8972a51d52810e323133b2b0753018d21c33ea7 Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Sun, 3 Nov 2024 23:37:57 +0900 Subject: [PATCH 02/40] =?UTF-8?q?docs:=20=EA=B5=AC=ED=98=84=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EB=AA=A9=EB=A1=9D=20=EC=98=88=EC=99=B8=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 97021ebef..87ff5e434 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ - [ ] 중복되는 숫자가 존재하면 예외 처리 - [ ] 숫자가 아닌 경우 예외 처리 - [ ] 공백을 포함한 경우 예외 처리 + - [ ] 6개 미만의 숫자를 입력한 경우 예외 처리 - [ ] 당첨 번호는 쉼표(,)를 기준으로 구분한다. - [ ] 쉼표가 아닌 구분자가 존재하면 예외 처리 - [ ] 사용자로부터 보너스 번호를 입력 받는다. From 3b9a6309fa08c7a72a6a4e8fd2292a2012bb07c7 Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Sun, 3 Nov 2024 23:40:07 +0900 Subject: [PATCH 03/40] =?UTF-8?q?docs:=20=EA=B5=AC=ED=98=84=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EB=AA=A9=EB=A1=9D=20=EC=98=88=EC=99=B8=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 87ff5e434..ac20fe34c 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ - [ ] 중복되는 숫자가 존재하면 예외 처리 - [ ] 숫자가 아닌 경우 예외 처리 - [ ] 공백을 포함한 경우 예외 처리 - - [ ] 6개 미만의 숫자를 입력한 경우 예외 처리 + - [ ] 6개의 숫자를 입력하지 않은 경우 예외 처리 - [ ] 당첨 번호는 쉼표(,)를 기준으로 구분한다. - [ ] 쉼표가 아닌 구분자가 존재하면 예외 처리 - [ ] 사용자로부터 보너스 번호를 입력 받는다. From 6cf65118b01108789d6e9fe0e95befe6a32d66e2 Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 21:15:15 +0900 Subject: [PATCH 04/40] =?UTF-8?q?feat:=20Lotto=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EA=B2=80=EC=A6=9D=20=EB=A1=9C=EC=A7=81=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/Lotto.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Lotto.js b/src/Lotto.js index cb0b1527e..9a2a23444 100644 --- a/src/Lotto.js +++ b/src/Lotto.js @@ -10,6 +10,14 @@ class Lotto { if (numbers.length !== 6) { throw new Error("[ERROR] 로또 번호는 6개여야 합니다."); } + + if (new Set(numbers).size !== numbers.length) { + throw new Error("[ERROR] 로또 번호에 중복된 숫자가 있습니다."); + } + + if (numbers.some(num => num < 1 || num > 45)) { + throw new Error("[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다."); + } } // TODO: 추가 기능 구현 From 4b152a5a5426a3c9cae9ac9ea04da05524cc2e0b Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 21:18:47 +0900 Subject: [PATCH 05/40] =?UTF-8?q?feat:=20Lotto=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EB=8B=B9=EC=B2=A8=20=EB=B2=88=ED=98=B8=20=EC=9D=BC?= =?UTF-8?q?=EC=B9=98=20=EA=B0=9C=EC=88=98=EB=A5=BC=20=EB=B0=98=ED=99=98?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Lotto.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Lotto.js b/src/Lotto.js index 9a2a23444..8c29f90f2 100644 --- a/src/Lotto.js +++ b/src/Lotto.js @@ -20,7 +20,10 @@ class Lotto { } } - // TODO: 추가 기능 구현 + // 당첨 번호 일치 개수를 반환 + getMatchCount(winningNumbers) { + return this.#numbers.filter((num) => winningNumbers.includes(num)).length; + } } export default Lotto; From 2a56258098eecc5256814c467ae2a04aa493d88d Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 21:20:24 +0900 Subject: [PATCH 06/40] =?UTF-8?q?feat:=20Lotto=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EB=B3=B4=EB=84=88=EC=8A=A4=20=EB=B2=88=ED=98=B8=20?= =?UTF-8?q?=ED=8F=AC=ED=95=A8=20=EC=97=AC=EB=B6=80=EB=A5=BC=20=ED=8C=90?= =?UTF-8?q?=EB=8B=A8=ED=95=98=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Lotto.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Lotto.js b/src/Lotto.js index 8c29f90f2..302035078 100644 --- a/src/Lotto.js +++ b/src/Lotto.js @@ -24,6 +24,11 @@ class Lotto { getMatchCount(winningNumbers) { return this.#numbers.filter((num) => winningNumbers.includes(num)).length; } + + // 보너스 번호 일치 여부 확인 + hasBonusNumber(bonusNumber) { + return this.#numbers.includes(bonusNumber); + } } export default Lotto; From d311b1b0ed294993888e809aa3a2e7e0fe6f1eee Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 21:21:37 +0900 Subject: [PATCH 07/40] =?UTF-8?q?feat:=20Lotto=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20Getter=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Lotto.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Lotto.js b/src/Lotto.js index 302035078..e05d51862 100644 --- a/src/Lotto.js +++ b/src/Lotto.js @@ -29,6 +29,11 @@ class Lotto { hasBonusNumber(bonusNumber) { return this.#numbers.includes(bonusNumber); } + + // private으로 선언된 numbers를 외부에서 확인하기 위한 Getter + get Numbers() { + return this.#numbers; + } } export default Lotto; From f97fd53c1d2232a8c61fbb46146203965d3bcf3d Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 21:36:10 +0900 Subject: [PATCH 08/40] =?UTF-8?q?chore:=20MVC=20=ED=8C=A8=ED=84=B4=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9=EC=9C=BC=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20?= =?UTF-8?q?=ED=8F=B4=EB=8D=94=20=EA=B5=AC=EC=A1=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/{ => model}/Lotto.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{ => model}/Lotto.js (100%) diff --git a/src/Lotto.js b/src/model/Lotto.js similarity index 100% rename from src/Lotto.js rename to src/model/Lotto.js From 60d7a678a7264304e52c9a1bf99fa4587a3da696 Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 21:41:00 +0900 Subject: [PATCH 09/40] =?UTF-8?q?feat:=20=EC=9E=85=EB=A0=A5=20=EA=B0=92=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=EB=A5=BC=20=EC=9C=84=ED=95=9C=20InputView=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/view/InputView.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/view/InputView.js diff --git a/src/view/InputView.js b/src/view/InputView.js new file mode 100644 index 000000000..529ed5021 --- /dev/null +++ b/src/view/InputView.js @@ -0,0 +1,7 @@ +import { Console } from "@woowacourse/mission-utils" + +const InputView = { + +} + +export default InputView; \ No newline at end of file From fd3e61589f08b70105415eb08e01695fe30f2f52 Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 21:42:27 +0900 Subject: [PATCH 10/40] =?UTF-8?q?feat:=20=EC=B6=9C=EB=A0=A5=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=EB=A5=BC=20=EC=B2=98=EB=A6=AC=ED=95=98?= =?UTF-8?q?=EB=8A=94=20OutputView=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view/OutputView.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/view/OutputView.js diff --git a/src/view/OutputView.js b/src/view/OutputView.js new file mode 100644 index 000000000..0d7401ab1 --- /dev/null +++ b/src/view/OutputView.js @@ -0,0 +1,7 @@ +import { Console } from "@woowacourse/mission-utils" + +const OutputView = { + +} + +export default OutputView; \ No newline at end of file From d98bd9ed51c244e24d03e3920e232c6a787f55b6 Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 21:59:17 +0900 Subject: [PATCH 11/40] =?UTF-8?q?feat:=20InputView=20=EB=82=B4=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=EC=9E=90=20=EC=9E=85=EB=A0=A5=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view/InputView.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/view/InputView.js b/src/view/InputView.js index 529ed5021..0b24a6d1b 100644 --- a/src/view/InputView.js +++ b/src/view/InputView.js @@ -1,7 +1,11 @@ import { Console } from "@woowacourse/mission-utils" const InputView = { - + async getPurchaseAmount() { + Console.print("구입 금액을 입력해주세요."); + const input = await Console.readLineAsync(); + const amount = parseInt(input); + } } export default InputView; \ No newline at end of file From ac323a946a5dcc54472b30450dd42663d4533402 Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 22:02:34 +0900 Subject: [PATCH 12/40] =?UTF-8?q?fix:=20=EB=A1=9C=EB=98=90=20=EA=B5=AC?= =?UTF-8?q?=EC=9E=85=20=EB=A7=A4=EC=88=98=20=EB=B0=98=ED=99=98=EC=9D=84=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view/InputView.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/view/InputView.js b/src/view/InputView.js index 0b24a6d1b..782fcd5ab 100644 --- a/src/view/InputView.js +++ b/src/view/InputView.js @@ -5,6 +5,8 @@ const InputView = { Console.print("구입 금액을 입력해주세요."); const input = await Console.readLineAsync(); const amount = parseInt(input); + + return amount; } } From 7affd2b612174926d3cc6428b3d5d12967adfd80 Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 22:03:22 +0900 Subject: [PATCH 13/40] =?UTF-8?q?feat:=20=EA=B5=AC=EC=9E=85=20=EA=B8=88?= =?UTF-8?q?=EC=95=A1=20=EC=9E=85=EB=A0=A5=EC=97=90=20=EB=8C=80=ED=95=9C=20?= =?UTF-8?q?=EC=97=90=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view/InputView.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/view/InputView.js b/src/view/InputView.js index 782fcd5ab..ed11edf1e 100644 --- a/src/view/InputView.js +++ b/src/view/InputView.js @@ -6,6 +6,10 @@ const InputView = { const input = await Console.readLineAsync(); const amount = parseInt(input); + if (isNaN(amount) || amount % 1000 !== 0) { + throw new Error("[ERROR] 구입 금액은 1,000원 단위여야 합니다.") + } + return amount; } } From 71ebb833bd14b25cff8e0fd160989431edd5439d Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 22:16:10 +0900 Subject: [PATCH 14/40] =?UTF-8?q?feat:=20InputView=20=EB=82=B4=20=EB=8B=B9?= =?UTF-8?q?=EC=B2=A8=20=EB=B2=88=ED=98=B8=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EC=9E=85=EB=A0=A5=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view/InputView.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/view/InputView.js b/src/view/InputView.js index ed11edf1e..c6ae25b5b 100644 --- a/src/view/InputView.js +++ b/src/view/InputView.js @@ -11,6 +11,14 @@ const InputView = { } return amount; + }, + + async getWinningNumbers() { + Console.print("당첨 번호를 입력해 주세요."); + const input = await Console.readLineAsync(); + const numbers = input.split(",").map(Number); + + return numbers; } } From 99770c4c3bb2e7e1202e31e003cf048106597f88 Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 22:18:39 +0900 Subject: [PATCH 15/40] =?UTF-8?q?feat:=20=EB=8B=B9=EC=B2=A8=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=9E=85=EB=A0=A5=EC=97=90=20=EB=8C=80=ED=95=9C=20?= =?UTF-8?q?=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view/InputView.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/view/InputView.js b/src/view/InputView.js index c6ae25b5b..694d48a35 100644 --- a/src/view/InputView.js +++ b/src/view/InputView.js @@ -18,6 +18,10 @@ const InputView = { const input = await Console.readLineAsync(); const numbers = input.split(",").map(Number); + if (numbers.length !== 6 || numbers.some((num) => isNaN(num) || num < 1 || num >45)) { + throw new Error("[ERROR] 당첨 번호는 1부터 45 사이의 숫자 6개여야 합니다.") + } + return numbers; } } From dd2dd1e7ef999dc7f1166340fbc26c805c467f00 Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 22:21:34 +0900 Subject: [PATCH 16/40] =?UTF-8?q?chore:=20=EC=BD=94=EB=93=9C=20=EC=BB=A8?= =?UTF-8?q?=EB=B2=A4=EC=85=98=EC=9D=84=20=EB=A7=9E=EC=B6=94=EA=B8=B0=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20;=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view/InputView.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/view/InputView.js b/src/view/InputView.js index 694d48a35..9ddcde681 100644 --- a/src/view/InputView.js +++ b/src/view/InputView.js @@ -7,7 +7,7 @@ const InputView = { const amount = parseInt(input); if (isNaN(amount) || amount % 1000 !== 0) { - throw new Error("[ERROR] 구입 금액은 1,000원 단위여야 합니다.") + throw new Error("[ERROR] 구입 금액은 1,000원 단위여야 합니다."); } return amount; @@ -19,9 +19,9 @@ const InputView = { const numbers = input.split(",").map(Number); if (numbers.length !== 6 || numbers.some((num) => isNaN(num) || num < 1 || num >45)) { - throw new Error("[ERROR] 당첨 번호는 1부터 45 사이의 숫자 6개여야 합니다.") + throw new Error("[ERROR] 당첨 번호는 1부터 45 사이의 숫자 6개여야 합니다."); } - + return numbers; } } From 028542c4cb948a518e53416610df7f847808654a Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 22:23:21 +0900 Subject: [PATCH 17/40] =?UTF-8?q?feat:=20InputView=20=EB=82=B4=20=EB=B3=B4?= =?UTF-8?q?=EB=84=88=EC=8A=A4=20=EB=B2=88=ED=98=B8=20=EC=9E=85=EB=A0=A5=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view/InputView.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/view/InputView.js b/src/view/InputView.js index 9ddcde681..40e77e531 100644 --- a/src/view/InputView.js +++ b/src/view/InputView.js @@ -23,6 +23,14 @@ const InputView = { } return numbers; + }, + + async getBonusNumber() { + Console.print("보너스 번호를 입력해 주세요."); + const input = await Console.readLineAsync(); + const bonus = parseInt(input); + + return bonus; } } From 55da94c7dd983dbd8bccea81b1cbcd2942cec12a Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 22:24:46 +0900 Subject: [PATCH 18/40] =?UTF-8?q?feat:=20=EB=B3=B4=EB=84=88=EC=8A=A4=20?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EC=9E=85=EB=A0=A5=EC=97=90=20=EB=8C=80?= =?UTF-8?q?=ED=95=9C=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view/InputView.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/view/InputView.js b/src/view/InputView.js index 40e77e531..6d6a609fc 100644 --- a/src/view/InputView.js +++ b/src/view/InputView.js @@ -30,6 +30,10 @@ const InputView = { const input = await Console.readLineAsync(); const bonus = parseInt(input); + if (isNaN(bonus) || bonus < 1 || bonus > 45) { + throw new Error("[ERROR] 보너스 번호는 1부터 45 사이의 숫자여야 합니다.") + } + return bonus; } } From 34e83b6301a587fa21ab2eab30e79b7a056a3f88 Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 22:25:07 +0900 Subject: [PATCH 19/40] =?UTF-8?q?chore:=20=EC=BD=94=EB=93=9C=20=EC=BB=A8?= =?UTF-8?q?=EB=B2=A4=EC=85=98=EC=9D=84=20=EB=A7=9E=EC=B6=94=EA=B8=B0=20?= =?UTF-8?q?=EC=9C=84=ED=95=9C=20;=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view/InputView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/view/InputView.js b/src/view/InputView.js index 6d6a609fc..42064c077 100644 --- a/src/view/InputView.js +++ b/src/view/InputView.js @@ -31,7 +31,7 @@ const InputView = { const bonus = parseInt(input); if (isNaN(bonus) || bonus < 1 || bonus > 45) { - throw new Error("[ERROR] 보너스 번호는 1부터 45 사이의 숫자여야 합니다.") + throw new Error("[ERROR] 보너스 번호는 1부터 45 사이의 숫자여야 합니다."); } return bonus; From cca5a04bb3ad8387a44f262daa4427044eab3b8d Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 22:29:00 +0900 Subject: [PATCH 20/40] =?UTF-8?q?feat:=20=EA=B5=AC=EB=A7=A4=ED=95=9C=20?= =?UTF-8?q?=EB=A1=9C=EB=98=90=20=EA=B0=9C=EC=88=98=EC=99=80=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=EC=9D=84=20=EC=B6=9C=EB=A0=A5=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view/OutputView.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/view/OutputView.js b/src/view/OutputView.js index 0d7401ab1..70ba104b4 100644 --- a/src/view/OutputView.js +++ b/src/view/OutputView.js @@ -1,7 +1,10 @@ import { Console } from "@woowacourse/mission-utils" const OutputView = { - + printLottoTickes(tickets) { + Console.print(`\n${tickets.length}개를 구매했습니다.`); + tickets.forEach((ticket) => Console.print(`[${ticket.numbers.join(", ")}]`)); + } } export default OutputView; \ No newline at end of file From 06e7d344c16317e4a640ab3432496cd9e59cb38c Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 22:48:36 +0900 Subject: [PATCH 21/40] =?UTF-8?q?feat:=20=EB=8B=B9=EC=B2=A8=20=ED=86=B5?= =?UTF-8?q?=EA=B3=84=EB=A5=BC=20=EC=B6=9C=EB=A0=A5=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view/OutputView.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/view/OutputView.js b/src/view/OutputView.js index 70ba104b4..d74fa1612 100644 --- a/src/view/OutputView.js +++ b/src/view/OutputView.js @@ -4,6 +4,14 @@ const OutputView = { printLottoTickes(tickets) { Console.print(`\n${tickets.length}개를 구매했습니다.`); tickets.forEach((ticket) => Console.print(`[${ticket.numbers.join(", ")}]`)); + }, + + printResults(ranks, earningRate) { + Console.print("\n당첨 통계\n---") + Object.entries(ranks).forEach(([rank, count]) => { + Console.print(`${rank} - ${count}개`) + }); + Console.print(`총 수익률은 ${earningRate}% 입니다.`); } } From b75547a62cbacc4d3992437a7e051c408673fc2a Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 22:49:55 +0900 Subject: [PATCH 22/40] =?UTF-8?q?feat:=20=EC=97=90=EB=9F=AC=20=EB=A9=94?= =?UTF-8?q?=EC=8B=9C=EC=A7=80=EB=A5=BC=20=EC=B6=9C=EB=A0=A5=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view/OutputView.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/view/OutputView.js b/src/view/OutputView.js index d74fa1612..59ff5e435 100644 --- a/src/view/OutputView.js +++ b/src/view/OutputView.js @@ -12,6 +12,10 @@ const OutputView = { Console.print(`${rank} - ${count}개`) }); Console.print(`총 수익률은 ${earningRate}% 입니다.`); + }, + + printError(message) { + Console.print(message); } } From a1adb22d44d27349123c5624bda618f974fda60a Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 22:53:37 +0900 Subject: [PATCH 23/40] =?UTF-8?q?feat:=20Lotto=20=EA=B2=8C=EC=9E=84?= =?UTF-8?q?=EC=9D=98=20=EB=B9=84=EC=A6=88=EB=8B=88=EC=8A=A4=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B2=98=EB=A6=AC=EB=A5=BC=20=EC=9C=84=ED=95=9C=20?= =?UTF-8?q?Lottogame=20=ED=8C=8C=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/service/LottoGame.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/service/LottoGame.js diff --git a/src/service/LottoGame.js b/src/service/LottoGame.js new file mode 100644 index 000000000..894ff5f8f --- /dev/null +++ b/src/service/LottoGame.js @@ -0,0 +1,7 @@ +import Lotto from "../model/Lotto.js"; + +class LottoGame { + +} + +export default LottoGame; \ No newline at end of file From a9f388ab845880c71eae338a8b7fc35acefc8383 Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 22:55:40 +0900 Subject: [PATCH 24/40] =?UTF-8?q?feat:=20LottoGame=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=EC=9E=90=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/service/LottoGame.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/service/LottoGame.js b/src/service/LottoGame.js index 894ff5f8f..a407295a9 100644 --- a/src/service/LottoGame.js +++ b/src/service/LottoGame.js @@ -1,7 +1,14 @@ import Lotto from "../model/Lotto.js"; class LottoGame { + constructor(purchaseAmount) { + this.lottoTickets = this.generateLottoTickets(purchaseAmount); + } + generateLottoTickets(amount) { + const ticketCount = Math.floor(amount / 1000); + return Array.from({ length: ticketCount }, () => new Lotto()); + } } export default LottoGame; \ No newline at end of file From 56e3efb8c83a301d913b14d97c92ed0136a85a6f Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 23:02:52 +0900 Subject: [PATCH 25/40] =?UTF-8?q?feat:=20=ED=8B=B0=EC=BC=93=EB=B3=84=20?= =?UTF-8?q?=EB=8B=B9=EC=B2=A8=20=EC=97=AC=EB=B6=80=EB=A5=BC=20=ED=8C=90?= =?UTF-8?q?=EB=8B=A8=ED=95=98=EC=97=AC=20=EC=B9=B4=EC=9A=B4=ED=8A=B8?= =?UTF-8?q?=ED=95=98=EB=8A=94=20=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/service/LottoGame.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/service/LottoGame.js b/src/service/LottoGame.js index a407295a9..c48dbdf61 100644 --- a/src/service/LottoGame.js +++ b/src/service/LottoGame.js @@ -9,6 +9,29 @@ class LottoGame { const ticketCount = Math.floor(amount / 1000); return Array.from({ length: ticketCount }, () => new Lotto()); } + + calculateRanks(winningNumbers, bonusNumber) { + const ranks = { + "3개 일치": 0, + "4개 일치": 0, + "5개 일치": 0, + "5개 일치 + 보너스 볼 일치": 0, + "6개 일치": 0, + }; + + this.lottoTickets.forEach((ticket) => { + const matchCount = ticket.getMatchCount(winningNumbers); + const hasBonus = ticket.hasBonusNumber(bonusNumber); + + if (matchCount === 3) ranks["3개 일치"]++; + if (matchCount === 4) ranks["4개 일치"]++; + if (matchCount === 5) ranks["5개 일치"]++; + if (matchCount === 5 && hasBonus) ranks["5개 일치 + 보너스 볼 일치"]++; + if (matchCount === 6) ranks["6개 일치"]++; + }); + + return ranks; + } } export default LottoGame; \ No newline at end of file From 41fddbb88ce45e106265c317a1e405db3fd63aed Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 23:07:26 +0900 Subject: [PATCH 26/40] =?UTF-8?q?feat:=20=EB=8B=B9=EC=B2=A8=20=EA=B8=88?= =?UTF-8?q?=EC=95=A1=EC=9D=84=20=EA=B8=B0=EB=A1=9D=ED=95=B4=EB=86=93?= =?UTF-8?q?=EC=9D=80=20prizeMoney=20=EA=B0=9D=EC=B2=B4=EB=A5=BC=20data.js?= =?UTF-8?q?=EB=A1=9C=20=EA=B3=B5=ED=86=B5=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/data.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/controller/data.js diff --git a/src/controller/data.js b/src/controller/data.js new file mode 100644 index 000000000..8e43130f0 --- /dev/null +++ b/src/controller/data.js @@ -0,0 +1,9 @@ +const prizeMoney = { + "3개 일치": 5000, + "4개 일치": 50000, + "5개 일치": 1500000, + "5개 일치 + 보너스 볼 일치": 30000000, + "6개 일치": 2000000000, +}; + +export default prizeMoney; \ No newline at end of file From 38fab7add712df2c2c6a2b807e9d8e196a58dbac Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 23:12:48 +0900 Subject: [PATCH 27/40] =?UTF-8?q?chore:=20data.js=EB=A5=BC=20service=20?= =?UTF-8?q?=ED=8F=B4=EB=8D=94=EB=A1=9C=20=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/{controller => service}/data.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{controller => service}/data.js (100%) diff --git a/src/controller/data.js b/src/service/data.js similarity index 100% rename from src/controller/data.js rename to src/service/data.js From 3600dadf29e5cfcd8b527e14cfdd979138873ebe Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 23:14:51 +0900 Subject: [PATCH 28/40] =?UTF-8?q?feat:=20=EC=88=98=EC=9D=B5=EB=A5=A0?= =?UTF-8?q?=EC=9D=84=20=EA=B3=84=EC=82=B0=ED=95=98=EB=8A=94=20=EB=A9=94?= =?UTF-8?q?=EC=84=9C=EB=93=9C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/service/LottoGame.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/service/LottoGame.js b/src/service/LottoGame.js index c48dbdf61..a18d0bd31 100644 --- a/src/service/LottoGame.js +++ b/src/service/LottoGame.js @@ -1,4 +1,5 @@ import Lotto from "../model/Lotto.js"; +import prizeMoney from "./data.js"; class LottoGame { constructor(purchaseAmount) { @@ -32,6 +33,14 @@ class LottoGame { return ranks; } + + calculateEarningRate(ranks, purchaseAmount) { + const totalPrize = Object.entries(ranks).reduce( + (sum, [rank, count]) => sum + prizeMoney[rank] * count, + 0 + ); + return ((totalPrize / purchaseAmount) * 100).toFixed(1); + } } export default LottoGame; \ No newline at end of file From c53ba963bff9ce5db5db58c47f8cc4ba6e927b89 Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 23:16:19 +0900 Subject: [PATCH 29/40] =?UTF-8?q?feat:=20LottoController.js=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/LottoController.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/controller/LottoController.js diff --git a/src/controller/LottoController.js b/src/controller/LottoController.js new file mode 100644 index 000000000..27fd8411c --- /dev/null +++ b/src/controller/LottoController.js @@ -0,0 +1,9 @@ +import InputView from "../view/InputView.js"; +import OutputView from "../view/OutputView.js"; +import LottoGame from "../LottoGame.js"; + +class LottoController { + +} + +export default LottoController; \ No newline at end of file From 6b89524d810c342b10681c538573edeef1cd96fa Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 23:17:17 +0900 Subject: [PATCH 30/40] =?UTF-8?q?feat:=20LottoController=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/LottoController.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/controller/LottoController.js b/src/controller/LottoController.js index 27fd8411c..9792689da 100644 --- a/src/controller/LottoController.js +++ b/src/controller/LottoController.js @@ -3,7 +3,23 @@ import OutputView from "../view/OutputView.js"; import LottoGame from "../LottoGame.js"; class LottoController { - + async start() { + try { + const purchaseAmount = await InputView.getPurchaseAmount(); + const lottoGame = new LottoGame(purchaseAmount); + OutputView.printLottoTickets(lottoGame.lottoTickets); + + const winningNumbers = await InputView.getWinningNumbers(); + const bonusNumber = await InputView.getBonusNumber(); + + const ranks = lottoGame.calculateRanks(winningNumbers, bonusNumber); + const earningRate = this.calculateEarningRate(ranks, purchaseAmount); + + OutputView.printResults(ranks, earningRate); + } catch (error) { + OutputView.printError(error.message); + } + } } export default LottoController; \ No newline at end of file From 3ac93219261bd957e151121142728146c93e875d Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 23:17:37 +0900 Subject: [PATCH 31/40] =?UTF-8?q?fix:=20=EB=A9=94=EC=84=9C=EB=93=9C=20?= =?UTF-8?q?=EC=9D=B4=EB=A6=84=20=EC=98=A4=ED=83=80=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view/OutputView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/view/OutputView.js b/src/view/OutputView.js index 59ff5e435..73c04bc1a 100644 --- a/src/view/OutputView.js +++ b/src/view/OutputView.js @@ -1,7 +1,7 @@ import { Console } from "@woowacourse/mission-utils" const OutputView = { - printLottoTickes(tickets) { + printLottoTickets(tickets) { Console.print(`\n${tickets.length}개를 구매했습니다.`); tickets.forEach((ticket) => Console.print(`[${ticket.numbers.join(", ")}]`)); }, From 1d2a01a6c0965231518d97898b5b54b001c80057 Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 23:28:37 +0900 Subject: [PATCH 32/40] =?UTF-8?q?feat:=20=EB=9E=9C=EB=8D=A4=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=83=9D=EC=84=B1=20=EB=A1=9C=EC=A7=81=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84(=EC=98=A4=EB=A6=84=EC=B0=A8=EC=88=9C=20=EC=9E=90?= =?UTF-8?q?=EB=8F=99=20=EC=A0=95=EB=A0=AC)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/RandomNumberGenerator.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/util/RandomNumberGenerator.js diff --git a/src/util/RandomNumberGenerator.js b/src/util/RandomNumberGenerator.js new file mode 100644 index 000000000..f7df3231e --- /dev/null +++ b/src/util/RandomNumberGenerator.js @@ -0,0 +1,9 @@ +import { Random } from "@woowacourse/mission-utils"; + +const RandomNumberGenerator = { + generateLottoNumbers() { + return Random.pickUniqueNumbersInRange(1, 45, 6).sort((a, b) => a - b); + }, +}; + +export default RandomNumberGenerator; \ No newline at end of file From 7348b9c1e28c91ec99730dd25b8a2cf2bdbbdded Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 23:30:47 +0900 Subject: [PATCH 33/40] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=83=9D=EC=84=B1=20=EC=8B=9C=20=EB=9E=9C?= =?UTF-8?q?=EB=8D=A4=20=EB=B2=88=ED=98=B8=EB=A5=BC=20=EC=A0=84=EB=8B=AC?= =?UTF-8?q?=EB=B0=9B=EB=8F=84=EB=A1=9D=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/service/LottoGame.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/service/LottoGame.js b/src/service/LottoGame.js index a18d0bd31..1dead5bed 100644 --- a/src/service/LottoGame.js +++ b/src/service/LottoGame.js @@ -1,5 +1,6 @@ import Lotto from "../model/Lotto.js"; import prizeMoney from "./data.js"; +import RandomNumberGenerator from "../util/RandomNumberGenerator.js"; class LottoGame { constructor(purchaseAmount) { @@ -8,7 +9,7 @@ class LottoGame { generateLottoTickets(amount) { const ticketCount = Math.floor(amount / 1000); - return Array.from({ length: ticketCount }, () => new Lotto()); + return Array.from({ length: ticketCount }, () => new Lotto(RandomNumberGenerator.generateLottoNumbers())); } calculateRanks(winningNumbers, bonusNumber) { From 7cb7954f8830612ccc0a4714fdb60e9314b3b853 Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 23:31:13 +0900 Subject: [PATCH 34/40] =?UTF-8?q?fix:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=98=88=EC=99=B8=20=EC=B2=98=EB=A6=AC=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/Lotto.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/model/Lotto.js b/src/model/Lotto.js index e05d51862..488f44ebc 100644 --- a/src/model/Lotto.js +++ b/src/model/Lotto.js @@ -10,14 +10,6 @@ class Lotto { if (numbers.length !== 6) { throw new Error("[ERROR] 로또 번호는 6개여야 합니다."); } - - if (new Set(numbers).size !== numbers.length) { - throw new Error("[ERROR] 로또 번호에 중복된 숫자가 있습니다."); - } - - if (numbers.some(num => num < 1 || num > 45)) { - throw new Error("[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다."); - } } // 당첨 번호 일치 개수를 반환 From 6de5497261e845feb78166d68098b7265773f191 Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 23:32:26 +0900 Subject: [PATCH 35/40] =?UTF-8?q?feat:=20App.js=EC=97=90=20=EC=BB=A8?= =?UTF-8?q?=ED=8A=B8=EB=A1=A4=EB=9F=AC=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/App.js b/src/App.js index 091aa0a5d..0f33cd426 100644 --- a/src/App.js +++ b/src/App.js @@ -1,5 +1,10 @@ +import LottoController from "./controller/LottoController.js"; + class App { - async run() {} + async run() { + const controller = new LottoController(); + await controller.start(); + } } export default App; From 19d9f21e27008581d21faf761f2ccfa6b3f714de Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 23:35:39 +0900 Subject: [PATCH 36/40] =?UTF-8?q?fix:=20LottoGame.js=20=EA=B2=BD=EB=A1=9C?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/LottoController.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controller/LottoController.js b/src/controller/LottoController.js index 9792689da..6caa4c468 100644 --- a/src/controller/LottoController.js +++ b/src/controller/LottoController.js @@ -1,6 +1,6 @@ import InputView from "../view/InputView.js"; import OutputView from "../view/OutputView.js"; -import LottoGame from "../LottoGame.js"; +import LottoGame from "../service/LottoGame.js"; class LottoController { async start() { From 442c19e40a037cffb0c8a6c464f79a7bf7ee5354 Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 23:36:55 +0900 Subject: [PATCH 37/40] =?UTF-8?q?fix:=20input=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EB=B0=A9=EC=8B=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view/InputView.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/view/InputView.js b/src/view/InputView.js index 42064c077..68d72d627 100644 --- a/src/view/InputView.js +++ b/src/view/InputView.js @@ -2,8 +2,7 @@ import { Console } from "@woowacourse/mission-utils" const InputView = { async getPurchaseAmount() { - Console.print("구입 금액을 입력해주세요."); - const input = await Console.readLineAsync(); + const input = await Console.readLineAsync("구입 금액을 입력해주세요.\n"); const amount = parseInt(input); if (isNaN(amount) || amount % 1000 !== 0) { @@ -14,8 +13,7 @@ const InputView = { }, async getWinningNumbers() { - Console.print("당첨 번호를 입력해 주세요."); - const input = await Console.readLineAsync(); + const input = await Console.readLineAsync("당첨 번호를 입력해 주세요.\n"); const numbers = input.split(",").map(Number); if (numbers.length !== 6 || numbers.some((num) => isNaN(num) || num < 1 || num >45)) { @@ -26,8 +24,7 @@ const InputView = { }, async getBonusNumber() { - Console.print("보너스 번호를 입력해 주세요."); - const input = await Console.readLineAsync(); + const input = await Console.readLineAsync("보너스 번호를 입력해 주세요.\n"); const bonus = parseInt(input); if (isNaN(bonus) || bonus < 1 || bonus > 45) { From 1c07c583c16fe38ee55763ce6253f75b0e80cf4c Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 23:42:43 +0900 Subject: [PATCH 38/40] =?UTF-8?q?feat:=20=EB=8B=B9=EC=B2=A8=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=20=EB=B3=84=20=EA=B8=88=EC=95=A1=EC=9D=84=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=EC=97=90=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view/OutputView.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/view/OutputView.js b/src/view/OutputView.js index 73c04bc1a..e5a3c3658 100644 --- a/src/view/OutputView.js +++ b/src/view/OutputView.js @@ -1,4 +1,5 @@ import { Console } from "@woowacourse/mission-utils" +import prizeMoney from "../service/data.js"; const OutputView = { printLottoTickets(tickets) { @@ -9,7 +10,7 @@ const OutputView = { printResults(ranks, earningRate) { Console.print("\n당첨 통계\n---") Object.entries(ranks).forEach(([rank, count]) => { - Console.print(`${rank} - ${count}개`) + Console.print(`${rank} ${prizeMoney[rank]} - ${count}개`) }); Console.print(`총 수익률은 ${earningRate}% 입니다.`); }, From f4419e24a7520b56414ec0fdda14f47f849e58a5 Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 23:42:51 +0900 Subject: [PATCH 39/40] =?UTF-8?q?feat:=20=EB=8B=B9=EC=B2=A8=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=20=EB=B3=84=20=EA=B8=88=EC=95=A1=EC=9D=84=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=EC=97=90=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/view/OutputView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/view/OutputView.js b/src/view/OutputView.js index e5a3c3658..5374f2c0e 100644 --- a/src/view/OutputView.js +++ b/src/view/OutputView.js @@ -10,7 +10,7 @@ const OutputView = { printResults(ranks, earningRate) { Console.print("\n당첨 통계\n---") Object.entries(ranks).forEach(([rank, count]) => { - Console.print(`${rank} ${prizeMoney[rank]} - ${count}개`) + Console.print(`${rank} (${prizeMoney[rank].toLocaleString("ko-KR")}원) - ${count}개`) }); Console.print(`총 수익률은 ${earningRate}% 입니다.`); }, From e06925b47c2079f7f5afc2f74bf916103131819b Mon Sep 17 00:00:00 2001 From: tjdvjd1160 Date: Mon, 4 Nov 2024 23:44:01 +0900 Subject: [PATCH 40/40] =?UTF-8?q?feat:=20=EC=97=90=EC=99=B8=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EB=8B=A4=EC=8B=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/model/Lotto.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/model/Lotto.js b/src/model/Lotto.js index 488f44ebc..e05d51862 100644 --- a/src/model/Lotto.js +++ b/src/model/Lotto.js @@ -10,6 +10,14 @@ class Lotto { if (numbers.length !== 6) { throw new Error("[ERROR] 로또 번호는 6개여야 합니다."); } + + if (new Set(numbers).size !== numbers.length) { + throw new Error("[ERROR] 로또 번호에 중복된 숫자가 있습니다."); + } + + if (numbers.some(num => num < 1 || num > 45)) { + throw new Error("[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다."); + } } // 당첨 번호 일치 개수를 반환