From 96b87b7a957db3e32fd1441881e9494bfa9dd45f Mon Sep 17 00:00:00 2001 From: Siul Date: Fri, 21 Feb 2025 17:44:11 +0900 Subject: [PATCH 1/7] =?UTF-8?q?README=20=ED=8C=8C=EC=9D=BC=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 137 +++++++++++++++++- .../lotto/controller/LottoController.java | 4 + src/main/java/lotto/model/Lottery.java | 5 + src/main/java/lotto/view/UserInput.java | 4 + src/main/java/lotto/view/UserOutput.java | 4 + 5 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 src/main/java/lotto/controller/LottoController.java create mode 100644 src/main/java/lotto/model/Lottery.java create mode 100644 src/main/java/lotto/view/UserInput.java create mode 100644 src/main/java/lotto/view/UserOutput.java diff --git a/README.md b/README.md index 5fa2560..6434a29 100644 --- a/README.md +++ b/README.md @@ -1 +1,136 @@ -# java-lotto-precourse +## ๐Ÿš€ ๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ + +๋กœ๋˜ ๊ฒŒ์ž„ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•ด์•ผ ํ•œ๋‹ค. ๋กœ๋˜ ๊ฒŒ์ž„์€ ์•„๋ž˜์™€ ๊ฐ™์€ ๊ทœ์น™์œผ๋กœ ์ง„ํ–‰๋œ๋‹ค. + +``` +- ๋กœ๋˜ ๋ฒˆํ˜ธ์˜ ์ˆซ์ž ๋ฒ”์œ„๋Š” 1~45๊นŒ์ง€์ด๋‹ค. +- 1๊ฐœ์˜ ๋กœ๋˜๋ฅผ ๋ฐœํ–‰ํ•  ๋•Œ ์ค‘๋ณต๋˜์ง€ ์•Š๋Š” 6๊ฐœ์˜ ์ˆซ์ž๋ฅผ ๋ฝ‘๋Š”๋‹ค. +- ๋‹น์ฒจ ๋ฒˆํ˜ธ ์ถ”์ฒจ ์‹œ ์ค‘๋ณต๋˜์ง€ ์•Š๋Š” ์ˆซ์ž 6๊ฐœ์™€ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ 1๊ฐœ๋ฅผ ๋ฝ‘๋Š”๋‹ค. +- ๋‹น์ฒจ์€ 1๋“ฑ๋ถ€ํ„ฐ 5๋“ฑ๊นŒ์ง€ ์žˆ๋‹ค. ๋‹น์ฒจ ๊ธฐ์ค€๊ณผ ๊ธˆ์•ก์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค. + - 1๋“ฑ: 6๊ฐœ ๋ฒˆํ˜ธ ์ผ์น˜ / 2,000,000,000์› + - 2๋“ฑ: 5๊ฐœ ๋ฒˆํ˜ธ + ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ ์ผ์น˜ / 30,000,000์› + - 3๋“ฑ: 5๊ฐœ ๋ฒˆํ˜ธ ์ผ์น˜ / 1,500,000์› + - 4๋“ฑ: 4๊ฐœ ๋ฒˆํ˜ธ ์ผ์น˜ / 50,000์› + - 5๋“ฑ: 3๊ฐœ ๋ฒˆํ˜ธ ์ผ์น˜ / 5,000์› +``` + +- ๋กœ๋˜ ๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅํ•˜๋ฉด ๊ตฌ์ž… ๊ธˆ์•ก์— ํ•ด๋‹นํ•˜๋Š” ๋งŒํผ ๋กœ๋˜๋ฅผ ๋ฐœํ–‰ํ•ด์•ผ ํ•œ๋‹ค. +- ๋กœ๋˜ 1์žฅ์˜ ๊ฐ€๊ฒฉ์€ 1,000์›์ด๋‹ค. +- ๋‹น์ฒจ ๋ฒˆํ˜ธ์™€ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. +- ์‚ฌ์šฉ์ž๊ฐ€ ๊ตฌ๋งคํ•œ ๋กœ๋˜ ๋ฒˆํ˜ธ์™€ ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ๋น„๊ตํ•˜์—ฌ ๋‹น์ฒจ ๋‚ด์—ญ ๋ฐ ์ˆ˜์ต๋ฅ ์„ ์ถœ๋ ฅํ•˜๊ณ  ๋กœ๋˜ ๊ฒŒ์ž„์„ ์ข…๋ฃŒํ•œ๋‹ค. +- ์‚ฌ์šฉ์ž๊ฐ€ ์ž˜๋ชป๋œ ๊ฐ’์„ ์ž…๋ ฅํ•  ๊ฒฝ์šฐ `IllegalArgumentException`๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๊ณ , "[ERROR]"๋กœ ์‹œ์ž‘ํ•˜๋Š” ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅ ํ›„ ๊ทธ ๋ถ€๋ถ„๋ถ€ํ„ฐ ์ž…๋ ฅ์„ ๋‹ค์‹œ ๋ฐ›๋Š”๋‹ค. + - `Exception`์ด ์•„๋‹Œ `IllegalArgumentException`, `IllegalStateException` ๋“ฑ๊ณผ ๊ฐ™์€ ๋ช…ํ™•ํ•œ ์œ ํ˜•์„ ์ฒ˜๋ฆฌํ•œ๋‹ค. + +- `Exception`์ด ์•„๋‹Œ `IllegalArgumentException`, `IllegalStateException` ๋“ฑ๊ณผ ๊ฐ™์€ ๋ช…ํ™•ํ•œ ์œ ํ˜•์„ ์ฒ˜๋ฆฌํ•œ๋‹ค. + +### ์ž…์ถœ๋ ฅ ์š”๊ตฌ ์‚ฌํ•ญ + +### ์ž…๋ ฅ + +- ๋กœ๋˜ ๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅ ๋ฐ›๋Š”๋‹ค. ๊ตฌ์ž… ๊ธˆ์•ก์€ 1,000์› ๋‹จ์œ„๋กœ ์ž…๋ ฅ ๋ฐ›์œผ๋ฉฐ 1,000์›์œผ๋กœ ๋‚˜๋ˆ„์–ด ๋–จ์–ด์ง€์ง€ ์•Š๋Š” ๊ฒฝ์šฐ ์˜ˆ์™ธ ์ฒ˜๋ฆฌํ•œ๋‹ค. + +``` +14000 +``` + +- ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅ ๋ฐ›๋Š”๋‹ค. ๋ฒˆํ˜ธ๋Š” ์‰ผํ‘œ(,)๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๊ตฌ๋ถ„ํ•œ๋‹ค. + +``` +1,2,3,4,5,6 +``` + +- ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅ ๋ฐ›๋Š”๋‹ค. + +``` +7 +``` + +### ์ถœ๋ ฅ +๋ฐœํ–‰ํ•œ ๋กœ๋˜ ์ˆ˜๋Ÿ‰ ๋ฐ ๋ฒˆํ˜ธ๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค. ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•˜์—ฌ ๋ณด์—ฌ์ค€๋‹ค. +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๊ฐœ +โ€‹ +์ˆ˜์ต๋ฅ ์€ ์†Œ์ˆ˜์  ๋‘˜์งธ ์ž๋ฆฌ์—์„œ ๋ฐ˜์˜ฌ๋ฆผํ•œ๋‹ค. (ex. 100.0%, 51.5%, 1,000,000.0%) +์ด ์ˆ˜์ต๋ฅ ์€ 62.5%์ž…๋‹ˆ๋‹ค. +โ€‹ +์˜ˆ์™ธ ์ƒํ™ฉ ์‹œ ์—๋Ÿฌ ๋ฌธ๊ตฌ๋ฅผ ์ถœ๋ ฅํ•ด์•ผ ํ•œ๋‹ค. ๋‹จ, ์—๋Ÿฌ ๋ฌธ๊ตฌ๋Š” "[ERROR]"๋กœ ์‹œ์ž‘ํ•ด์•ผ ํ•œ๋‹ค. +[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 1๋ถ€ํ„ฐ 45 ์‚ฌ์ด์˜ ์ˆซ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค. + +์‹คํ–‰ ๊ฒฐ๊ณผ ์˜ˆ์‹œ +``` +๊ตฌ์ž…๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”. +8000 + +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] + +๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”. +1,2,3,4,5,6 + +๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”. +7 + +๋‹น์ฒจ ํ†ต๊ณ„ +--- +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%์ž…๋‹ˆ๋‹ค. +``` + + +## ๐ŸŽฏ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ +- indent(์ธ๋ดํŠธ, ๋“ค์—ฌ์“ฐ๊ธฐ) depth๋ฅผ 3์ด ๋„˜์ง€ ์•Š๋„๋ก ๊ตฌํ˜„ํ•œ๋‹ค. 2๊นŒ์ง€๋งŒ ํ—ˆ์šฉํ•œ๋‹ค. + - ์˜ˆ๋ฅผ ๋“ค์–ด while๋ฌธ ์•ˆ์— if๋ฌธ์ด ์žˆ์œผ๋ฉด ๋“ค์—ฌ์“ฐ๊ธฐ๋Š” 2์ด๋‹ค. + - ํžŒํŠธ: indent(์ธ๋ดํŠธ, ๋“ค์—ฌ์“ฐ๊ธฐ) depth๋ฅผ ์ค„์ด๋Š” ์ข‹์€ ๋ฐฉ๋ฒ•์€ ํ•จ์ˆ˜(๋˜๋Š” ๋ฉ”์„œ๋“œ)๋ฅผ ๋ถ„๋ฆฌํ•˜๋ฉด ๋œ๋‹ค. +- 3ํ•ญ ์—ฐ์‚ฐ์ž๋ฅผ ์“ฐ์ง€ ์•Š๋Š”๋‹ค. +- ํ•จ์ˆ˜(๋˜๋Š” ๋ฉ”์„œ๋“œ)๊ฐ€ ํ•œ ๊ฐ€์ง€ ์ผ๋งŒ ํ•˜๋„๋ก ์ตœ๋Œ€ํ•œ ์ž‘๊ฒŒ ๋งŒ๋“ค์–ด๋ผ. +- JUnit 5์™€ AssertJ๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ณธ์ธ์ด ์ •๋ฆฌํ•œ ๊ธฐ๋Šฅ ๋ชฉ๋ก์ด ์ •์ƒ ๋™์ž‘ํ•จ์„ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋กœ ํ™•์ธํ•œ๋‹ค. + +### ์ถ”๊ฐ€๋œ ์š”๊ตฌ ์‚ฌํ•ญ + +- ํ•จ์ˆ˜(๋˜๋Š” ๋ฉ”์„œ๋“œ)์˜ ๊ธธ์ด๊ฐ€ 15๋ผ์ธ์„ ๋„˜์–ด๊ฐ€์ง€ ์•Š๋„๋ก ๊ตฌํ˜„ํ•œ๋‹ค. + - ํ•จ์ˆ˜(๋˜๋Š” ๋ฉ”์„œ๋“œ)๊ฐ€ ํ•œ ๊ฐ€์ง€ ์ผ๋งŒ ์ž˜ ํ•˜๋„๋ก ๊ตฌํ˜„ํ•œ๋‹ค. +- else ์˜ˆ์•ฝ์–ด๋ฅผ ์“ฐ์ง€ ์•Š๋Š”๋‹ค. + - ํžŒํŠธ: if ์กฐ๊ฑด์ ˆ์—์„œ ๊ฐ’์„ returnํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ•˜๋ฉด else๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค. + - else๋ฅผ ์“ฐ์ง€ ๋ง๋ผ๊ณ  ํ•˜๋‹ˆ switch/case๋กœ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋Š”๋ฐ switch/case๋„ ํ—ˆ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค. +- Java Enum์„ ์ ์šฉํ•œ๋‹ค. +- ๋„๋ฉ”์ธ ๋กœ์ง์— ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋ฅผ ๊ตฌํ˜„ํ•ด์•ผ ํ•œ๋‹ค. ๋‹จ, UI(System.out, [System.in](http://system.in/), Scanner) ๋กœ์ง์€ ์ œ์™ธํ•œ๋‹ค. + - ํ•ต์‹ฌ ๋กœ์ง์„ ๊ตฌํ˜„ํ•˜๋Š” ์ฝ”๋“œ์™€ UI๋ฅผ ๋‹ด๋‹นํ•˜๋Š” ๋กœ์ง์„ ๋ถ„๋ฆฌํ•ด ๊ตฌํ˜„ํ•œ๋‹ค. + - ๋‹จ์œ„ ํ…Œ์ŠคํŠธ ์ž‘์„ฑ์ด ์ต์ˆ™ํ•˜์ง€ ์•Š๋‹ค๋ฉด `test/java/lotto/LottoTest`๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ํ•™์Šตํ•œ ํ›„ ํ…Œ์ŠคํŠธ๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค. + +### ๊ตฌํ˜„ํ•  ๊ธฐ๋Šฅ +- ๊ตฌ์ž… ๊ธˆ์•ก ์ž…๋ ฅ +- ๋ฒˆํ˜ธ 6๊ฐœ์™€ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ ์ž…๋ ฅ +- ๋ฒˆํ˜ธ ์ผ์น˜ํ•˜๋Š”์ง€ ํŒ๋‹จ +- ๋ช‡๋“ฑ์ธ์ง€ ํŒ๋‹จ +- ๋‹น์ฒจ ๋‚ด์—ญ ๋ฐ ์ˆ˜์ต๋ฅ ์„ ์ถœ๋ ฅ + +### ๋น„์ง€๋‹ˆ์Šค ๋กœ์ง +- ๋กœ๋˜ ๊ตฌ์ž…ํ•ด์„œ ๋ฒˆํ˜ธ ์ž…๋ ฅํ•˜๊ธฐ +- ๋ฒˆํ˜ธ ๋งž์ถฐ๋ณด๊ธฐ +- ๋“ฑ์ˆ˜ ํŒ๋‹จํ•˜๊ธฐ +- ๊ฒฐ๊ณผ ์ถœ๋ ฅํ•˜๊ธฐ \ No newline at end of file diff --git a/src/main/java/lotto/controller/LottoController.java b/src/main/java/lotto/controller/LottoController.java new file mode 100644 index 0000000..92ab476 --- /dev/null +++ b/src/main/java/lotto/controller/LottoController.java @@ -0,0 +1,4 @@ +package lotto.controller; + +public class LottoController { +} diff --git a/src/main/java/lotto/model/Lottery.java b/src/main/java/lotto/model/Lottery.java new file mode 100644 index 0000000..25f4b54 --- /dev/null +++ b/src/main/java/lotto/model/Lottery.java @@ -0,0 +1,5 @@ +package lotto.model; + +public class Lottery { + +} diff --git a/src/main/java/lotto/view/UserInput.java b/src/main/java/lotto/view/UserInput.java new file mode 100644 index 0000000..03e390e --- /dev/null +++ b/src/main/java/lotto/view/UserInput.java @@ -0,0 +1,4 @@ +package lotto.view; + +public class UserInput { +} diff --git a/src/main/java/lotto/view/UserOutput.java b/src/main/java/lotto/view/UserOutput.java new file mode 100644 index 0000000..e62ed22 --- /dev/null +++ b/src/main/java/lotto/view/UserOutput.java @@ -0,0 +1,4 @@ +package lotto.view; + +public class UserOutput { +} From 5536ea2af2604c50a3170915985a6e3353b0f705 Mon Sep 17 00:00:00 2001 From: Siul Date: Fri, 21 Feb 2025 23:24:09 +0900 Subject: [PATCH 2/7] =?UTF-8?q?validator=20=EC=A0=9C=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 ++ src/main/java/lotto/AppConfig.java | 7 ++++ src/main/java/lotto/Lotto.java | 20 ------------ .../lotto/controller/LottoController.java | 9 ++++++ src/main/java/lotto/model/Lottery.java | 5 --- src/main/java/lotto/model/Lotto.java | 18 +++++++++++ .../java/lotto/service/MakeRandomNumbers.java | 16 ++++++++++ src/main/java/lotto/util/validator.java | 32 +++++++++++++++++++ src/main/java/lotto/view/UserInput.java | 3 ++ src/test/java/lotto/LottoTest.java | 1 + 10 files changed, 88 insertions(+), 25 deletions(-) create mode 100644 src/main/java/lotto/AppConfig.java delete mode 100644 src/main/java/lotto/Lotto.java delete mode 100644 src/main/java/lotto/model/Lottery.java create mode 100644 src/main/java/lotto/model/Lotto.java create mode 100644 src/main/java/lotto/service/MakeRandomNumbers.java create mode 100644 src/main/java/lotto/util/validator.java diff --git a/README.md b/README.md index 6434a29..9c7640e 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,8 @@ ### ๋น„์ง€๋‹ˆ์Šค ๋กœ์ง - ๋กœ๋˜ ๊ตฌ์ž…ํ•ด์„œ ๋ฒˆํ˜ธ ์ž…๋ ฅํ•˜๊ธฐ +- ๋‹น์ฒจ ๋ฒˆํ˜ธ ์ž…๋ ฅํ•˜๊ธฐ +- ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ ์ž…๋ ฅํ•˜๊ธฐ - ๋ฒˆํ˜ธ ๋งž์ถฐ๋ณด๊ธฐ - ๋“ฑ์ˆ˜ ํŒ๋‹จํ•˜๊ธฐ - ๊ฒฐ๊ณผ ์ถœ๋ ฅํ•˜๊ธฐ \ No newline at end of file diff --git a/src/main/java/lotto/AppConfig.java b/src/main/java/lotto/AppConfig.java new file mode 100644 index 0000000..06e1ff8 --- /dev/null +++ b/src/main/java/lotto/AppConfig.java @@ -0,0 +1,7 @@ +package lotto; + + + +public class AppConfig { + +} diff --git a/src/main/java/lotto/Lotto.java b/src/main/java/lotto/Lotto.java deleted file mode 100644 index 88fc5cf..0000000 --- a/src/main/java/lotto/Lotto.java +++ /dev/null @@ -1,20 +0,0 @@ -package lotto; - -import java.util.List; - -public class Lotto { - private final List numbers; - - public Lotto(List numbers) { - validate(numbers); - this.numbers = numbers; - } - - private void validate(List numbers) { - if (numbers.size() != 6) { - throw new IllegalArgumentException("[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 6๊ฐœ์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."); - } - } - - // TODO: ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ -} diff --git a/src/main/java/lotto/controller/LottoController.java b/src/main/java/lotto/controller/LottoController.java index 92ab476..1638dd6 100644 --- a/src/main/java/lotto/controller/LottoController.java +++ b/src/main/java/lotto/controller/LottoController.java @@ -1,4 +1,13 @@ package lotto.controller; +import lotto.view.UserInput; +import lotto.view.UserOutput; + public class LottoController { + + UserInput userInput = new UserInput(); + UserOutput userOutput = new UserOutput(); + for (int i = 0; i < userInput) + + // } diff --git a/src/main/java/lotto/model/Lottery.java b/src/main/java/lotto/model/Lottery.java deleted file mode 100644 index 25f4b54..0000000 --- a/src/main/java/lotto/model/Lottery.java +++ /dev/null @@ -1,5 +0,0 @@ -package lotto.model; - -public class Lottery { - -} diff --git a/src/main/java/lotto/model/Lotto.java b/src/main/java/lotto/model/Lotto.java new file mode 100644 index 0000000..40668da --- /dev/null +++ b/src/main/java/lotto/model/Lotto.java @@ -0,0 +1,18 @@ +package lotto.model; + +import java.util.List; +import lotto.AppConfig; + +public class Lotto { + private final List numbers; + + public Lotto(List number) { + + AppConfig appConfig = new AppConfig(); + appConfig.validator(number); + this.numbers = number; + } + + + // TODO: ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ +} diff --git a/src/main/java/lotto/service/MakeRandomNumbers.java b/src/main/java/lotto/service/MakeRandomNumbers.java new file mode 100644 index 0000000..c32b107 --- /dev/null +++ b/src/main/java/lotto/service/MakeRandomNumbers.java @@ -0,0 +1,16 @@ +package lotto.service; + +import java.util.List; +import camp.nextstep.edu.missionutils.Randoms; + +public class MakeRandomNumbers { + private List numbers; + + public MakeRandomNumbers() { + numbers = Randoms.pickUniqueNumbersInRange(1, 45, 6); + } + + public List getNumbers() { + return numbers; + } +} diff --git a/src/main/java/lotto/util/validator.java b/src/main/java/lotto/util/validator.java new file mode 100644 index 0000000..3fa5c99 --- /dev/null +++ b/src/main/java/lotto/util/validator.java @@ -0,0 +1,32 @@ +package lotto.util; + +import camp.nextstep.edu.missionutils.Randoms; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class validator { + private void numberCountValidator(List numbers) { + if (numbers.size() != 6) { + throw new IllegalArgumentException("[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 6๊ฐœ์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."); + } + } + + private void numberLimitValidator(List numbers) { + numbers.forEach(number -> { + if (number > 45 || number < 1) { + throw new IllegalArgumentException("[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 1๋ถ€ํ„ฐ 45 ์‚ฌ์ด์˜ ์ˆซ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."); + } + }); + } + + private void numberDuplicateValidator(List numbers) { + Set seen = new HashSet<>(); + for (int number : numbers) { + if (!seen.add(number)) { // add()๊ฐ€ false๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋ฉด ์ค‘๋ณต๋œ ๊ฐ’ + throw new IllegalArgumentException("[ERROR] ์ค‘๋ณต๋œ ๊ฐ’์„ ์ž…๋ ฅ๋ฐ›์•˜์Šต๋‹ˆ๋‹ค!"); + } + } + } +} diff --git a/src/main/java/lotto/view/UserInput.java b/src/main/java/lotto/view/UserInput.java index 03e390e..f74c707 100644 --- a/src/main/java/lotto/view/UserInput.java +++ b/src/main/java/lotto/view/UserInput.java @@ -1,4 +1,7 @@ package lotto.view; public class UserInput { + + + } diff --git a/src/test/java/lotto/LottoTest.java b/src/test/java/lotto/LottoTest.java index 309f4e5..c8ca9d6 100644 --- a/src/test/java/lotto/LottoTest.java +++ b/src/test/java/lotto/LottoTest.java @@ -1,5 +1,6 @@ package lotto; +import lotto.model.Lotto; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; From dbf1682c8fef8658668ca91b75fb24a3f1e3aad3 Mon Sep 17 00:00:00 2001 From: Siul Date: Fri, 21 Feb 2025 23:59:58 +0900 Subject: [PATCH 3/7] =?UTF-8?q?=EC=95=84=EC=A7=81=20=EB=AF=B8=EC=99=84?= =?UTF-8?q?=EC=84=B1..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lotto/controller/LottoController.java | 3 +- src/main/java/lotto/model/Lotto.java | 3 -- .../java/lotto/service/CalculateMoney.java | 6 ++++ .../lotto/service/ChooseCorrectNumber.java | 4 +++ src/main/java/lotto/service/CountLotto.java | 8 +++++ .../java/lotto/service/MakeRandomNumbers.java | 18 ++++++++--- src/main/java/lotto/view/UserInput.java | 31 +++++++++++++++++++ src/main/java/lotto/view/UserOutput.java | 2 ++ 8 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 src/main/java/lotto/service/CalculateMoney.java create mode 100644 src/main/java/lotto/service/ChooseCorrectNumber.java create mode 100644 src/main/java/lotto/service/CountLotto.java diff --git a/src/main/java/lotto/controller/LottoController.java b/src/main/java/lotto/controller/LottoController.java index 1638dd6..470ea5d 100644 --- a/src/main/java/lotto/controller/LottoController.java +++ b/src/main/java/lotto/controller/LottoController.java @@ -7,7 +7,8 @@ public class LottoController { UserInput userInput = new UserInput(); UserOutput userOutput = new UserOutput(); - for (int i = 0; i < userInput) + + // } diff --git a/src/main/java/lotto/model/Lotto.java b/src/main/java/lotto/model/Lotto.java index 40668da..d0fe814 100644 --- a/src/main/java/lotto/model/Lotto.java +++ b/src/main/java/lotto/model/Lotto.java @@ -7,9 +7,6 @@ public class Lotto { private final List numbers; public Lotto(List number) { - - AppConfig appConfig = new AppConfig(); - appConfig.validator(number); this.numbers = number; } diff --git a/src/main/java/lotto/service/CalculateMoney.java b/src/main/java/lotto/service/CalculateMoney.java new file mode 100644 index 0000000..4fe27a6 --- /dev/null +++ b/src/main/java/lotto/service/CalculateMoney.java @@ -0,0 +1,6 @@ +package lotto.service; + +public class CalculateMoney { + + +} diff --git a/src/main/java/lotto/service/ChooseCorrectNumber.java b/src/main/java/lotto/service/ChooseCorrectNumber.java new file mode 100644 index 0000000..b8aa08e --- /dev/null +++ b/src/main/java/lotto/service/ChooseCorrectNumber.java @@ -0,0 +1,4 @@ +package lotto.service; + +public class ChooseCorrectNumber { +} diff --git a/src/main/java/lotto/service/CountLotto.java b/src/main/java/lotto/service/CountLotto.java new file mode 100644 index 0000000..8967aca --- /dev/null +++ b/src/main/java/lotto/service/CountLotto.java @@ -0,0 +1,8 @@ +package lotto.service; + +public class CountLotto { + + public int countLotto(int money) { + return money / 1000; + } +} diff --git a/src/main/java/lotto/service/MakeRandomNumbers.java b/src/main/java/lotto/service/MakeRandomNumbers.java index c32b107..2c07a62 100644 --- a/src/main/java/lotto/service/MakeRandomNumbers.java +++ b/src/main/java/lotto/service/MakeRandomNumbers.java @@ -1,16 +1,24 @@ package lotto.service; +import java.util.ArrayList; import java.util.List; import camp.nextstep.edu.missionutils.Randoms; +import lotto.service.CountLotto; + public class MakeRandomNumbers { - private List numbers; + private List> numbers; + private List number; + private int trial; + public List> makeRandomNumbers(int money) { + CountLotto t = new CountLotto(); + trial = t.countLotto(money); - public MakeRandomNumbers() { - numbers = Randoms.pickUniqueNumbersInRange(1, 45, 6); - } + for (int i = 0; i < trial; i++) { + number = Randoms.pickUniqueNumbersInRange(1, 45, 6); + numbers.add(number); + } - public List getNumbers() { return numbers; } } diff --git a/src/main/java/lotto/view/UserInput.java b/src/main/java/lotto/view/UserInput.java index f74c707..049b9c8 100644 --- a/src/main/java/lotto/view/UserInput.java +++ b/src/main/java/lotto/view/UserInput.java @@ -1,7 +1,38 @@ package lotto.view; +import camp.nextstep.edu.missionutils.Console; + +import java.util.List; + public class UserInput { + private String trial; + private int numbers; + + public String getTrial() { + return trial; + } + + public int getNumbers() { + return numbers; + } + + public void setTrial() { + try { + System.out.println("๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + trial = Console.readLine(); + } catch (Exception exception) { + throw new IllegalArgumentException("[Error] ์ž…์ถœ๋ ฅ ๊ณผ์ •์—์„œ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. "); + } + } + public void setNumbers() { + try { + System.out.println("๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + numbers = Integer.parseInt(Console.readLine()); + } catch (Exception exception) { + throw new IllegalArgumentException("[Error] ์ž…์ถœ๋ ฅ ๊ณผ์ •์—์„œ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. "); + } + } } diff --git a/src/main/java/lotto/view/UserOutput.java b/src/main/java/lotto/view/UserOutput.java index e62ed22..8729ee4 100644 --- a/src/main/java/lotto/view/UserOutput.java +++ b/src/main/java/lotto/view/UserOutput.java @@ -1,4 +1,6 @@ package lotto.view; public class UserOutput { + + } From 02be20ef5e618ca0525664bfc19cd3fb3b079b34 Mon Sep 17 00:00:00 2001 From: Siul Date: Sat, 22 Feb 2025 23:26:31 +0900 Subject: [PATCH 4/7] =?UTF-8?q?=EB=A1=9C=EB=98=90=20=EA=B5=AC=EC=9E=85=20?= =?UTF-8?q?=ED=9B=84=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/AppConfig.java | 18 ++++++++ src/main/java/lotto/Application.java | 8 ++++ .../lotto/controller/LottoController.java | 44 +++++++++++++++++-- src/main/java/lotto/model/Lotto.java | 3 +- .../lotto/service/ChooseCorrectNumber.java | 1 + src/main/java/lotto/service/CountLotto.java | 1 - .../java/lotto/service/MakeRandomNumbers.java | 19 ++++---- .../StringListToIntegerListConverter.java | 4 ++ .../util/{validator.java => Validator.java} | 4 +- src/main/java/lotto/view/UserInput.java | 36 ++++++++++++--- src/main/java/lotto/view/UserOutput.java | 11 +++++ 11 files changed, 122 insertions(+), 27 deletions(-) create mode 100644 src/main/java/lotto/service/StringListToIntegerListConverter.java rename src/main/java/lotto/util/{validator.java => Validator.java} (93%) diff --git a/src/main/java/lotto/AppConfig.java b/src/main/java/lotto/AppConfig.java index 06e1ff8..bd7f45c 100644 --- a/src/main/java/lotto/AppConfig.java +++ b/src/main/java/lotto/AppConfig.java @@ -1,7 +1,25 @@ package lotto; +import lotto.controller.LottoController; +import lotto.service.CountLotto; +import lotto.service.MakeRandomNumbers; +import lotto.view.UserInput; +import lotto.view.UserOutput; public class AppConfig { + public UserInput userInput(){ + return new UserInput(); + }; + public UserOutput userOutput(){ + return new UserOutput(); + } + + public LottoController lottoController(){ + return new LottoController( + userInput(), + userOutput() + ); + } } diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java index d190922..aefbd32 100644 --- a/src/main/java/lotto/Application.java +++ b/src/main/java/lotto/Application.java @@ -1,7 +1,15 @@ package lotto; +import lotto.controller.LottoController; + public class Application { + static AppConfig appConfig; + static LottoController lottoController; public static void main(String[] args) { // TODO: ํ”„๋กœ๊ทธ๋žจ ๊ตฌํ˜„ + appConfig = new AppConfig(); + lottoController = appConfig.lottoController(); + + lottoController.buyLotto(); } } diff --git a/src/main/java/lotto/controller/LottoController.java b/src/main/java/lotto/controller/LottoController.java index 470ea5d..95c7bf4 100644 --- a/src/main/java/lotto/controller/LottoController.java +++ b/src/main/java/lotto/controller/LottoController.java @@ -1,14 +1,52 @@ package lotto.controller; +import lotto.service.CountLotto; +import lotto.service.MakeRandomNumbers; import lotto.view.UserInput; import lotto.view.UserOutput; +import lotto.util.Validator; +import java.util.List; public class LottoController { + UserInput userInput; + UserOutput userOutput; + Validator validator; + + public LottoController(UserInput userInput, UserOutput userOutput) { + this.userInput = userInput; + this.userOutput = userOutput; + validator = new Validator(); + } + + public void lottoPlaying(){ + buyLotto(); + } + + public void buyLotto(){ + userInput.setTrial(); + MakeRandomNumbers lottoList = new MakeRandomNumbers(); + CountLotto countLotto = new CountLotto(); + + int numberOfLotto = countLotto.countLotto(userInput.getTrial()); + List> lottoNumbersContainer = lottoList.makeRandomNumbers(numberOfLotto); + + userOutput.printNumberOfLotto(numberOfLotto); + userOutput.printNumberOfLottoNumbers(lottoNumbersContainer); + } + + public void executeLotto(){ + userInput.setWinningNumbers(); + validator.numberCountValidator(userInput.getLottoNumbers()); + + } + + public void lottoController() { + + } + + - UserInput userInput = new UserInput(); - UserOutput userOutput = new UserOutput(); - // } diff --git a/src/main/java/lotto/model/Lotto.java b/src/main/java/lotto/model/Lotto.java index d0fe814..78b2c68 100644 --- a/src/main/java/lotto/model/Lotto.java +++ b/src/main/java/lotto/model/Lotto.java @@ -1,7 +1,7 @@ package lotto.model; import java.util.List; -import lotto.AppConfig; + public class Lotto { private final List numbers; @@ -11,5 +11,4 @@ public Lotto(List number) { } - // TODO: ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ } diff --git a/src/main/java/lotto/service/ChooseCorrectNumber.java b/src/main/java/lotto/service/ChooseCorrectNumber.java index b8aa08e..bd3afa2 100644 --- a/src/main/java/lotto/service/ChooseCorrectNumber.java +++ b/src/main/java/lotto/service/ChooseCorrectNumber.java @@ -1,4 +1,5 @@ package lotto.service; public class ChooseCorrectNumber { + } diff --git a/src/main/java/lotto/service/CountLotto.java b/src/main/java/lotto/service/CountLotto.java index 8967aca..25a20df 100644 --- a/src/main/java/lotto/service/CountLotto.java +++ b/src/main/java/lotto/service/CountLotto.java @@ -1,7 +1,6 @@ package lotto.service; public class CountLotto { - public int countLotto(int money) { return money / 1000; } diff --git a/src/main/java/lotto/service/MakeRandomNumbers.java b/src/main/java/lotto/service/MakeRandomNumbers.java index 2c07a62..f03ac19 100644 --- a/src/main/java/lotto/service/MakeRandomNumbers.java +++ b/src/main/java/lotto/service/MakeRandomNumbers.java @@ -3,22 +3,19 @@ import java.util.ArrayList; import java.util.List; import camp.nextstep.edu.missionutils.Randoms; -import lotto.service.CountLotto; public class MakeRandomNumbers { - private List> numbers; - private List number; - private int trial; - public List> makeRandomNumbers(int money) { - CountLotto t = new CountLotto(); - trial = t.countLotto(money); + private final List> lottoNumbersContainer = new ArrayList>(); - for (int i = 0; i < trial; i++) { - number = Randoms.pickUniqueNumbersInRange(1, 45, 6); - numbers.add(number); + public List> makeRandomNumbers(int numberOfTrials) { + + for (int i = 0; i < numberOfTrials; i++) { + List lottoNumbers = Randoms.pickUniqueNumbersInRange(1, 45, 6); + lottoNumbersContainer.add(lottoNumbers); } - return numbers; + return lottoNumbersContainer; } + } diff --git a/src/main/java/lotto/service/StringListToIntegerListConverter.java b/src/main/java/lotto/service/StringListToIntegerListConverter.java new file mode 100644 index 0000000..6f85ca9 --- /dev/null +++ b/src/main/java/lotto/service/StringListToIntegerListConverter.java @@ -0,0 +1,4 @@ +package lotto.service; + +public class StringListToIntegerListConverter { +} diff --git a/src/main/java/lotto/util/validator.java b/src/main/java/lotto/util/Validator.java similarity index 93% rename from src/main/java/lotto/util/validator.java rename to src/main/java/lotto/util/Validator.java index 3fa5c99..9d44407 100644 --- a/src/main/java/lotto/util/validator.java +++ b/src/main/java/lotto/util/Validator.java @@ -1,12 +1,10 @@ package lotto.util; -import camp.nextstep.edu.missionutils.Randoms; - import java.util.HashSet; import java.util.List; import java.util.Set; -public class validator { +public class Validator { private void numberCountValidator(List numbers) { if (numbers.size() != 6) { throw new IllegalArgumentException("[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 6๊ฐœ์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."); diff --git a/src/main/java/lotto/view/UserInput.java b/src/main/java/lotto/view/UserInput.java index 049b9c8..7e217fd 100644 --- a/src/main/java/lotto/view/UserInput.java +++ b/src/main/java/lotto/view/UserInput.java @@ -2,19 +2,30 @@ import camp.nextstep.edu.missionutils.Console; +import java.util.ArrayList; import java.util.List; +import java.util.Arrays; public class UserInput { private String trial; - private int numbers; + private String numbers; + private String bonusNumber; + private List lottoNumbers; + + public UserInput() { + trial = ""; + numbers = ""; + bonusNumber = ""; + lottoNumbers = new ArrayList<>(); + } - public String getTrial() { - return trial; + public int getTrial() { + return Integer.parseInt(trial); } - public int getNumbers() { - return numbers; + public List getLottoNumbers() { + return lottoNumbers; } public void setTrial() { @@ -26,13 +37,24 @@ public void setTrial() { } } - public void setNumbers() { + public void setWinningNumbers() { try { System.out.println("๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); - numbers = Integer.parseInt(Console.readLine()); + numbers = Console.readLine(); + String [] numbersArray = numbers.split(","); + lottoNumbers = new ArrayList<>(Arrays.asList(numbersArray)); + } catch (Exception exception) { throw new IllegalArgumentException("[Error] ์ž…์ถœ๋ ฅ ๊ณผ์ •์—์„œ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. "); } } + public void bonusNumber(){ + try { + System.out.println("๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”"); + bonusNumber = Console.readLine(); + } catch (Exception exception) { + throw new IllegalArgumentException("[Error] ์ž…์ถœ๋ ฅ ๊ณผ์ •์—์„œ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. "); + } + } } diff --git a/src/main/java/lotto/view/UserOutput.java b/src/main/java/lotto/view/UserOutput.java index 8729ee4..85d9e35 100644 --- a/src/main/java/lotto/view/UserOutput.java +++ b/src/main/java/lotto/view/UserOutput.java @@ -1,6 +1,17 @@ package lotto.view; +import java.util.List; + public class UserOutput { + public void printNumberOfLotto(int numberOfLotto){ + System.out.println(numberOfLotto + "๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค."); + } + + public void printNumberOfLottoNumbers(List> lottoList){ + for (List integers : lottoList) { + System.out.println(integers.toString()); + } + } } From 6a7d76fd280e465acc428585ce1faec765e454d7 Mon Sep 17 00:00:00 2001 From: Siul Date: Sun, 23 Feb 2025 07:11:14 +0900 Subject: [PATCH 5/7] =?UTF-8?q?=EB=A1=9C=EB=98=90=20=EB=A7=9E=EC=B6=98=20?= =?UTF-8?q?=EB=B2=88=ED=98=B8=EC=9D=98=20=EA=B0=9C=EC=88=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/main/java/lotto/AppConfig.java | 24 +++++++++-- src/main/java/lotto/Application.java | 2 +- .../lotto/controller/LottoController.java | 40 ++++++++++++------- src/main/java/lotto/model/Lotto.java | 20 +++++++++- .../java/lotto/service/AdjustmentLotto.java | 30 ++++++++++++++ .../java/lotto/service/CalculateMoney.java | 6 --- .../lotto/service/ChooseCorrectNumber.java | 5 --- .../lotto/service/CountCorrectNumber.java | 34 ++++++++++++++++ src/main/java/lotto/service/CountLotto.java | 7 ---- .../java/lotto/service/FindSameNumber.java | 22 ++++++++++ src/main/java/lotto/service/LottoList.java | 26 ++++++++++++ .../java/lotto/service/MakeRandomNumbers.java | 21 ---------- .../StringListToIntegerListConverter.java | 4 -- src/main/java/lotto/util/Enum.java | 33 +++++++++++++++ src/main/java/lotto/util/Validator.java | 27 +++++++++---- src/main/java/lotto/view/UserInput.java | 39 +++++++++--------- src/main/java/lotto/view/UserOutput.java | 16 ++++++-- 18 files changed, 260 insertions(+), 98 deletions(-) create mode 100644 src/main/java/lotto/service/AdjustmentLotto.java delete mode 100644 src/main/java/lotto/service/CalculateMoney.java delete mode 100644 src/main/java/lotto/service/ChooseCorrectNumber.java create mode 100644 src/main/java/lotto/service/CountCorrectNumber.java delete mode 100644 src/main/java/lotto/service/CountLotto.java create mode 100644 src/main/java/lotto/service/FindSameNumber.java create mode 100644 src/main/java/lotto/service/LottoList.java delete mode 100644 src/main/java/lotto/service/MakeRandomNumbers.java delete mode 100644 src/main/java/lotto/service/StringListToIntegerListConverter.java create mode 100644 src/main/java/lotto/util/Enum.java diff --git a/README.md b/README.md index 9c7640e..c031812 100644 --- a/README.md +++ b/README.md @@ -120,7 +120,7 @@ - Java Enum์„ ์ ์šฉํ•œ๋‹ค. - ๋„๋ฉ”์ธ ๋กœ์ง์— ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋ฅผ ๊ตฌํ˜„ํ•ด์•ผ ํ•œ๋‹ค. ๋‹จ, UI(System.out, [System.in](http://system.in/), Scanner) ๋กœ์ง์€ ์ œ์™ธํ•œ๋‹ค. - ํ•ต์‹ฌ ๋กœ์ง์„ ๊ตฌํ˜„ํ•˜๋Š” ์ฝ”๋“œ์™€ UI๋ฅผ ๋‹ด๋‹นํ•˜๋Š” ๋กœ์ง์„ ๋ถ„๋ฆฌํ•ด ๊ตฌํ˜„ํ•œ๋‹ค. - - ๋‹จ์œ„ ํ…Œ์ŠคํŠธ ์ž‘์„ฑ์ด ์ต์ˆ™ํ•˜์ง€ ์•Š๋‹ค๋ฉด `test/java/lotto/LottoTest`๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ํ•™์Šตํ•œ ํ›„ ํ…Œ์ŠคํŠธ๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค. + - ๋‹จ์œ„ ํ…Œ์ŠคํŠธ ์ž‘์„ฑ์ด ์ต์ˆ™ํ•˜์ง€ ์•Š๋‹ค๋ฉด `test/java/lottoList/LottoTest`๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ํ•™์Šตํ•œ ํ›„ ํ…Œ์ŠคํŠธ๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค. ### ๊ตฌํ˜„ํ•  ๊ธฐ๋Šฅ - ๊ตฌ์ž… ๊ธˆ์•ก ์ž…๋ ฅ diff --git a/src/main/java/lotto/AppConfig.java b/src/main/java/lotto/AppConfig.java index bd7f45c..eab03f5 100644 --- a/src/main/java/lotto/AppConfig.java +++ b/src/main/java/lotto/AppConfig.java @@ -2,8 +2,9 @@ import lotto.controller.LottoController; -import lotto.service.CountLotto; -import lotto.service.MakeRandomNumbers; +import lotto.service.CountCorrectNumber; +import lotto.service.LottoList; +import lotto.util.Validator; import lotto.view.UserInput; import lotto.view.UserOutput; @@ -16,10 +17,25 @@ public UserOutput userOutput(){ return new UserOutput(); } + public Validator validator(){ + return new Validator(); + } + + public LottoList makeRandomLotto(){ + return new LottoList(userInput().getNumberOfLotto()); + } + + public CountCorrectNumber chooseCorrectNumber(){ + return new CountCorrectNumber(makeRandomLotto().getLottoContainer()); + } + public LottoController lottoController(){ return new LottoController( userInput(), - userOutput() - ); + userOutput(), + validator(), + makeRandomLotto(), + chooseCorrectNumber() + ); } } diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java index aefbd32..80e3799 100644 --- a/src/main/java/lotto/Application.java +++ b/src/main/java/lotto/Application.java @@ -10,6 +10,6 @@ public static void main(String[] args) { appConfig = new AppConfig(); lottoController = appConfig.lottoController(); - lottoController.buyLotto(); + lottoController.lottoPlaying(); } } diff --git a/src/main/java/lotto/controller/LottoController.java b/src/main/java/lotto/controller/LottoController.java index 95c7bf4..2da5d5e 100644 --- a/src/main/java/lotto/controller/LottoController.java +++ b/src/main/java/lotto/controller/LottoController.java @@ -1,46 +1,55 @@ package lotto.controller; -import lotto.service.CountLotto; -import lotto.service.MakeRandomNumbers; +import lotto.model.Lotto; +import lotto.service.CountCorrectNumber; +import lotto.service.LottoList; import lotto.view.UserInput; import lotto.view.UserOutput; import lotto.util.Validator; -import java.util.List; public class LottoController { UserInput userInput; UserOutput userOutput; Validator validator; + LottoList lottoList; + CountCorrectNumber countCorrectNumber; - public LottoController(UserInput userInput, UserOutput userOutput) { + + public LottoController( + UserInput userInput, + UserOutput userOutput, + Validator validator, + LottoList lottoList, + CountCorrectNumber countCorrectNumber) { this.userInput = userInput; this.userOutput = userOutput; - validator = new Validator(); + this.validator = validator; + this.lottoList = lottoList; + this.countCorrectNumber = countCorrectNumber; } public void lottoPlaying(){ buyLotto(); + executeLotto(); } public void buyLotto(){ userInput.setTrial(); - MakeRandomNumbers lottoList = new MakeRandomNumbers(); - CountLotto countLotto = new CountLotto(); - - int numberOfLotto = countLotto.countLotto(userInput.getTrial()); - List> lottoNumbersContainer = lottoList.makeRandomNumbers(numberOfLotto); + lottoList = new LottoList(userInput.getNumberOfLotto()); - userOutput.printNumberOfLotto(numberOfLotto); - userOutput.printNumberOfLottoNumbers(lottoNumbersContainer); + userOutput.printNumberOfLotto(userInput.getNumberOfLotto()); + userOutput.printNumberOfLottoNumbers(lottoList.getLottoContainer()); } public void executeLotto(){ userInput.setWinningNumbers(); - validator.numberCountValidator(userInput.getLottoNumbers()); + Lotto winningLotto = new Lotto(userInput.getWinningLotto().getNumbers()); + validator.numberCountValidator(winningLotto.getNumbers()); - } + userInput.setBonusNumber(); + validator.numberDuplicateWithBonusNumberValidator(winningLotto, userInput.getBonusNumber()); - public void lottoController() { + countCorrectNumber.listCorrectNumber(lottoList.getLottoContainer(), winningLotto); } @@ -49,4 +58,5 @@ public void lottoController() { + } diff --git a/src/main/java/lotto/model/Lotto.java b/src/main/java/lotto/model/Lotto.java index 78b2c68..3410386 100644 --- a/src/main/java/lotto/model/Lotto.java +++ b/src/main/java/lotto/model/Lotto.java @@ -5,10 +5,26 @@ public class Lotto { private final List numbers; + private int correctNumbers; - public Lotto(List number) { - this.numbers = number; + public Lotto(List lotto) { + correctNumbers = 0; + numbers = lotto; } + public List getNumbers() { + return numbers; + } + + public int getCorrectNumbers() { + return correctNumbers; + } + public void setNumbers(int correctNumbers) { + this.correctNumbers = correctNumbers; + } + + public void plusCorrectNumbers() { + correctNumbers++; + } } diff --git a/src/main/java/lotto/service/AdjustmentLotto.java b/src/main/java/lotto/service/AdjustmentLotto.java new file mode 100644 index 0000000..99093ca --- /dev/null +++ b/src/main/java/lotto/service/AdjustmentLotto.java @@ -0,0 +1,30 @@ +package lotto.service; + +import lotto.model.Lotto; + +import java.util.List; + +import static lotto.service.FindSameNumber.sameNumber; + +public class AdjustmentLotto { + private int[] lotto = {0, 0, 0, 0, 0}; + + public void countCorrectNumber(List lotto, int bonus){ + for (Lotto l : lotto){ + countCorrectNumber(l, bonus); + } + } + + public void countCorrectNumber(Lotto winningLotto, int bonus) { + if (winningLotto.getCorrectNumbers() == 3) { lotto[0]++; } + if (winningLotto.getCorrectNumbers() == 4) { lotto[1]++; } + if (winningLotto.getCorrectNumbers() == 5) { + if (sameNumber(winningLotto, bonus)){ + lotto[3]++; + return; + } + lotto[4]++; + } + if (winningLotto.getCorrectNumbers() == 6) { lotto[4]++; } + } +} diff --git a/src/main/java/lotto/service/CalculateMoney.java b/src/main/java/lotto/service/CalculateMoney.java deleted file mode 100644 index 4fe27a6..0000000 --- a/src/main/java/lotto/service/CalculateMoney.java +++ /dev/null @@ -1,6 +0,0 @@ -package lotto.service; - -public class CalculateMoney { - - -} diff --git a/src/main/java/lotto/service/ChooseCorrectNumber.java b/src/main/java/lotto/service/ChooseCorrectNumber.java deleted file mode 100644 index bd3afa2..0000000 --- a/src/main/java/lotto/service/ChooseCorrectNumber.java +++ /dev/null @@ -1,5 +0,0 @@ -package lotto.service; - -public class ChooseCorrectNumber { - -} diff --git a/src/main/java/lotto/service/CountCorrectNumber.java b/src/main/java/lotto/service/CountCorrectNumber.java new file mode 100644 index 0000000..5734a66 --- /dev/null +++ b/src/main/java/lotto/service/CountCorrectNumber.java @@ -0,0 +1,34 @@ +package lotto.service; + +import lotto.model.Lotto; + +import java.util.List; + +public class CountCorrectNumber { + private List lottoList; + + public CountCorrectNumber(List lottoList) { + this.lottoList = lottoList; + } + + public void listCorrectNumber(List myLottos, Lotto winningLotto){ + for (Lotto myLotto : myLottos) { + chooseCorrectNumber(myLotto, winningLotto); + } + } + + public void chooseCorrectNumber(Lotto myLotto, Lotto winningLotto) { + for (int winningLottoNumber : winningLotto.getNumbers()) { + sameNumber(myLotto, winningLottoNumber); + } + } + + public void sameNumber(Lotto myLotto, int oneOfMyLottoNumber) { + for (int lotto : myLotto.getNumbers()) { + if (lotto == oneOfMyLottoNumber) { + myLotto.plusCorrectNumbers(); + break; + } + } + } +} diff --git a/src/main/java/lotto/service/CountLotto.java b/src/main/java/lotto/service/CountLotto.java deleted file mode 100644 index 25a20df..0000000 --- a/src/main/java/lotto/service/CountLotto.java +++ /dev/null @@ -1,7 +0,0 @@ -package lotto.service; - -public class CountLotto { - public int countLotto(int money) { - return money / 1000; - } -} diff --git a/src/main/java/lotto/service/FindSameNumber.java b/src/main/java/lotto/service/FindSameNumber.java new file mode 100644 index 0000000..ebad5bf --- /dev/null +++ b/src/main/java/lotto/service/FindSameNumber.java @@ -0,0 +1,22 @@ +package lotto.service; + +import lotto.model.Lotto; + +import java.awt.*; + +public class FindSameNumber { + private Lotto lotto; + + public FindSameNumber(Lotto lotto) { + this.lotto = lotto; + } + + public static boolean sameNumber(Lotto myLotto, int bonus) { + for (int lotto : myLotto.getNumbers()) { + if (lotto == bonus) { + return true; + } + } + return false; + } +} diff --git a/src/main/java/lotto/service/LottoList.java b/src/main/java/lotto/service/LottoList.java new file mode 100644 index 0000000..f74c8ee --- /dev/null +++ b/src/main/java/lotto/service/LottoList.java @@ -0,0 +1,26 @@ +package lotto.service; + +import java.util.ArrayList; +import java.util.List; +import camp.nextstep.edu.missionutils.Randoms; +import lotto.model.Lotto; +import lotto.util.Validator; + + +public class LottoList { + private List lottoContainer = new ArrayList<>(); + + public LottoList(int numberOfTrials) { + for (int i = 0; i < numberOfTrials; i++) { + List lottoNumbers = Randoms.pickUniqueNumbersInRange(1, 45, 6); + Validator validator = new Validator(); + validator.numberDuplicateValidator(lottoNumbers); + Lotto lotto = new Lotto(lottoNumbers); + lottoContainer.add(lotto); + } + } + + public List getLottoContainer() { + return lottoContainer; + } +} diff --git a/src/main/java/lotto/service/MakeRandomNumbers.java b/src/main/java/lotto/service/MakeRandomNumbers.java deleted file mode 100644 index f03ac19..0000000 --- a/src/main/java/lotto/service/MakeRandomNumbers.java +++ /dev/null @@ -1,21 +0,0 @@ -package lotto.service; - -import java.util.ArrayList; -import java.util.List; -import camp.nextstep.edu.missionutils.Randoms; - - -public class MakeRandomNumbers { - private final List> lottoNumbersContainer = new ArrayList>(); - - public List> makeRandomNumbers(int numberOfTrials) { - - for (int i = 0; i < numberOfTrials; i++) { - List lottoNumbers = Randoms.pickUniqueNumbersInRange(1, 45, 6); - lottoNumbersContainer.add(lottoNumbers); - } - - return lottoNumbersContainer; - } - -} diff --git a/src/main/java/lotto/service/StringListToIntegerListConverter.java b/src/main/java/lotto/service/StringListToIntegerListConverter.java deleted file mode 100644 index 6f85ca9..0000000 --- a/src/main/java/lotto/service/StringListToIntegerListConverter.java +++ /dev/null @@ -1,4 +0,0 @@ -package lotto.service; - -public class StringListToIntegerListConverter { -} diff --git a/src/main/java/lotto/util/Enum.java b/src/main/java/lotto/util/Enum.java new file mode 100644 index 0000000..a9ba7e7 --- /dev/null +++ b/src/main/java/lotto/util/Enum.java @@ -0,0 +1,33 @@ +package lotto.util; + +interface Displayable{ + void display(); +} + +enum MessageType implements Displayable { + THREE { + public void display(){ + System.out.println("3๊ฐœ ์ผ์น˜ (5000์›)"); + } + }, + FOUR { + public void display(){ + System.out.println("4๊ฐœ ์ผ์น˜ (50,000์›)"); + } + }, + FIVE { + public void display(){ + System.out.println("5๊ฐœ ์ผ์น˜ (1,500,000์›)"); + } + }, + FIVE_AND_ONE { + public void display(){ + System.out.println("5๊ฐœ ์ผ์น˜, ๋ณด๋„ˆ์Šค ๋ณผ ์ผ์น˜ (30,000,000์›)"); + } + }, + SIX { + public void display(){ + System.out.println("6๊ฐœ ์ผ์น˜ (2,000,000,000์›)"); + } + }, +} \ No newline at end of file diff --git a/src/main/java/lotto/util/Validator.java b/src/main/java/lotto/util/Validator.java index 9d44407..6eb845f 100644 --- a/src/main/java/lotto/util/Validator.java +++ b/src/main/java/lotto/util/Validator.java @@ -1,17 +1,17 @@ package lotto.util; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import lotto.model.Lotto; + +import java.util.*; public class Validator { - private void numberCountValidator(List numbers) { + public void numberCountValidator(List numbers) { if (numbers.size() != 6) { throw new IllegalArgumentException("[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 6๊ฐœ์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."); } } - private void numberLimitValidator(List numbers) { + public void numberLimitValidator(List numbers) { numbers.forEach(number -> { if (number > 45 || number < 1) { throw new IllegalArgumentException("[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 1๋ถ€ํ„ฐ 45 ์‚ฌ์ด์˜ ์ˆซ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."); @@ -19,10 +19,21 @@ private void numberLimitValidator(List numbers) { }); } - private void numberDuplicateValidator(List numbers) { + public void numberDuplicateValidator(List numbers) { + Set seen = new HashSet<>(); + for (Integer number : numbers) { + if (!seen.add(number)) { + throw new IllegalArgumentException("[ERROR] ์ค‘๋ณต๋œ ๊ฐ’์„ ์ž…๋ ฅ๋ฐ›์•˜์Šต๋‹ˆ๋‹ค!"); + } + } + } + public void numberDuplicateWithBonusNumberValidator(Lotto winningLotto, String bonusNumber) { Set seen = new HashSet<>(); - for (int number : numbers) { - if (!seen.add(number)) { // add()๊ฐ€ false๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋ฉด ์ค‘๋ณต๋œ ๊ฐ’ + for (int i = 0; i < winningLotto.getNumbers().size() + 1; i++) { + if (!seen.add(winningLotto.getNumbers().get(i))) { + throw new IllegalArgumentException("[ERROR] ์ค‘๋ณต๋œ ๊ฐ’์„ ์ž…๋ ฅ๋ฐ›์•˜์Šต๋‹ˆ๋‹ค!"); + } + if (!seen.add(Integer.parseInt(bonusNumber))) { throw new IllegalArgumentException("[ERROR] ์ค‘๋ณต๋œ ๊ฐ’์„ ์ž…๋ ฅ๋ฐ›์•˜์Šต๋‹ˆ๋‹ค!"); } } diff --git a/src/main/java/lotto/view/UserInput.java b/src/main/java/lotto/view/UserInput.java index 7e217fd..1d5859e 100644 --- a/src/main/java/lotto/view/UserInput.java +++ b/src/main/java/lotto/view/UserInput.java @@ -1,37 +1,33 @@ package lotto.view; import camp.nextstep.edu.missionutils.Console; +import lotto.model.Lotto; import java.util.ArrayList; -import java.util.List; -import java.util.Arrays; public class UserInput { - private String trial; - private String numbers; + private String budget; + private Lotto winningLotto; private String bonusNumber; - private List lottoNumbers; + public UserInput() { - trial = ""; - numbers = ""; + budget = ""; bonusNumber = ""; - lottoNumbers = new ArrayList<>(); } - public int getTrial() { - return Integer.parseInt(trial); + public int getNumberOfLotto() { + return Integer.parseInt(budget)/1000; } - public List getLottoNumbers() { - return lottoNumbers; - } + public Lotto getWinningLotto() { return winningLotto; } + public String getBonusNumber() { return bonusNumber; } public void setTrial() { try { System.out.println("๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); - trial = Console.readLine(); + budget = Console.readLine(); } catch (Exception exception) { throw new IllegalArgumentException("[Error] ์ž…์ถœ๋ ฅ ๊ณผ์ •์—์„œ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. "); } @@ -40,16 +36,19 @@ public void setTrial() { public void setWinningNumbers() { try { System.out.println("๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); - numbers = Console.readLine(); - String [] numbersArray = numbers.split(","); - lottoNumbers = new ArrayList<>(Arrays.asList(numbersArray)); - - } catch (Exception exception) { + ArrayList numbers = new ArrayList<>(); + String winningNums = Console.readLine(); + for (String num : winningNums.split(",")) { + numbers.add(Integer.parseInt(num.trim())); + } + + winningLotto = new Lotto(numbers); + } catch (Exception exception) { throw new IllegalArgumentException("[Error] ์ž…์ถœ๋ ฅ ๊ณผ์ •์—์„œ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. "); } } - public void bonusNumber(){ + public void setBonusNumber(){ try { System.out.println("๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”"); bonusNumber = Console.readLine(); diff --git a/src/main/java/lotto/view/UserOutput.java b/src/main/java/lotto/view/UserOutput.java index 85d9e35..01aac48 100644 --- a/src/main/java/lotto/view/UserOutput.java +++ b/src/main/java/lotto/view/UserOutput.java @@ -1,17 +1,25 @@ package lotto.view; +import lotto.model.Lotto; +import lotto.service.AdjustmentLotto; + +import java.awt.*; import java.util.List; + + public class UserOutput { public void printNumberOfLotto(int numberOfLotto){ System.out.println(numberOfLotto + "๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค."); } - public void printNumberOfLottoNumbers(List> lottoList){ - for (List integers : lottoList) { - System.out.println(integers.toString()); + public void printNumberOfLottoNumbers(List lottoList) { + for (Lotto lotto : lottoList) { + System.out.println(lotto.getNumbers()); } } - + public void printNumberOfWinningNumbers(Lotto winningLotto, int bonus) { + AdjustmentLotto adjustmentLotto = new AdjustmentLotto(); + } } From 4e336886e5f03450582170d1bd55a72efba94d1a Mon Sep 17 00:00:00 2001 From: Siul Date: Sun, 23 Feb 2025 21:00:10 +0900 Subject: [PATCH 6/7] =?UTF-8?q?enum=EC=9D=84=20=EC=9D=B4=EC=9A=A9=ED=95=9C?= =?UTF-8?q?=20=EB=AC=B8=EC=9E=90=EC=97=B4=20=EC=B6=9C=EB=A0=A5,=20?= =?UTF-8?q?=EB=8B=B9=EC=B2=A8=EB=90=9C=20=EB=A1=9C=EB=98=90=20=EA=B3=84?= =?UTF-8?q?=EC=82=B0=20=ED=9B=84=20=EC=88=98=EC=9D=B5=EB=A5=A0=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=20-=EC=88=98=EC=A0=95=20=EA=B1=B0=EC=B3=90=EC=95=BC?= =?UTF-8?q?=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/AppConfig.java | 13 ++++++- .../lotto/controller/LottoController.java | 21 +++++++++-- .../java/lotto/service/AdjustmentLotto.java | 29 ++++++++++++--- .../lotto/service/CalculateTotalBenefit.java | 34 ++++++++++++++++++ .../lotto/service/CountCorrectNumber.java | 2 ++ src/main/java/lotto/util/Enum.java | 33 ----------------- .../java/lotto/util/MessageConstants.java | 35 +++++++++++++++++++ src/main/java/lotto/util/Validator.java | 18 +++++----- src/main/java/lotto/view/UserInput.java | 31 ++++++++-------- src/main/java/lotto/view/UserOutput.java | 10 ++---- 10 files changed, 153 insertions(+), 73 deletions(-) create mode 100644 src/main/java/lotto/service/CalculateTotalBenefit.java delete mode 100644 src/main/java/lotto/util/Enum.java create mode 100644 src/main/java/lotto/util/MessageConstants.java diff --git a/src/main/java/lotto/AppConfig.java b/src/main/java/lotto/AppConfig.java index eab03f5..9918b0d 100644 --- a/src/main/java/lotto/AppConfig.java +++ b/src/main/java/lotto/AppConfig.java @@ -2,6 +2,8 @@ import lotto.controller.LottoController; +import lotto.service.AdjustmentLotto; +import lotto.service.CalculateTotalBenefit; import lotto.service.CountCorrectNumber; import lotto.service.LottoList; import lotto.util.Validator; @@ -29,13 +31,22 @@ public CountCorrectNumber chooseCorrectNumber(){ return new CountCorrectNumber(makeRandomLotto().getLottoContainer()); } + public AdjustmentLotto adjustmentLotto(){ + return new AdjustmentLotto(makeRandomLotto().getLottoContainer(), userInput().getBonusNumber()); + } + + public CalculateTotalBenefit calculateTotalBenefit(){ + return new CalculateTotalBenefit(adjustmentLotto().getLotto(), userInput().getBonusNumber()); + } public LottoController lottoController(){ return new LottoController( userInput(), userOutput(), validator(), makeRandomLotto(), - chooseCorrectNumber() + chooseCorrectNumber(), + adjustmentLotto(), + calculateTotalBenefit() ); } } diff --git a/src/main/java/lotto/controller/LottoController.java b/src/main/java/lotto/controller/LottoController.java index 2da5d5e..d29b7d9 100644 --- a/src/main/java/lotto/controller/LottoController.java +++ b/src/main/java/lotto/controller/LottoController.java @@ -1,6 +1,8 @@ package lotto.controller; import lotto.model.Lotto; +import lotto.service.AdjustmentLotto; +import lotto.service.CalculateTotalBenefit; import lotto.service.CountCorrectNumber; import lotto.service.LottoList; import lotto.view.UserInput; @@ -13,28 +15,34 @@ public class LottoController { Validator validator; LottoList lottoList; CountCorrectNumber countCorrectNumber; - + AdjustmentLotto adjustmentLotto; + CalculateTotalBenefit calculateTotalBenefit; public LottoController( UserInput userInput, UserOutput userOutput, Validator validator, LottoList lottoList, - CountCorrectNumber countCorrectNumber) { + CountCorrectNumber countCorrectNumber, + AdjustmentLotto adjustmentLotto, + CalculateTotalBenefit calculateTotalBenefit) { this.userInput = userInput; this.userOutput = userOutput; this.validator = validator; this.lottoList = lottoList; this.countCorrectNumber = countCorrectNumber; + this.adjustmentLotto = adjustmentLotto; + this.calculateTotalBenefit = calculateTotalBenefit; } public void lottoPlaying(){ buyLotto(); executeLotto(); + winningPriceLotto(); } public void buyLotto(){ - userInput.setTrial(); + userInput.setBudget(); lottoList = new LottoList(userInput.getNumberOfLotto()); userOutput.printNumberOfLotto(userInput.getNumberOfLotto()); @@ -53,6 +61,13 @@ public void executeLotto(){ } + public void winningPriceLotto(){ + adjustmentLotto.countCorrectNumber(); + adjustmentLotto.printLotto(); + + calculateTotalBenefit.calculateTotalBenefit(); + } + diff --git a/src/main/java/lotto/service/AdjustmentLotto.java b/src/main/java/lotto/service/AdjustmentLotto.java index 99093ca..bb38a6f 100644 --- a/src/main/java/lotto/service/AdjustmentLotto.java +++ b/src/main/java/lotto/service/AdjustmentLotto.java @@ -1,21 +1,42 @@ package lotto.service; import lotto.model.Lotto; +import lotto.util.MessageConstants; +import java.util.ArrayList; import java.util.List; import static lotto.service.FindSameNumber.sameNumber; public class AdjustmentLotto { private int[] lotto = {0, 0, 0, 0, 0}; + private List lottoList = new ArrayList(); + private int bonus; - public void countCorrectNumber(List lotto, int bonus){ - for (Lotto l : lotto){ - countCorrectNumber(l, bonus); + public AdjustmentLotto(List lottoList, int bonus) { + this.lottoList = lottoList; + this.bonus = bonus; + } + + public int[] getLotto() { + return lotto; + } + + public void printLotto() { + System.out.println(MessageConstants.THREE_MESSAGE.getMessage() + lotto[0] + "๊ฐœ"); + System.out.println(MessageConstants.FOUR_MESSAGE.getMessage() + lotto[1] + "๊ฐœ"); + System.out.println(MessageConstants.FIVE_MESSAGE.getMessage() + lotto[2] + "๊ฐœ"); + System.out.println(MessageConstants.FIVE_AND_BONUS_MASSAGE.getMessage() + lotto[3] + "๊ฐœ"); + System.out.println(MessageConstants.SIX_MASSAGE.getMessage() + lotto[4] + "๊ฐœ"); + } + + public void countCorrectNumber(){ + for (Lotto l : lottoList){ + countCorrectNumber(l); } } - public void countCorrectNumber(Lotto winningLotto, int bonus) { + public void countCorrectNumber(Lotto winningLotto) { if (winningLotto.getCorrectNumbers() == 3) { lotto[0]++; } if (winningLotto.getCorrectNumbers() == 4) { lotto[1]++; } if (winningLotto.getCorrectNumbers() == 5) { diff --git a/src/main/java/lotto/service/CalculateTotalBenefit.java b/src/main/java/lotto/service/CalculateTotalBenefit.java new file mode 100644 index 0000000..d16e38a --- /dev/null +++ b/src/main/java/lotto/service/CalculateTotalBenefit.java @@ -0,0 +1,34 @@ +package lotto.service; + +import lotto.util.MessageConstants; + +public class CalculateTotalBenefit { + private int[] lotto; + private int budget; + private double totalBenefit = 0; + public CalculateTotalBenefit(int[] lotto, int budget) { + this.lotto = lotto; + this.budget = budget; + } + + public double sumLotto(){ + lotto[0] *= 5000; + lotto[1] *= 50000; + lotto[2] *= 1500000; + lotto[3] *= 30000000; + lotto[4] *= 2000000000; + for (int i = 0; i < lotto.length; i++) { + totalBenefit += (double)lotto[i]; + } + return totalBenefit; + } + + public void calculateTotalBenefit() { + if (totalBenefit != 0) { + totalBenefit /= (double)budget; + System.out.println(MessageConstants.TOTAL_BENEFIT.getMessage(totalBenefit)); + return; + } + System.out.println(MessageConstants.TOTAL_BENEFIT.getMessage(0)); + } +} diff --git a/src/main/java/lotto/service/CountCorrectNumber.java b/src/main/java/lotto/service/CountCorrectNumber.java index 5734a66..fb1e12e 100644 --- a/src/main/java/lotto/service/CountCorrectNumber.java +++ b/src/main/java/lotto/service/CountCorrectNumber.java @@ -7,6 +7,8 @@ public class CountCorrectNumber { private List lottoList; + + public CountCorrectNumber(List lottoList) { this.lottoList = lottoList; } diff --git a/src/main/java/lotto/util/Enum.java b/src/main/java/lotto/util/Enum.java deleted file mode 100644 index a9ba7e7..0000000 --- a/src/main/java/lotto/util/Enum.java +++ /dev/null @@ -1,33 +0,0 @@ -package lotto.util; - -interface Displayable{ - void display(); -} - -enum MessageType implements Displayable { - THREE { - public void display(){ - System.out.println("3๊ฐœ ์ผ์น˜ (5000์›)"); - } - }, - FOUR { - public void display(){ - System.out.println("4๊ฐœ ์ผ์น˜ (50,000์›)"); - } - }, - FIVE { - public void display(){ - System.out.println("5๊ฐœ ์ผ์น˜ (1,500,000์›)"); - } - }, - FIVE_AND_ONE { - public void display(){ - System.out.println("5๊ฐœ ์ผ์น˜, ๋ณด๋„ˆ์Šค ๋ณผ ์ผ์น˜ (30,000,000์›)"); - } - }, - SIX { - public void display(){ - System.out.println("6๊ฐœ ์ผ์น˜ (2,000,000,000์›)"); - } - }, -} \ No newline at end of file diff --git a/src/main/java/lotto/util/MessageConstants.java b/src/main/java/lotto/util/MessageConstants.java new file mode 100644 index 0000000..e764b2d --- /dev/null +++ b/src/main/java/lotto/util/MessageConstants.java @@ -0,0 +1,35 @@ +package lotto.util; + +public enum MessageConstants{ + THREE_MESSAGE("3๊ฐœ ์ผ์น˜ (5,000์›) - "), + FOUR_MESSAGE("4๊ฐœ ์ผ์น˜ (50,000์›) - "), + FIVE_MESSAGE("5๊ฐœ ์ผ์น˜ (1,500,000์›) - "), + FIVE_AND_BONUS_MASSAGE("5๊ฐœ ์ผ์น˜, ๋ณด๋„ˆ์Šค ๋ณผ ์ผ์น˜ (30,000,000์›) - "), + SIX_MASSAGE("6๊ฐœ ์ผ์น˜ (2,000,000,000์›) - "), + + PURCHASE_MESSAGE("๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค"), + REQUEST_WINNING_NUMBER("๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."), + REQUEST_BONUS_NUMBER("๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."), + REQUEST_PURCHASE_AMOUNT("๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."), + WINNING_STATISTICS("๋‹น์ฒจ ํ†ต๊ณ„\n---"), + TOTAL_BENEFIT("์ด ์ˆ˜์ต๋ฅ ์€ %.1f%%์ž…๋‹ˆ๋‹ค."), + + INOUTPUT_ERROR("[Error] ์ž…์ถœ๋ ฅ ๊ณผ์ •์—์„œ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค."), + NUMBER_COUNT_ERROR("[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 6๊ฐœ์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."), + NUMBER_LIMIT_ERROR("[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 1๋ถ€ํ„ฐ 45 ์‚ฌ์ด์˜ ์ˆซ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."), + NUMBER_DUPLICATE_ERROR("[ERROR] ์ค‘๋ณต๋œ ๊ฐ’์„ ์ž…๋ ฅ๋ฐ›์•˜์Šต๋‹ˆ๋‹ค!"), + NOT_NUMBER_ERROR("[ERROR] ์ˆซ์ž๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”."); + + + private String message; + MessageConstants(String message){ + this.message = message; + } + + public String getMessage(double totalBenefit){ + return String.format(message, totalBenefit); + } + public String getMessage(){ + return message; + } +} \ No newline at end of file diff --git a/src/main/java/lotto/util/Validator.java b/src/main/java/lotto/util/Validator.java index 6eb845f..b043c86 100644 --- a/src/main/java/lotto/util/Validator.java +++ b/src/main/java/lotto/util/Validator.java @@ -7,14 +7,14 @@ public class Validator { public void numberCountValidator(List numbers) { if (numbers.size() != 6) { - throw new IllegalArgumentException("[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 6๊ฐœ์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."); + throw new IllegalArgumentException(MessageConstants.NUMBER_COUNT_ERROR.getMessage()); } } public void numberLimitValidator(List numbers) { numbers.forEach(number -> { if (number > 45 || number < 1) { - throw new IllegalArgumentException("[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 1๋ถ€ํ„ฐ 45 ์‚ฌ์ด์˜ ์ˆซ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."); + throw new IllegalArgumentException(MessageConstants.NUMBER_LIMIT_ERROR.getMessage()); } }); } @@ -23,19 +23,19 @@ public void numberDuplicateValidator(List numbers) { Set seen = new HashSet<>(); for (Integer number : numbers) { if (!seen.add(number)) { - throw new IllegalArgumentException("[ERROR] ์ค‘๋ณต๋œ ๊ฐ’์„ ์ž…๋ ฅ๋ฐ›์•˜์Šต๋‹ˆ๋‹ค!"); + throw new IllegalArgumentException(MessageConstants.NUMBER_DUPLICATE_ERROR.getMessage()); } } } - public void numberDuplicateWithBonusNumberValidator(Lotto winningLotto, String bonusNumber) { + public void numberDuplicateWithBonusNumberValidator(Lotto winningLotto, int bonusNumber) { Set seen = new HashSet<>(); - for (int i = 0; i < winningLotto.getNumbers().size() + 1; i++) { + for (int i = 0; i < winningLotto.getNumbers().size(); i++) { if (!seen.add(winningLotto.getNumbers().get(i))) { - throw new IllegalArgumentException("[ERROR] ์ค‘๋ณต๋œ ๊ฐ’์„ ์ž…๋ ฅ๋ฐ›์•˜์Šต๋‹ˆ๋‹ค!"); - } - if (!seen.add(Integer.parseInt(bonusNumber))) { - throw new IllegalArgumentException("[ERROR] ์ค‘๋ณต๋œ ๊ฐ’์„ ์ž…๋ ฅ๋ฐ›์•˜์Šต๋‹ˆ๋‹ค!"); + throw new IllegalArgumentException(MessageConstants.NUMBER_DUPLICATE_ERROR.getMessage()); } } + if (!seen.add(bonusNumber)) { + throw new IllegalArgumentException(MessageConstants.NUMBER_DUPLICATE_ERROR.getMessage()); + } } } diff --git a/src/main/java/lotto/view/UserInput.java b/src/main/java/lotto/view/UserInput.java index 1d5859e..e258b16 100644 --- a/src/main/java/lotto/view/UserInput.java +++ b/src/main/java/lotto/view/UserInput.java @@ -2,40 +2,41 @@ import camp.nextstep.edu.missionutils.Console; import lotto.model.Lotto; +import lotto.util.MessageConstants; import java.util.ArrayList; public class UserInput { - private String budget; + private int budget; private Lotto winningLotto; - private String bonusNumber; + private int bonusNumber; public UserInput() { - budget = ""; - bonusNumber = ""; + budget = 0; + bonusNumber = 0; } public int getNumberOfLotto() { - return Integer.parseInt(budget)/1000; + return budget/1000; } public Lotto getWinningLotto() { return winningLotto; } - public String getBonusNumber() { return bonusNumber; } + public int getBonusNumber() { return bonusNumber; } - public void setTrial() { + public void setBudget() { try { - System.out.println("๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); - budget = Console.readLine(); + System.out.println(MessageConstants.REQUEST_PURCHASE_AMOUNT.getMessage()); + budget = Integer.parseInt(Console.readLine()); } catch (Exception exception) { - throw new IllegalArgumentException("[Error] ์ž…์ถœ๋ ฅ ๊ณผ์ •์—์„œ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. "); + throw new IllegalArgumentException(MessageConstants.INOUTPUT_ERROR.getMessage()); } } public void setWinningNumbers() { try { - System.out.println("๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + System.out.println(MessageConstants.REQUEST_WINNING_NUMBER.getMessage()); ArrayList numbers = new ArrayList<>(); String winningNums = Console.readLine(); for (String num : winningNums.split(",")) { @@ -44,16 +45,16 @@ public void setWinningNumbers() { winningLotto = new Lotto(numbers); } catch (Exception exception) { - throw new IllegalArgumentException("[Error] ์ž…์ถœ๋ ฅ ๊ณผ์ •์—์„œ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. "); + throw new IllegalArgumentException(MessageConstants.INOUTPUT_ERROR.getMessage()); } } public void setBonusNumber(){ try { - System.out.println("๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”"); - bonusNumber = Console.readLine(); + System.out.println(MessageConstants.REQUEST_BONUS_NUMBER.getMessage()); + bonusNumber = Integer.parseInt(Console.readLine()); } catch (Exception exception) { - throw new IllegalArgumentException("[Error] ์ž…์ถœ๋ ฅ ๊ณผ์ •์—์„œ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค. "); + throw new IllegalArgumentException(MessageConstants.INOUTPUT_ERROR.getMessage()); } } } diff --git a/src/main/java/lotto/view/UserOutput.java b/src/main/java/lotto/view/UserOutput.java index 01aac48..d74974b 100644 --- a/src/main/java/lotto/view/UserOutput.java +++ b/src/main/java/lotto/view/UserOutput.java @@ -1,16 +1,14 @@ package lotto.view; import lotto.model.Lotto; -import lotto.service.AdjustmentLotto; - -import java.awt.*; import java.util.List; +import lotto.util.MessageConstants; public class UserOutput { public void printNumberOfLotto(int numberOfLotto){ - System.out.println(numberOfLotto + "๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค."); + System.out.println(numberOfLotto + MessageConstants.PURCHASE_MESSAGE.getMessage()); } public void printNumberOfLottoNumbers(List lottoList) { @@ -18,8 +16,4 @@ public void printNumberOfLottoNumbers(List lottoList) { System.out.println(lotto.getNumbers()); } } - - public void printNumberOfWinningNumbers(Lotto winningLotto, int bonus) { - AdjustmentLotto adjustmentLotto = new AdjustmentLotto(); - } } From b2d268c2a8b49be8890c65f66f0e0e40a07ad594 Mon Sep 17 00:00:00 2001 From: Siul Date: Sun, 23 Feb 2025 22:06:16 +0900 Subject: [PATCH 7/7] =?UTF-8?q?=EA=B0=AF=EC=88=98=EA=B0=80=20=EC=A0=9C?= =?UTF-8?q?=EB=8C=80=EB=A1=9C=20=EC=95=88=20=EC=84=B8=EC=96=B4=EC=A7=80?= =?UTF-8?q?=EB=8A=94=20=EB=B2=84=EA=B7=B8=20=EB=B0=9C=EC=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/AppConfig.java | 8 +++---- .../lotto/controller/LottoController.java | 3 ++- .../java/lotto/service/AdjustmentLotto.java | 16 ++++---------- .../lotto/service/CalculateTotalBenefit.java | 3 +-- .../lotto/service/CountCorrectNumber.java | 15 +++++++------ .../java/lotto/service/FindSameNumber.java | 22 ------------------- src/main/java/lotto/service/LottoList.java | 3 +-- src/main/java/lotto/view/UserInput.java | 3 ++- src/main/java/lotto/view/UserOutput.java | 8 +++++++ 9 files changed, 30 insertions(+), 51 deletions(-) delete mode 100644 src/main/java/lotto/service/FindSameNumber.java diff --git a/src/main/java/lotto/AppConfig.java b/src/main/java/lotto/AppConfig.java index 9918b0d..ee8f77e 100644 --- a/src/main/java/lotto/AppConfig.java +++ b/src/main/java/lotto/AppConfig.java @@ -27,16 +27,16 @@ public LottoList makeRandomLotto(){ return new LottoList(userInput().getNumberOfLotto()); } - public CountCorrectNumber chooseCorrectNumber(){ + public CountCorrectNumber countCorrectNumber(){ return new CountCorrectNumber(makeRandomLotto().getLottoContainer()); } public AdjustmentLotto adjustmentLotto(){ - return new AdjustmentLotto(makeRandomLotto().getLottoContainer(), userInput().getBonusNumber()); + return new AdjustmentLotto(countCorrectNumber().getLottoList(), userInput().getBonusNumber()); } public CalculateTotalBenefit calculateTotalBenefit(){ - return new CalculateTotalBenefit(adjustmentLotto().getLotto(), userInput().getBonusNumber()); + return new CalculateTotalBenefit(adjustmentLotto().getLotto(), userInput().getBudget()); } public LottoController lottoController(){ return new LottoController( @@ -44,7 +44,7 @@ public LottoController lottoController(){ userOutput(), validator(), makeRandomLotto(), - chooseCorrectNumber(), + countCorrectNumber(), adjustmentLotto(), calculateTotalBenefit() ); diff --git a/src/main/java/lotto/controller/LottoController.java b/src/main/java/lotto/controller/LottoController.java index d29b7d9..a128a3b 100644 --- a/src/main/java/lotto/controller/LottoController.java +++ b/src/main/java/lotto/controller/LottoController.java @@ -63,8 +63,9 @@ public void executeLotto(){ public void winningPriceLotto(){ adjustmentLotto.countCorrectNumber(); - adjustmentLotto.printLotto(); + userOutput.printWinningLotto(adjustmentLotto.getLotto()); + calculateTotalBenefit.sumLotto(); calculateTotalBenefit.calculateTotalBenefit(); } diff --git a/src/main/java/lotto/service/AdjustmentLotto.java b/src/main/java/lotto/service/AdjustmentLotto.java index bb38a6f..0d629d3 100644 --- a/src/main/java/lotto/service/AdjustmentLotto.java +++ b/src/main/java/lotto/service/AdjustmentLotto.java @@ -1,35 +1,26 @@ package lotto.service; import lotto.model.Lotto; -import lotto.util.MessageConstants; import java.util.ArrayList; import java.util.List; -import static lotto.service.FindSameNumber.sameNumber; public class AdjustmentLotto { - private int[] lotto = {0, 0, 0, 0, 0}; + private int[] lotto = new int[5]; private List lottoList = new ArrayList(); private int bonus; public AdjustmentLotto(List lottoList, int bonus) { this.lottoList = lottoList; this.bonus = bonus; + for (int l : lotto) { lotto[l] = 0; } } public int[] getLotto() { return lotto; } - public void printLotto() { - System.out.println(MessageConstants.THREE_MESSAGE.getMessage() + lotto[0] + "๊ฐœ"); - System.out.println(MessageConstants.FOUR_MESSAGE.getMessage() + lotto[1] + "๊ฐœ"); - System.out.println(MessageConstants.FIVE_MESSAGE.getMessage() + lotto[2] + "๊ฐœ"); - System.out.println(MessageConstants.FIVE_AND_BONUS_MASSAGE.getMessage() + lotto[3] + "๊ฐœ"); - System.out.println(MessageConstants.SIX_MASSAGE.getMessage() + lotto[4] + "๊ฐœ"); - } - public void countCorrectNumber(){ for (Lotto l : lottoList){ countCorrectNumber(l); @@ -40,7 +31,8 @@ public void countCorrectNumber(Lotto winningLotto) { if (winningLotto.getCorrectNumbers() == 3) { lotto[0]++; } if (winningLotto.getCorrectNumbers() == 4) { lotto[1]++; } if (winningLotto.getCorrectNumbers() == 5) { - if (sameNumber(winningLotto, bonus)){ + CountCorrectNumber countCorrectNumber = new CountCorrectNumber(lottoList); + if (countCorrectNumber.sameNumber(winningLotto, bonus)){ lotto[3]++; return; } diff --git a/src/main/java/lotto/service/CalculateTotalBenefit.java b/src/main/java/lotto/service/CalculateTotalBenefit.java index d16e38a..ec72f04 100644 --- a/src/main/java/lotto/service/CalculateTotalBenefit.java +++ b/src/main/java/lotto/service/CalculateTotalBenefit.java @@ -11,7 +11,7 @@ public CalculateTotalBenefit(int[] lotto, int budget) { this.budget = budget; } - public double sumLotto(){ + public void sumLotto(){ lotto[0] *= 5000; lotto[1] *= 50000; lotto[2] *= 1500000; @@ -20,7 +20,6 @@ public double sumLotto(){ for (int i = 0; i < lotto.length; i++) { totalBenefit += (double)lotto[i]; } - return totalBenefit; } public void calculateTotalBenefit() { diff --git a/src/main/java/lotto/service/CountCorrectNumber.java b/src/main/java/lotto/service/CountCorrectNumber.java index fb1e12e..9c99b17 100644 --- a/src/main/java/lotto/service/CountCorrectNumber.java +++ b/src/main/java/lotto/service/CountCorrectNumber.java @@ -7,7 +7,9 @@ public class CountCorrectNumber { private List lottoList; - + public List getLottoList(){ + return lottoList; + } public CountCorrectNumber(List lottoList) { this.lottoList = lottoList; @@ -25,12 +27,11 @@ public void chooseCorrectNumber(Lotto myLotto, Lotto winningLotto) { } } - public void sameNumber(Lotto myLotto, int oneOfMyLottoNumber) { - for (int lotto : myLotto.getNumbers()) { - if (lotto == oneOfMyLottoNumber) { - myLotto.plusCorrectNumbers(); - break; - } + public boolean sameNumber(Lotto myLotto, int winningLottoNumber) { + if (myLotto.getNumbers().contains(winningLottoNumber)) { + myLotto.plusCorrectNumbers(); + return true; } + return false; } } diff --git a/src/main/java/lotto/service/FindSameNumber.java b/src/main/java/lotto/service/FindSameNumber.java deleted file mode 100644 index ebad5bf..0000000 --- a/src/main/java/lotto/service/FindSameNumber.java +++ /dev/null @@ -1,22 +0,0 @@ -package lotto.service; - -import lotto.model.Lotto; - -import java.awt.*; - -public class FindSameNumber { - private Lotto lotto; - - public FindSameNumber(Lotto lotto) { - this.lotto = lotto; - } - - public static boolean sameNumber(Lotto myLotto, int bonus) { - for (int lotto : myLotto.getNumbers()) { - if (lotto == bonus) { - return true; - } - } - return false; - } -} diff --git a/src/main/java/lotto/service/LottoList.java b/src/main/java/lotto/service/LottoList.java index f74c8ee..032cc06 100644 --- a/src/main/java/lotto/service/LottoList.java +++ b/src/main/java/lotto/service/LottoList.java @@ -15,8 +15,7 @@ public LottoList(int numberOfTrials) { List lottoNumbers = Randoms.pickUniqueNumbersInRange(1, 45, 6); Validator validator = new Validator(); validator.numberDuplicateValidator(lottoNumbers); - Lotto lotto = new Lotto(lottoNumbers); - lottoContainer.add(lotto); + lottoContainer.add(new Lotto(lottoNumbers) ); } } diff --git a/src/main/java/lotto/view/UserInput.java b/src/main/java/lotto/view/UserInput.java index e258b16..9062d45 100644 --- a/src/main/java/lotto/view/UserInput.java +++ b/src/main/java/lotto/view/UserInput.java @@ -21,9 +21,10 @@ public UserInput() { public int getNumberOfLotto() { return budget/1000; } - public Lotto getWinningLotto() { return winningLotto; } public int getBonusNumber() { return bonusNumber; } + public int getBudget() { return budget; } + public void setBudget() { try { diff --git a/src/main/java/lotto/view/UserOutput.java b/src/main/java/lotto/view/UserOutput.java index d74974b..787f9b8 100644 --- a/src/main/java/lotto/view/UserOutput.java +++ b/src/main/java/lotto/view/UserOutput.java @@ -16,4 +16,12 @@ public void printNumberOfLottoNumbers(List lottoList) { System.out.println(lotto.getNumbers()); } } + + public void printWinningLotto(int[] lotto){ + System.out.println(MessageConstants.THREE_MESSAGE.getMessage() + lotto[0] + "๊ฐœ"); + System.out.println(MessageConstants.FOUR_MESSAGE.getMessage() + lotto[1] + "๊ฐœ"); + System.out.println(MessageConstants.FIVE_MESSAGE.getMessage() + lotto[2] + "๊ฐœ"); + System.out.println(MessageConstants.FIVE_AND_BONUS_MASSAGE.getMessage() + lotto[3] + "๊ฐœ"); + System.out.println(MessageConstants.SIX_MASSAGE.getMessage() + lotto[4] + "๊ฐœ"); + } }