From 0f61e75e646ec5f186f196a552952974e9fd4e0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 03:27:53 +0900 Subject: [PATCH 01/32] docs(README.md): update README.md --- README.md | 234 ++++++++++-------------------------------------------- 1 file changed, 44 insertions(+), 190 deletions(-) diff --git a/README.md b/README.md index 81b03cdba2..fbe717dc8e 100644 --- a/README.md +++ b/README.md @@ -1,207 +1,61 @@ -# ๊ณผ์ œ - ๋กœ๋˜ +# ๐ŸŽฑ ๋กœ๋˜ ๋ฏธ์…˜ ์ง„ํ–‰ -## ๐Ÿ” ์ง„ํ–‰ ๋ฐฉ์‹ +
+ +## ๐Ÿ—’ ๊ตฌํ˜„ ๊ธฐ๋Šฅ ๋ชฉ๋ก + +### 1๏ธโƒฃ [์ž…๋ ฅ] ๊ตฌ์ž…ํ•  ๋กœ๋˜ ๊ธˆ์•ก ์ž…๋ ฅ๋ฐ›๊ธฐ + +- ์ฒœ์› ๋‹จ์œ„๋กœ ์ž…๋ ฅ๋ฐ›์•„ *MyLottoData*์˜ *money*์— ๊ธˆ์•ก์„ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. +- ์˜ˆ์™ธ์ฒ˜๋ฆฌ +- **inputPurchasingMoney**(): void + +
+ +### 2๏ธโƒฃ [๊ณ„์‚ฐ] ๋กœ๋˜ ๋ฐœํ–‰ํ•˜๊ธฐ + +- ๊ตฌ์ž…ํ•  ๋กœ๋˜ ๊ธˆ์•ก์œผ๋กœ๋ถ€ํ„ฐ ๋กœ๋˜ ๊ฐœ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•ด์„œ ๊ฐœ์ˆ˜๋ฅผ *MyLottoData*์˜ *quantity*์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. +- ๊ฐœ์ˆ˜๋งŒํผ ๋กœ๋˜๋ฅผ ์—ฌ๋Ÿฌ๊ฐœ ๋ฐœํ–‰ํ•ด์„œ *MyLottoData*์˜ *lottoSet*์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. +- **issueLottoMultiSet**: void // ๋กœ๋˜ ์—ฌ๋Ÿฌ๊ฐœ ๋ฐœํ–‰ + - **issueLottoOneSet**: void // ๋กœ๋˜ ํ•œ์žฅ ๋ฐœํ–‰ (์ˆซ์ž 6๊ฐœ) -- ๊ณผ์ œ๋Š” **๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ, ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ, ๊ณผ์ œ ์ง„ํ–‰ ์š”๊ตฌ ์‚ฌํ•ญ** ์„ธ ๊ฐ€์ง€๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค. -- ์„ธ ๊ฐœ์˜ ์š”๊ตฌ ์‚ฌํ•ญ์„ ๋งŒ์กฑํ•˜๊ธฐ ์œ„ํ•ด ๋…ธ๋ ฅํ•œ๋‹ค. ํŠนํžˆ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์ „์— ๊ธฐ๋Šฅ ๋ชฉ๋ก์„ ๋งŒ๋“ค๊ณ , ๊ธฐ๋Šฅ ๋‹จ์œ„๋กœ ์ปค๋ฐ‹ ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ง„ํ–‰ํ•œ๋‹ค. -- ๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ์— ๊ธฐ์žฌ๋˜์ง€ ์•Š์€ ๋‚ด์šฉ์€ ์Šค์Šค๋กœ ํŒ๋‹จํ•˜์—ฌ ๊ตฌํ˜„ํ•œ๋‹ค. ---- +
+ +### 2๏ธโƒฃ [์ถœ๋ ฅ] ๊ตฌ์ž…ํ•œ ๋กœ๋˜ ์ถœ๋ ฅํ•˜๊ธฐ + +- *MyLottoData*์˜ *lottoSet*์— ์ €์žฅ๋œ ๊ตฌ์ž…ํ•œ ๋กœ๋˜์˜ ๋ฒˆํ˜ธ๋“ค์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. +- **printPurchasedLotto()**: void + +
-## ๐Ÿ“ˆ ๊ณผ์ œ ์ง„ํ–‰ ๋ฐ ์ œ์ถœ ๋ฐฉ๋ฒ• +### 3๏ธโƒฃ [์ž…๋ ฅ] ๋‹น์ฒจ ๋ฒˆํ˜ธ์™€ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ ์ž…๋ ฅ๋ฐ›๊ธฐ -- ๊ณผ์ œ๋Š” [java-lotto](https://github.com/LandvibeDev/java-lotto) ์ €์žฅ์†Œ๋ฅผ Fork/Cloneํ•ด ์‹œ์ž‘ํ•œ๋‹ค. -- **๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์ „์— java-baseball-precourse/README.md ํŒŒ์ผ์— ๊ตฌํ˜„ํ•  ๊ธฐ๋Šฅ ๋ชฉ๋ก์„ ์ •๋ฆฌ**ํ•ด ์ถ”๊ฐ€ํ•œ๋‹ค. -- **Git์˜ ์ปค๋ฐ‹ ๋‹จ์œ„๋Š” ์•ž ๋‹จ๊ณ„์—์„œ README.md ํŒŒ์ผ์— ์ •๋ฆฌํ•œ ๊ธฐ๋Šฅ ๋ชฉ๋ก ๋‹จ์œ„**๋กœ ์ถ”๊ฐ€ํ•œ๋‹ค. - - [AngularJS Commit Message Conventions](https://gist.github.com/stephenparish/9941e89d80e2bc58a153) ์ฐธ๊ณ ํ•ด commit log๋ฅผ ๋‚จ๊ธด๋‹ค. -- ๊ณผ์ œ ์ง„ํ–‰ ๋ฐ ์ œ์ถœ ๋ฐฉ๋ฒ•์€ [์šฐ์•„ํ•œ์ฝ”์Šค ๊ณผ์ œ ์ œ์ถœ ๋ฌธ์„œ](https://github.com/woowacourse/woowacourse-docs/tree/master/precourse) ๋ฅผ ์ฐธ๊ณ ํ•œ๋‹ค. - - base repository๋ฅผ `LandvibeDev/java-lotto`๋กœ ์ง€์ •ํ•ด์„œ PR ์ƒ์„ฑํ•˜๋ฉด๋จ +- ๋‹น์ฒจ ๋ฒˆํ˜ธ์™€ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ *WinnerLottoData*์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. +- ์˜ˆ์™ธ์ฒ˜๋ฆฌ +- **inputWinnerNumber()**: void +- **inputBonusNumber()**: void
-### ํ…Œ์ŠคํŠธ ์‹คํ–‰ ๊ฐ€์ด๋“œ +### 4๏ธโƒฃ [๊ณ„์‚ฐ] ๋กœ๋˜ ๋‹น์ฒจ ๊ฒฐ๊ณผ ๊ณ„์‚ฐํ•˜๊ธฐ -- ํ„ฐ๋ฏธ๋„์—์„œ `java -version`์„ ์‹คํ–‰ํ•˜์—ฌ Java ๋ฒ„์ „์ด 14์ธ์ง€ ํ™•์ธํ•œ๋‹ค. ๋˜๋Š” Eclipse ๋˜๋Š” IntelliJ IDEA์™€ ๊ฐ™์€ IDE์—์„œ Java 14๋กœ ์‹คํ–‰๋˜๋Š”์ง€ ํ™•์ธํ•œ๋‹ค. -- ํ„ฐ๋ฏธ๋„์—์„œ Mac ๋˜๋Š” Linux ์‚ฌ์šฉ์ž์˜ ๊ฒฝ์šฐ `./gradlew clean test` ๋ช…๋ น์„ ์‹คํ–‰ ํ•˜๊ณ , - Windows ์‚ฌ์šฉ์ž์˜ ๊ฒฝ์šฐ `gradlew.bat clean test` ๋ช…๋ น์„ ์‹คํ–‰ํ•  ๋•Œ ๋™์ž‘ ํ•˜๋Š”์ง€ ๋งŒ ํ™•์ธ(ํ…Œ์ŠคํŠธ๋Š” ์‹คํŒจ). +- ๋ฐœํ–‰ํ•œ ๋กœ๋˜์™€ ๋‹น์ฒจ ๋ฒˆํ˜ธ, ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ๋น„๊ตํ•˜์—ฌ *ResultLottoData*์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. +- **calculateResultLotto()**: void + - **countNumberOfLottoMatches(**Lotto**)**: int + - **isMatchWithBonusNumber(**Lotto**)**: boolean ---- -## ๐Ÿš€ ๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ +
-๋กœ๋˜ ๊ฒŒ์ž„ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•ด์•ผ ํ•œ๋‹ค. ๋กœ๋˜ ๊ฒŒ์ž„์€ ์•„๋ž˜์™€ ๊ฐ™์€ ๊ทœ์น™์œผ๋กœ ์ง„ํ–‰๋œ๋‹ค. +### 5๏ธโƒฃ [์ถœ๋ ฅ] ๋กœ๋˜ ๋‹น์ฒจ ๊ฒฐ๊ณผ ์ถœ๋ ฅํ•˜๊ธฐ -``` -- ๋กœ๋˜ ๋ฒˆํ˜ธ์˜ ์ˆซ์ž ๋ฒ”์œ„๋Š” 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์› -``` +- *ResultLottoData*์— ์ €์žฅ๋œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ๋‹น์ฒจ ๊ฒฐ๊ณผ์™€ ์ˆ˜์ต๋ฅ ์„ ์ถœ๋ ฅํ•ฉ๋‹ˆ๋‹ค. +- **printResultLotto()**: void -- ๋กœ๋˜ ๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅํ•˜๋ฉด ๊ตฌ์ž… ๊ธˆ์•ก์— ํ•ด๋‹นํ•˜๋Š” ๋งŒํผ ๋กœ๋˜๋ฅผ ๋ฐœํ–‰ํ•ด์•ผ ํ•œ๋‹ค. -- ๋กœ๋˜ 1์žฅ์˜ ๊ฐ€๊ฒฉ์€ 1,000์›์ด๋‹ค. -- ๋‹น์ฒจ ๋ฒˆํ˜ธ์™€ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. -- ์‚ฌ์šฉ์ž๊ฐ€ ๊ตฌ๋งคํ•œ ๋กœ๋˜ ๋ฒˆํ˜ธ์™€ ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ๋น„๊ตํ•˜์—ฌ ๋‹น์ฒจ ๋‚ด์—ญ ๋ฐ ์ˆ˜์ต๋ฅ ์„ ์ถœ๋ ฅํ•˜๊ณ  ๋กœ๋˜ ๊ฒŒ์ž„์„ ์ข…๋ฃŒํ•œ๋‹ค. -- ์‚ฌ์šฉ์ž๊ฐ€ ์ž˜๋ชป๋œ ๊ฐ’์„ ์ž…๋ ฅํ•  ๊ฒฝ์šฐ `IllegalArgumentException`๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๊ณ , "[ERROR]"๋กœ ์‹œ์ž‘ํ•˜๋Š” ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅ ํ›„ ์ข…๋ฃŒํ•œ๋‹ค. +
-## โœ๐Ÿป ์ž…์ถœ๋ ฅ ์š”๊ตฌ์‚ฌํ•ญ +------ -### โŒจ๏ธ ์ž…๋ ฅ +
-- ๋กœ๋˜ ๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅ ๋ฐ›๋Š”๋‹ค. ๊ตฌ์ž… ๊ธˆ์•ก์€ 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%์ž…๋‹ˆ๋‹ค. -``` - ---- - -## ๐ŸŽฏ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ - -- JDK 14 ๋ฒ„์ „์—์„œ ์‹คํ–‰ ๊ฐ€๋Šฅํ•ด์•ผ ํ•œ๋‹ค. -- ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰์˜ ์‹œ์ž‘์ ์€ `Application`์˜ `main()`์ด๋‹ค. -- `build.gradle` ํŒŒ์ผ์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†๊ณ , ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค. -- [Java ์ฝ”๋“œ ์ปจ๋ฒค์…˜](https://naver.github.io/hackday-conventions-java/) ๊ฐ€์ด๋“œ๋ฅผ ์ค€์ˆ˜ํ•˜๋ฉฐ ํ”„๋กœ๊ทธ๋ž˜๋ฐํ•œ๋‹ค. -- ํ”„๋กœ๊ทธ๋žจ ์ข…๋ฃŒ ์‹œ `System.exit()`๋ฅผ ํ˜ธ์ถœํ•˜์ง€ ์•Š๋Š”๋‹ค. -- ํ”„๋กœ๊ทธ๋žจ ๊ตฌํ˜„์ด ์™„๋ฃŒ๋˜๋ฉด `ApplicationTest`์˜ ๋ชจ๋“  ํ…Œ์ŠคํŠธ๊ฐ€ ์„ฑ๊ณตํ•ด์•ผ ํ•œ๋‹ค. -- ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ์—์„œ ๋‹ฌ๋ฆฌ ๋ช…์‹œํ•˜์ง€ ์•Š๋Š” ํ•œ ํŒŒ์ผ, ํŒจํ‚ค์ง€ ์ด๋ฆ„์„ ์ˆ˜์ •ํ•˜๊ฑฐ๋‚˜ ์ด๋™ํ•˜์ง€ ์•Š๋Š”๋‹ค. -- 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, Scanner) ๋กœ์ง์€ ์ œ์™ธํ•œ๋‹ค. - - ํ•ต์‹ฌ ๋กœ์ง์„ ๊ตฌํ˜„ํ•˜๋Š” ์ฝ”๋“œ์™€ UI๋ฅผ ๋‹ด๋‹นํ•˜๋Š” ๋กœ์ง์„ ๋ถ„๋ฆฌํ•ด ๊ตฌํ˜„ํ•œ๋‹ค. - -### ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ - -- [`camp.nextstep.edu.missionutils`](https://github.com/woowacourse-projects/mission-utils)์—์„œ ์ œ๊ณตํ•˜๋Š” `Randoms` ๋ฐ `Console` API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌํ˜„ํ•ด์•ผ ํ•œ๋‹ค. - - Random ๊ฐ’ ์ถ”์ถœ์€ `camp.nextstep.edu.missionutils.Randoms`์˜ `pickUniqueNumbersInRange()`๋ฅผ ํ™œ์šฉํ•œ๋‹ค. - - ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•˜๋Š” ๊ฐ’์€ `camp.nextstep.edu.missionutils.Console`์˜ `readLine()`์„ ํ™œ์šฉํ•œ๋‹ค. - -#### ์‚ฌ์šฉ ์˜ˆ์‹œ - -```java -List numbers = Randoms.pickUniqueNumbersInRange(1, 45, 6); -``` - -### Lotto ํด๋ž˜์Šค - -- ์ œ๊ณต๋œ `Lotto` ํด๋ž˜์Šค๋ฅผ ํ™œ์šฉํ•ด ๊ตฌํ˜„ํ•ด์•ผ ํ•œ๋‹ค. -- `Lotto`์— ๋งค๊ฐœ ๋ณ€์ˆ˜๊ฐ€ ์—†๋Š” ์ƒ์„ฑ์ž๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์—†๋‹ค. -- `numbers`์˜ ์ ‘๊ทผ ์ œ์–ด์ž์ธ private์„ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†๋‹ค. -- `Lotto`์— ํ•„๋“œ(์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜)๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์—†๋‹ค. -- `Lotto`์˜ ํŒจํ‚ค์ง€ ๋ณ€๊ฒฝ์€ ๊ฐ€๋Šฅํ•˜๋‹ค. - -```java -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(); - } - } - - // TODO: ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ -} -``` From 6f52b9f814bb35e725c63885debca4d60ec3f548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 03:28:07 +0900 Subject: [PATCH 02/32] fix(build.gradle): update java language version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 1cd662974c..d844da4369 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ dependencies { java { toolchain { - languageVersion = JavaLanguageVersion.of(14) + languageVersion = JavaLanguageVersion.of(15) } } From 932f89edfb92f7ef330afec184068060cd6d3997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 03:28:48 +0900 Subject: [PATCH 03/32] feat(Message): add a constant message file --- src/main/java/lotto/Message.java | 75 ++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/main/java/lotto/Message.java diff --git a/src/main/java/lotto/Message.java b/src/main/java/lotto/Message.java new file mode 100644 index 0000000000..50ed990cb4 --- /dev/null +++ b/src/main/java/lotto/Message.java @@ -0,0 +1,75 @@ +package lotto; + +public class Message { + public enum Input { + PURCHASE_MONEY("๊ตฌ์ž…๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."), + WINNER_NUMBER("\n๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."), + BONUS_NUMBER("\n๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + + private final String inputMessage; + + Input(String message) { + inputMessage = message; + } + + @Override + public String toString() { + return inputMessage; + } + } + + public enum Output { + PURCHASE_QUANTITY("\n%d๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค."), + RESULT_STAT("\n๋‹น์ฒจ ํ†ต๊ณ„\n---"), + RESULT_RATE("์ด ์ˆ˜์ต๋ฅ ์€ %.1f%%์ž…๋‹ˆ๋‹ค."), + RESULT_CONTENTS(""" + 3๊ฐœ ์ผ์น˜ (%s์›) - %d๊ฐœ + 4๊ฐœ ์ผ์น˜ (%s์›) - %d๊ฐœ + 5๊ฐœ ์ผ์น˜ (%s์›) - %d๊ฐœ + 5๊ฐœ ์ผ์น˜, ๋ณด๋„ˆ์Šค ๋ณผ ์ผ์น˜ (%s์›) - %d๊ฐœ + 6๊ฐœ ์ผ์น˜ (%s์›) - %d๊ฐœ"""); + + private final String outputMessage; + Output(String message) { + outputMessage = message; + } + + public String toQuantityFormat(int lottoQuantity) { + return String.format(outputMessage, lottoQuantity); + } + + public String toRateFormat(double rate) { + return String.format(outputMessage, rate); + } + + public String toContentsFormat(ResultLottoData resultData) { + return String.format(outputMessage, + Number.Prize.THREE_MATCH.toDecimalFormat(), resultData.threeMatchCount, + Number.Prize.FOUR_MATCH.toDecimalFormat(), resultData.fourMatchCount, + Number.Prize.FIVE_MATCH.toDecimalFormat(), resultData.fiveMatchCount, + Number.Prize.FIVE_BONUS_MATCH.toDecimalFormat(), resultData.fiveAndBonusMatchCount, + Number.Prize.SIX_MATCH.toDecimalFormat(), resultData.sixMatchCount); + } + + @Override + public String toString() { + return outputMessage; + } + } + + public enum Error { + PURCHASE_AMOUNT("๊ตฌ์ž… ๊ธˆ์•ก์€ ๋กœ๋˜ ํ•œ์žฅ ๊ฐ€๊ฒฉ์˜ ๋‹จ์œ„๋กœ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."), + LOTTO_NUMBER("๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” ์ค‘๋ณต๋˜์ง€ ์•Š๋Š” 1๋ถ€ํ„ฐ 45 ์‚ฌ์ด์˜ ์ˆซ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."), + BONUS_NUMBER("์ค‘๋ณต๋˜์ง€ ์•Š๋Š” ํ•œ ๊ฐœ์˜ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + + private final String errorMessage; + + Error(String input) { + this.errorMessage = input; + } + + public String toErrorFormat() { + return "[ERROR] " + errorMessage; + } + } +} From dfd587f107ea0160ef563d1ebfec2cb9d24f1b61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 03:29:02 +0900 Subject: [PATCH 04/32] feat(Number): add a constant number file --- src/main/java/lotto/Number.java | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/main/java/lotto/Number.java diff --git a/src/main/java/lotto/Number.java b/src/main/java/lotto/Number.java new file mode 100644 index 0000000000..e28a21cc3a --- /dev/null +++ b/src/main/java/lotto/Number.java @@ -0,0 +1,46 @@ +package lotto; + +import java.text.DecimalFormat; + +public class Number { + public enum Rule { + MIN(1), + MAX(45), + SIZE(6), + PRICE(1000); + + private final int rule; + + Rule(int number) { + this.rule = number; + } + + public int toNumber() { + return rule; + } + } + + public enum Prize { + THREE_MATCH(5000), + FOUR_MATCH(50000), + FIVE_MATCH(1500000), + FIVE_BONUS_MATCH(30000000), + SIX_MATCH(2000000000); + + private final int prize; + + Prize(int number) { + this.prize = number; + } + + public int toNumber() { + return prize; + } + + public String toDecimalFormat() { + DecimalFormat decimalFormat = new DecimalFormat("#,###"); + String formattedNumber = decimalFormat.format(prize); + return formattedNumber; + } + } +} \ No newline at end of file From a4c0ede051a649316a4e00889536c2587097f56e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 03:30:41 +0900 Subject: [PATCH 05/32] feat(Lotto): add a Lotto class --- src/main/java/lotto/Lotto.java | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/main/java/lotto/Lotto.java diff --git a/src/main/java/lotto/Lotto.java b/src/main/java/lotto/Lotto.java new file mode 100644 index 0000000000..f9fe58916e --- /dev/null +++ b/src/main/java/lotto/Lotto.java @@ -0,0 +1,27 @@ +package lotto; + +import camp.nextstep.edu.missionutils.Randoms; + +import java.util.Collections; +import java.util.ArrayList; +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(); + } + } + + public List getNumbers() { + Collections.sort(numbers); + return numbers; + } +} \ No newline at end of file From 380bcaa94435d644f4a52cb1ca42835d9c0c1f8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 03:31:05 +0900 Subject: [PATCH 06/32] feat(MyLottoData): add a MyLottoData class --- src/main/java/lotto/MyLottoData.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/lotto/MyLottoData.java diff --git a/src/main/java/lotto/MyLottoData.java b/src/main/java/lotto/MyLottoData.java new file mode 100644 index 0000000000..3cb36cfb1b --- /dev/null +++ b/src/main/java/lotto/MyLottoData.java @@ -0,0 +1,16 @@ +package lotto; + +import java.util.ArrayList; +import java.util.List; + +public class MyLottoData { + public int money; + public int quantity; + public List lottoSet; + + public MyLottoData() { + money = 0; + quantity = 0; + lottoSet = new ArrayList<>(); + } +} From 4ec9285d36a0c39d014f64d19f40724f91aa501e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 03:31:38 +0900 Subject: [PATCH 07/32] feat(WinnerLottoData): add a WinnerLottoData class --- src/main/java/lotto/WinnerLottoData.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/main/java/lotto/WinnerLottoData.java diff --git a/src/main/java/lotto/WinnerLottoData.java b/src/main/java/lotto/WinnerLottoData.java new file mode 100644 index 0000000000..9b7a4f72cb --- /dev/null +++ b/src/main/java/lotto/WinnerLottoData.java @@ -0,0 +1,19 @@ +package lotto; + +import java.util.ArrayList; +import java.util.List; + +public class WinnerLottoData { + public Lotto number; + public int bonusNumber; + + public void parseWinnerNumber(String input) { + String[] stringArray = input.split(","); + List integerList = new ArrayList<>(); + for (String str : stringArray) { + int num = Integer.parseInt(str); + integerList.add(num); + } + this.number = new Lotto(integerList); + } +} \ No newline at end of file From 64cf7babce30d54204d26960e22a8d85ae96ee7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 03:31:44 +0900 Subject: [PATCH 08/32] feat(ResultLottoData): add a ResultLottoData class --- src/main/java/lotto/ResultLottoData.java | 57 ++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/main/java/lotto/ResultLottoData.java diff --git a/src/main/java/lotto/ResultLottoData.java b/src/main/java/lotto/ResultLottoData.java new file mode 100644 index 0000000000..b9370aaa76 --- /dev/null +++ b/src/main/java/lotto/ResultLottoData.java @@ -0,0 +1,57 @@ +package lotto; + +public class ResultLottoData { + public int threeMatchCount; + public int fourMatchCount; + public int fiveMatchCount; + public int fiveAndBonusMatchCount; + public int sixMatchCount; + public int totalProfit; + public double rate; + + public ResultLottoData() { + threeMatchCount = 0; + fourMatchCount = 0; + fiveMatchCount = 0; + fiveAndBonusMatchCount = 0; + sixMatchCount = 0; + totalProfit = 0; + rate = 0.0; + } + + public void update(int numOfLottoMatches, boolean isMatchWithBonus) { + if(numOfLottoMatches == 3) { + threeMatchCount++; + return; + } + if(numOfLottoMatches == 4) { + fourMatchCount++; + return; + } + if(numOfLottoMatches == 5) { + if(isMatchWithBonus) { + fiveAndBonusMatchCount++; + return; + } + fiveMatchCount++; + return; + } + if(numOfLottoMatches == 6) { + sixMatchCount++; + return; + } + } + + public void calculateProfit() { + totalProfit = threeMatchCount * Number.Prize.THREE_MATCH.toNumber() + + fourMatchCount * Number.Prize.FOUR_MATCH.toNumber() + + fiveMatchCount * Number.Prize.FIVE_MATCH.toNumber() + + fiveAndBonusMatchCount * Number.Prize.FIVE_BONUS_MATCH.toNumber() + + sixMatchCount * Number.Prize.SIX_MATCH.toNumber(); + } + + public void calculateRate(int purchaseMoney) { + double rate = (this.totalProfit / purchaseMoney) * 100; + this.rate = Math.round(rate * 100.0) / 100.0; + } +} \ No newline at end of file From 58157ea7958ed57ba0e54230d5c9c49c7c159c33 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 03:34:34 +0900 Subject: [PATCH 09/32] feat(LottoManager): add a LottoManager class --- src/main/java/lotto/LottoManager.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/lotto/LottoManager.java diff --git a/src/main/java/lotto/LottoManager.java b/src/main/java/lotto/LottoManager.java new file mode 100644 index 0000000000..4fc452da0f --- /dev/null +++ b/src/main/java/lotto/LottoManager.java @@ -0,0 +1,16 @@ +package lotto; + +import camp.nextstep.edu.missionutils.Console; +import camp.nextstep.edu.missionutils.Randoms; + +public class LottoManager { + private MyLottoData myLotto; + private WinnerLottoData winnerLotto; + private ResultLottoData resultLotto; + + public LottoManager() { + myLotto = new MyLottoData(); + winnerLotto = new WinnerLottoData(); + resultLotto = new ResultLottoData(); + } +} From d65a39eb1e9a60106d950fac2d7fbaf27e59cdcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 03:36:06 +0900 Subject: [PATCH 10/32] feat(LottoManager): add a function that input purchase money --- src/main/java/lotto/LottoManager.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/lotto/LottoManager.java b/src/main/java/lotto/LottoManager.java index 4fc452da0f..6bb733b767 100644 --- a/src/main/java/lotto/LottoManager.java +++ b/src/main/java/lotto/LottoManager.java @@ -13,4 +13,17 @@ public LottoManager() { winnerLotto = new WinnerLottoData(); resultLotto = new ResultLottoData(); } + + private void inputPurchaingMoney() { + System.out.println(Message.Input.PURCHASE_MONEY); + String input = Console.readLine(); + validatePurchaseMoney(input); + int money = Integer.parseInt(input); + myLotto.money = money; + } + + // TODO: - ์œ ํšจ์„ฑ ์ฒดํฌ + private void validatePurchaseMoney(String money) { + + } } From cc4713830073df39eb5e5d643e092ae7b1fb51d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 03:37:44 +0900 Subject: [PATCH 11/32] feat(LottoManager): add two functions that issue lottery --- src/main/java/lotto/LottoManager.java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/main/java/lotto/LottoManager.java b/src/main/java/lotto/LottoManager.java index 6bb733b767..01e22cd55a 100644 --- a/src/main/java/lotto/LottoManager.java +++ b/src/main/java/lotto/LottoManager.java @@ -3,6 +3,9 @@ import camp.nextstep.edu.missionutils.Console; import camp.nextstep.edu.missionutils.Randoms; +import java.util.ArrayList; +import java.util.List; + public class LottoManager { private MyLottoData myLotto; private WinnerLottoData winnerLotto; @@ -22,6 +25,26 @@ private void inputPurchaingMoney() { myLotto.money = money; } + private void issueLottoMultiSet() { + myLotto.quantity = myLotto.money / Number.Rule.PRICE.toNumber(); + while(myLotto.lottoSet.size() < myLotto.quantity) { + Lotto lottoOneSet = issueLottoOneSet(); + myLotto.lottoSet.add(lottoOneSet); + } + } + + private Lotto issueLottoOneSet() { + List lottoOneList = new ArrayList<>(); + while(lottoOneList.size() < Number.Rule.SIZE.toNumber()) { + int newNumber = Randoms.pickNumberInRange(Number.Rule.MIN.toNumber(), Number.Rule.MAX.toNumber()); + if(lottoOneList.contains(newNumber)) { + continue; + } + lottoOneList.add(newNumber); + } + return new Lotto(lottoOneList); + } + // TODO: - ์œ ํšจ์„ฑ ์ฒดํฌ private void validatePurchaseMoney(String money) { From 25fa5d97433cbbdaa4fc151e8507363bc063a0f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 03:39:01 +0900 Subject: [PATCH 12/32] feat(LottoManager): add a function that print issued lottery --- src/main/java/lotto/LottoManager.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/lotto/LottoManager.java b/src/main/java/lotto/LottoManager.java index 01e22cd55a..a35d52b6aa 100644 --- a/src/main/java/lotto/LottoManager.java +++ b/src/main/java/lotto/LottoManager.java @@ -45,6 +45,13 @@ private Lotto issueLottoOneSet() { return new Lotto(lottoOneList); } + private void printPurchasedLotto() { + System.out.println(Message.Output.PURCHASE_QUANTITY.toQuantityFormat(myLotto.quantity)); + for(Lotto lotto : myLotto.lottoSet) { + System.out.println(lotto.getNumbers()); + } + } + // TODO: - ์œ ํšจ์„ฑ ์ฒดํฌ private void validatePurchaseMoney(String money) { From d500744c199294234f32c18a619a4355c62032a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 03:39:52 +0900 Subject: [PATCH 13/32] feat(LottoManager): add two functions that input winner and bonus number --- src/main/java/lotto/LottoManager.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/main/java/lotto/LottoManager.java b/src/main/java/lotto/LottoManager.java index a35d52b6aa..3788f043ca 100644 --- a/src/main/java/lotto/LottoManager.java +++ b/src/main/java/lotto/LottoManager.java @@ -52,8 +52,30 @@ private void printPurchasedLotto() { } } + private void inputWinnerNumber() { + System.out.println(Message.Input.WINNER_NUMBER); + String winnerString = Console.readLine(); + validateWinnerString(winnerString); + winnerLotto.parseWinnerNumber(winnerString); + } + + private void inputBonusNumber() { + System.out.println(Message.Input.BONUS_NUMBER); + String bonusNumber = Console.readLine(); + validateBonusNumber(bonusNumber); + winnerLotto.bonusNumber = Integer.parseInt(bonusNumber); + } + // TODO: - ์œ ํšจ์„ฑ ์ฒดํฌ private void validatePurchaseMoney(String money) { } + + private void validateWinnerString(String input) { + + } + + private void validateBonusNumber(String input) { + + } } From 8118e3f94b1a9f6b72f4a0f06654dce058b04589 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 03:40:39 +0900 Subject: [PATCH 14/32] feat(LottoManager): add a function that calculate my profit and rate --- src/main/java/lotto/LottoManager.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/lotto/LottoManager.java b/src/main/java/lotto/LottoManager.java index 3788f043ca..cf974f1d5a 100644 --- a/src/main/java/lotto/LottoManager.java +++ b/src/main/java/lotto/LottoManager.java @@ -66,6 +66,16 @@ private void inputBonusNumber() { winnerLotto.bonusNumber = Integer.parseInt(bonusNumber); } + private void calculateResultLotto() { + for (Lotto lottoOneSet : myLotto.lottoSet) { + int matchCount = countNumberOfLottoMatches(lottoOneSet); + boolean isBonusMatch = isMatchWithBonusNumber(lottoOneSet); + resultLotto.update(matchCount, isBonusMatch); + } + resultLotto.calculateProfit(); + resultLotto.calculateRate(myLotto.money); + } + // TODO: - ์œ ํšจ์„ฑ ์ฒดํฌ private void validatePurchaseMoney(String money) { From e7bb169c63637463ec182103458dfaed75e8ecba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 03:41:59 +0900 Subject: [PATCH 15/32] feat(LottoManager): add two functions that used for calculate lottery result --- src/main/java/lotto/LottoManager.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/lotto/LottoManager.java b/src/main/java/lotto/LottoManager.java index cf974f1d5a..1fcff1056b 100644 --- a/src/main/java/lotto/LottoManager.java +++ b/src/main/java/lotto/LottoManager.java @@ -75,7 +75,21 @@ private void calculateResultLotto() { resultLotto.calculateProfit(); resultLotto.calculateRate(myLotto.money); } - + + private int countNumberOfLottoMatches(Lotto lottoOneSet) { + int matchCount = 0; + for (int number : lottoOneSet.getNumbers()) { + if (winnerLotto.number.getNumbers().contains(number)) { + matchCount++; + } + } + return matchCount; + } + + private boolean isMatchWithBonusNumber(Lotto lottoOneSet) { + return lottoOneSet.getNumbers().contains(winnerLotto.bonusNumber); + } + // TODO: - ์œ ํšจ์„ฑ ์ฒดํฌ private void validatePurchaseMoney(String money) { From 561627e16501c0745a5072431ec2b250955935e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 03:42:27 +0900 Subject: [PATCH 16/32] feat(LottoManager): add a function that print lottery result --- src/main/java/lotto/LottoManager.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/lotto/LottoManager.java b/src/main/java/lotto/LottoManager.java index 1fcff1056b..9160dc61be 100644 --- a/src/main/java/lotto/LottoManager.java +++ b/src/main/java/lotto/LottoManager.java @@ -90,6 +90,12 @@ private boolean isMatchWithBonusNumber(Lotto lottoOneSet) { return lottoOneSet.getNumbers().contains(winnerLotto.bonusNumber); } + private void printResultLotto() { + System.out.println(Message.Output.RESULT_STAT); + System.out.println(Message.Output.RESULT_CONTENTS.toContentsFormat(resultLotto)); + System.out.println(Message.Output.RESULT_RATE.toRateFormat(resultLotto.rate)); + } + // TODO: - ์œ ํšจ์„ฑ ์ฒดํฌ private void validatePurchaseMoney(String money) { From 94feba050747b7f978f52701addd7a5137ec02f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 03:43:38 +0900 Subject: [PATCH 17/32] feat(LottoManager): add a play function to operate the full functions --- src/main/java/lotto/LottoManager.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/lotto/LottoManager.java b/src/main/java/lotto/LottoManager.java index 9160dc61be..cae8627d42 100644 --- a/src/main/java/lotto/LottoManager.java +++ b/src/main/java/lotto/LottoManager.java @@ -17,6 +17,16 @@ public LottoManager() { resultLotto = new ResultLottoData(); } + public void play() { + inputPurchaingMoney(); + issueLottoMultiSet(); + printPurchasedLotto(); + inputWinnerNumber(); + inputBonusNumber(); + calculateResultLotto(); + printResultLotto(); + } + private void inputPurchaingMoney() { System.out.println(Message.Input.PURCHASE_MONEY); String input = Console.readLine(); From 3796ee47c349e2e5084cec30326f04aec0366639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 03:44:10 +0900 Subject: [PATCH 18/32] feat(Application): add codes to operate LottoManager class --- src/main/java/lotto/Application.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java index 367ee30584..9ee6db8b64 100644 --- a/src/main/java/lotto/Application.java +++ b/src/main/java/lotto/Application.java @@ -2,6 +2,7 @@ public class Application { public static void main(String[] args) { - // TODO: ํ”„๋กœ๊ทธ๋žจ ๊ตฌํ˜„ + LottoManager lottoManager = new LottoManager(); + lottoManager.play(); } } \ No newline at end of file From 6d0df310eb4be9638c2fc72b4313e9fc2f58cf61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 03:49:41 +0900 Subject: [PATCH 19/32] feat(LottoManager): delete a issueLottoOneSet function --- src/main/java/lotto/LottoManager.java | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/main/java/lotto/LottoManager.java b/src/main/java/lotto/LottoManager.java index cae8627d42..ef4aadf1cd 100644 --- a/src/main/java/lotto/LottoManager.java +++ b/src/main/java/lotto/LottoManager.java @@ -38,23 +38,12 @@ private void inputPurchaingMoney() { private void issueLottoMultiSet() { myLotto.quantity = myLotto.money / Number.Rule.PRICE.toNumber(); while(myLotto.lottoSet.size() < myLotto.quantity) { - Lotto lottoOneSet = issueLottoOneSet(); + List lottoOneList = Randoms.pickUniqueNumbersInRange(Number.Rule.MIN.toNumber(), Number.Rule.MAX.toNumber(), Number.Rule.SIZE.toNumber()); + Lotto lottoOneSet = new Lotto(lottoOneList); myLotto.lottoSet.add(lottoOneSet); } } - private Lotto issueLottoOneSet() { - List lottoOneList = new ArrayList<>(); - while(lottoOneList.size() < Number.Rule.SIZE.toNumber()) { - int newNumber = Randoms.pickNumberInRange(Number.Rule.MIN.toNumber(), Number.Rule.MAX.toNumber()); - if(lottoOneList.contains(newNumber)) { - continue; - } - lottoOneList.add(newNumber); - } - return new Lotto(lottoOneList); - } - private void printPurchasedLotto() { System.out.println(Message.Output.PURCHASE_QUANTITY.toQuantityFormat(myLotto.quantity)); for(Lotto lotto : myLotto.lottoSet) { From 9de6adeb4463161d4ff798cb54d8772a9ec930f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 03:49:50 +0900 Subject: [PATCH 20/32] docs(README.md): update README.md --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index fbe717dc8e..a1d9e66049 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,7 @@ - ๊ตฌ์ž…ํ•  ๋กœ๋˜ ๊ธˆ์•ก์œผ๋กœ๋ถ€ํ„ฐ ๋กœ๋˜ ๊ฐœ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•ด์„œ ๊ฐœ์ˆ˜๋ฅผ *MyLottoData*์˜ *quantity*์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. - ๊ฐœ์ˆ˜๋งŒํผ ๋กœ๋˜๋ฅผ ์—ฌ๋Ÿฌ๊ฐœ ๋ฐœํ–‰ํ•ด์„œ *MyLottoData*์˜ *lottoSet*์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. -- **issueLottoMultiSet**: void // ๋กœ๋˜ ์—ฌ๋Ÿฌ๊ฐœ ๋ฐœํ–‰ - - **issueLottoOneSet**: void // ๋กœ๋˜ ํ•œ์žฅ ๋ฐœํ–‰ (์ˆซ์ž 6๊ฐœ) - +- **issueLottoMultiSet**: void
From acecbd0833db325139b82fabb97b8c5b433d9f58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 04:23:25 +0900 Subject: [PATCH 21/32] feat(ResultLottoData): update code at calculateRate function --- src/main/java/lotto/ResultLottoData.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/lotto/ResultLottoData.java b/src/main/java/lotto/ResultLottoData.java index b9370aaa76..0887514341 100644 --- a/src/main/java/lotto/ResultLottoData.java +++ b/src/main/java/lotto/ResultLottoData.java @@ -51,7 +51,7 @@ public void calculateProfit() { } public void calculateRate(int purchaseMoney) { - double rate = (this.totalProfit / purchaseMoney) * 100; - this.rate = Math.round(rate * 100.0) / 100.0; + double money = purchaseMoney; + this.rate = (this.totalProfit / money) * 100.0; } } \ No newline at end of file From d5e9c7dd27963709b75eb2a63663e50e7464a3c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 04:24:03 +0900 Subject: [PATCH 22/32] feat(Message): update code about output rate format --- src/main/java/lotto/Message.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/lotto/Message.java b/src/main/java/lotto/Message.java index 50ed990cb4..1dd503b986 100644 --- a/src/main/java/lotto/Message.java +++ b/src/main/java/lotto/Message.java @@ -1,5 +1,7 @@ package lotto; +import java.text.DecimalFormat; + public class Message { public enum Input { PURCHASE_MONEY("๊ตฌ์ž…๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."), @@ -21,7 +23,7 @@ public String toString() { public enum Output { PURCHASE_QUANTITY("\n%d๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค."), RESULT_STAT("\n๋‹น์ฒจ ํ†ต๊ณ„\n---"), - RESULT_RATE("์ด ์ˆ˜์ต๋ฅ ์€ %.1f%%์ž…๋‹ˆ๋‹ค."), + RESULT_RATE("์ด ์ˆ˜์ต๋ฅ ์€ %s%%์ž…๋‹ˆ๋‹ค."), RESULT_CONTENTS(""" 3๊ฐœ ์ผ์น˜ (%s์›) - %d๊ฐœ 4๊ฐœ ์ผ์น˜ (%s์›) - %d๊ฐœ @@ -39,7 +41,9 @@ public String toQuantityFormat(int lottoQuantity) { } public String toRateFormat(double rate) { - return String.format(outputMessage, rate); + DecimalFormat decimalFormat = new DecimalFormat("#.##"); + String roundedNumber = decimalFormat.format(rate); + return String.format(outputMessage, roundedNumber); } public String toContentsFormat(ResultLottoData resultData) { From 5dc0977a3bfa2e338bf4ba8682be5e3e3d104a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 04:46:16 +0900 Subject: [PATCH 23/32] docs(README.md): update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a1d9e66049..392b390cad 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ - ์ฒœ์› ๋‹จ์œ„๋กœ ์ž…๋ ฅ๋ฐ›์•„ *MyLottoData*์˜ *money*์— ๊ธˆ์•ก์„ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. - ์˜ˆ์™ธ์ฒ˜๋ฆฌ -- **inputPurchasingMoney**(): void +- **inputPurchasingMoney()**: void
@@ -16,7 +16,7 @@ - ๊ตฌ์ž…ํ•  ๋กœ๋˜ ๊ธˆ์•ก์œผ๋กœ๋ถ€ํ„ฐ ๋กœ๋˜ ๊ฐœ์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•ด์„œ ๊ฐœ์ˆ˜๋ฅผ *MyLottoData*์˜ *quantity*์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. - ๊ฐœ์ˆ˜๋งŒํผ ๋กœ๋˜๋ฅผ ์—ฌ๋Ÿฌ๊ฐœ ๋ฐœํ–‰ํ•ด์„œ *MyLottoData*์˜ *lottoSet*์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. -- **issueLottoMultiSet**: void +- **issueLottoMultiSet()**: void
From 7cd2e4003771566f81ba40474a7078637c652352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 04:47:03 +0900 Subject: [PATCH 24/32] feat(LottoManager): add validation codes --- src/main/java/lotto/Lotto.java | 1 - src/main/java/lotto/LottoManager.java | 31 +++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/main/java/lotto/Lotto.java b/src/main/java/lotto/Lotto.java index f9fe58916e..96f98c68c3 100644 --- a/src/main/java/lotto/Lotto.java +++ b/src/main/java/lotto/Lotto.java @@ -21,7 +21,6 @@ private void validate(List numbers) { } public List getNumbers() { - Collections.sort(numbers); return numbers; } } \ No newline at end of file diff --git a/src/main/java/lotto/LottoManager.java b/src/main/java/lotto/LottoManager.java index ef4aadf1cd..be6f032578 100644 --- a/src/main/java/lotto/LottoManager.java +++ b/src/main/java/lotto/LottoManager.java @@ -95,16 +95,39 @@ private void printResultLotto() { System.out.println(Message.Output.RESULT_RATE.toRateFormat(resultLotto.rate)); } - // TODO: - ์œ ํšจ์„ฑ ์ฒดํฌ - private void validatePurchaseMoney(String money) { - + private void validatePurchaseMoney(String input) throws IllegalArgumentException { + for(char c : input.toCharArray()) { + if(c < '0' || c > '9') { + throw new IllegalArgumentException(Message.Error.PURCHASE_AMOUNT.toErrorFormat()); + } + } + int purchaseMoney = Integer.parseInt(input); + if(purchaseMoney % Number.Rule.PRICE.toNumber() != 0) { + throw new IllegalArgumentException(Message.Error.PURCHASE_AMOUNT.toErrorFormat()); + } } private void validateWinnerString(String input) { - + try { + String[] stringArray = input.split(","); + for (String str : stringArray) { + int num = Integer.parseInt(str); + } + } catch (Exception e) { + throw new IllegalArgumentException(Message.Error.LOTTO_NUMBER.toErrorFormat()); + } } private void validateBonusNumber(String input) { + try { + Integer.parseInt(input); + } catch (NumberFormatException e) { + throw new IllegalArgumentException(Message.Error.BONUS_NUMBER.toErrorFormat()); + } + int bonusNumber = Integer.parseInt(input); + if(bonusNumber < Number.Rule.MIN.toNumber() || bonusNumber > Number.Rule.MAX.toNumber()) { + throw new IllegalArgumentException(Message.Error.BONUS_NUMBER.toErrorFormat()); + } } } From dd04ac0c7c08aae95ea4534829deeab7db93bc66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 10 Jul 2023 05:02:26 +0900 Subject: [PATCH 25/32] docs(README.md): update README.md --- README.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/README.md b/README.md index 392b390cad..8faa313cfd 100644 --- a/README.md +++ b/README.md @@ -57,3 +57,37 @@
+ + +## ๐Ÿ—‚ ํด๋”๋ง + +``` +๐Ÿ“ฆ src/main/java/ +| ++ ๐Ÿ—‚ lotto/ +โ”‚ ++-------๐Ÿ…ฒ Application +| : main() ์กด์žฌ, LottoManager ํ˜ธ์ถœ +| ++-------๐Ÿ…ฒ LottoManager +| : ๋กœ๋˜๊ฐ€ ์ง„ํ–‰๋˜๋Š” ํด๋ž˜์Šค +| ++-------๐Ÿ…ฒ Lotto +| : 6๊ฐœ์˜ ๋กœ๋˜ ์ˆซ์ž๊ฐ€ ์ €์žฅ๋˜๋Š” ํด๋ž˜์Šค +| ++-------๐Ÿ…ฒ MyLottoData +| : ๊ตฌ์ž… ๊ธˆ์•ก๊ณผ ๋ฐœํ–‰๋œ ๋กœ๋˜ ์ˆ˜๋Ÿ‰๊ณผ ๋ฒˆํ˜ธ๊ฐ€ ์ €์žฅ๋˜๋Š” ํด๋ž˜์Šค +| ++-------๐Ÿ…ฒ WinnerLottoData +| : ๋‹น์ฒจ ๋ฒˆํ˜ธ์™€ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๊ฐ€ ์ €์žฅ๋˜๋Š” ํด๋ž˜์Šค +| ++-------๐Ÿ…ฒ ResultLottoData +| : ๋กœ๋˜ ๋‹น์ฒจ ๊ฒฐ๊ณผ์™€ ์ˆ˜์ต๋ฅ ์ด ์ €์žฅ๋˜๋Š” ํด๋ž˜์Šค +| ++-------๐Ÿ…ฒ Message +| : ์ƒ์ˆ˜ ๋ฉ”์„ธ์ง€๋“ค์„ ๋ชจ์•„๋†“์€ ํด๋ž˜์Šค +| ++-------๐Ÿ…ฒ Number +| : ์ƒ์ˆ˜ ์ˆซ์ž๋“ค์„ ๋ชจ์•„๋†“์€ ํด๋ž˜์Šค + +``` From 0183b3763f7740c160e4ee7fefb2532f3d7fe8fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Tue, 18 Jul 2023 13:31:04 +0900 Subject: [PATCH 26/32] feat (LottoData) : delete LottoData --- src/main/java/lotto/MyLottoData.java | 16 ------- src/main/java/lotto/ResultLottoData.java | 57 ------------------------ src/main/java/lotto/WinnerLottoData.java | 19 -------- 3 files changed, 92 deletions(-) delete mode 100644 src/main/java/lotto/MyLottoData.java delete mode 100644 src/main/java/lotto/ResultLottoData.java delete mode 100644 src/main/java/lotto/WinnerLottoData.java diff --git a/src/main/java/lotto/MyLottoData.java b/src/main/java/lotto/MyLottoData.java deleted file mode 100644 index 3cb36cfb1b..0000000000 --- a/src/main/java/lotto/MyLottoData.java +++ /dev/null @@ -1,16 +0,0 @@ -package lotto; - -import java.util.ArrayList; -import java.util.List; - -public class MyLottoData { - public int money; - public int quantity; - public List lottoSet; - - public MyLottoData() { - money = 0; - quantity = 0; - lottoSet = new ArrayList<>(); - } -} diff --git a/src/main/java/lotto/ResultLottoData.java b/src/main/java/lotto/ResultLottoData.java deleted file mode 100644 index 0887514341..0000000000 --- a/src/main/java/lotto/ResultLottoData.java +++ /dev/null @@ -1,57 +0,0 @@ -package lotto; - -public class ResultLottoData { - public int threeMatchCount; - public int fourMatchCount; - public int fiveMatchCount; - public int fiveAndBonusMatchCount; - public int sixMatchCount; - public int totalProfit; - public double rate; - - public ResultLottoData() { - threeMatchCount = 0; - fourMatchCount = 0; - fiveMatchCount = 0; - fiveAndBonusMatchCount = 0; - sixMatchCount = 0; - totalProfit = 0; - rate = 0.0; - } - - public void update(int numOfLottoMatches, boolean isMatchWithBonus) { - if(numOfLottoMatches == 3) { - threeMatchCount++; - return; - } - if(numOfLottoMatches == 4) { - fourMatchCount++; - return; - } - if(numOfLottoMatches == 5) { - if(isMatchWithBonus) { - fiveAndBonusMatchCount++; - return; - } - fiveMatchCount++; - return; - } - if(numOfLottoMatches == 6) { - sixMatchCount++; - return; - } - } - - public void calculateProfit() { - totalProfit = threeMatchCount * Number.Prize.THREE_MATCH.toNumber() - + fourMatchCount * Number.Prize.FOUR_MATCH.toNumber() - + fiveMatchCount * Number.Prize.FIVE_MATCH.toNumber() - + fiveAndBonusMatchCount * Number.Prize.FIVE_BONUS_MATCH.toNumber() - + sixMatchCount * Number.Prize.SIX_MATCH.toNumber(); - } - - public void calculateRate(int purchaseMoney) { - double money = purchaseMoney; - this.rate = (this.totalProfit / money) * 100.0; - } -} \ No newline at end of file diff --git a/src/main/java/lotto/WinnerLottoData.java b/src/main/java/lotto/WinnerLottoData.java deleted file mode 100644 index 9b7a4f72cb..0000000000 --- a/src/main/java/lotto/WinnerLottoData.java +++ /dev/null @@ -1,19 +0,0 @@ -package lotto; - -import java.util.ArrayList; -import java.util.List; - -public class WinnerLottoData { - public Lotto number; - public int bonusNumber; - - public void parseWinnerNumber(String input) { - String[] stringArray = input.split(","); - List integerList = new ArrayList<>(); - for (String str : stringArray) { - int num = Integer.parseInt(str); - integerList.add(num); - } - this.number = new Lotto(integerList); - } -} \ No newline at end of file From 685452486652498df425db30f607e0157b8e1aa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Tue, 18 Jul 2023 13:32:00 +0900 Subject: [PATCH 27/32] feat (GameController) : add GameController --- src/main/java/lotto/GameController.java | 88 +++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/main/java/lotto/GameController.java diff --git a/src/main/java/lotto/GameController.java b/src/main/java/lotto/GameController.java new file mode 100644 index 0000000000..93dd0f9272 --- /dev/null +++ b/src/main/java/lotto/GameController.java @@ -0,0 +1,88 @@ +package lotto; + +import camp.nextstep.edu.missionutils.Console; + +import java.util.ArrayList; +import java.util.List; + +public class GameController { + + private final LottoManager lottoManager; + + public GameController(LottoManager lottoManager) { + this.lottoManager = lottoManager; + } + + public void play() { + System.out.println(Message.Input.PURCHASE_MONEY); + int money = readMoney(); + + int quantity = money / Number.Rule.PRICE.toNumber(); + List myLottoSet = new ArrayList<>(); + for (int i = 0; i < quantity; i++) { + Lotto lottoOneSet = lottoManager.generate(Number.Rule.MIN.toNumber(), Number.Rule.MAX.toNumber(), Number.Rule.SIZE.toNumber()); + myLottoSet.add(lottoOneSet); + } + + System.out.println(Message.Output.PURCHASE_QUANTITY.toQuantityFormat(quantity)); + for (Lotto lotto : myLottoSet) { + System.out.println(lotto.getNumbers()); + } + + System.out.println(Message.Input.WINNER_NUMBER); + Lotto winnerNumber = readNumber(); + int bonusNumber = readBonus(); + + Score score = lottoManager.calculate(myLottoSet, winnerNumber, bonusNumber); + System.out.println(Message.Output.RESULT_STAT); + System.out.println(score); + System.out.println(Message.Output.RESULT_RATE.toRateFormat(score.calculateRate(money))); + } + + private int readMoney() { + String input = Console.readLine(); + for (char c : input.toCharArray()) { + if (c < '0' || c > '9') { + throw new IllegalArgumentException(Message.Error.PURCHASE_AMOUNT.toString()); + } + } + int purchaseMoney = Integer.parseInt(input); + if (purchaseMoney % Number.Rule.PRICE.toNumber() != 0) { + throw new IllegalArgumentException(Message.Error.PURCHASE_AMOUNT.toString()); + } + return Integer.parseInt(input); + } + + private Lotto readNumber() { + String input = Console.readLine(); + try { + String[] stringArray = input.split(","); + for (String str : stringArray) { + int num = Integer.parseInt(str); + } + } catch (Exception e) { + throw new IllegalArgumentException(Message.Error.LOTTO_NUMBER.toString()); + } + String[] stringArray = input.split(","); + List integerList = new ArrayList<>(); + for (String str : stringArray) { + int num = Integer.parseInt(str); + integerList.add(num); + } + return new Lotto(integerList); + } + + private int readBonus() { + String input = Console.readLine(); + try { + Integer.parseInt(input); + } catch (NumberFormatException e) { + throw new IllegalArgumentException(Message.Error.BONUS_NUMBER.toString()); + } + int bonusNumber = Integer.parseInt(input); + if (bonusNumber < Number.Rule.MIN.toNumber() || bonusNumber > Number.Rule.MAX.toNumber()) { + throw new IllegalArgumentException(Message.Error.BONUS_NUMBER.toString()); + } + return bonusNumber; + } +} \ No newline at end of file From b8937d247294b2e741cb55485322b4133e0fae4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Tue, 18 Jul 2023 13:32:26 +0900 Subject: [PATCH 28/32] feat (LottoManager) : move code to GameController --- src/main/java/lotto/LottoManager.java | 153 +++++++------------------- 1 file changed, 38 insertions(+), 115 deletions(-) diff --git a/src/main/java/lotto/LottoManager.java b/src/main/java/lotto/LottoManager.java index be6f032578..015b911e54 100644 --- a/src/main/java/lotto/LottoManager.java +++ b/src/main/java/lotto/LottoManager.java @@ -1,133 +1,56 @@ package lotto; -import camp.nextstep.edu.missionutils.Console; import camp.nextstep.edu.missionutils.Randoms; import java.util.ArrayList; import java.util.List; public class LottoManager { - private MyLottoData myLotto; - private WinnerLottoData winnerLotto; - private ResultLottoData resultLotto; - - public LottoManager() { - myLotto = new MyLottoData(); - winnerLotto = new WinnerLottoData(); - resultLotto = new ResultLottoData(); - } - - public void play() { - inputPurchaingMoney(); - issueLottoMultiSet(); - printPurchasedLotto(); - inputWinnerNumber(); - inputBonusNumber(); - calculateResultLotto(); - printResultLotto(); - } - - private void inputPurchaingMoney() { - System.out.println(Message.Input.PURCHASE_MONEY); - String input = Console.readLine(); - validatePurchaseMoney(input); - int money = Integer.parseInt(input); - myLotto.money = money; - } - - private void issueLottoMultiSet() { - myLotto.quantity = myLotto.money / Number.Rule.PRICE.toNumber(); - while(myLotto.lottoSet.size() < myLotto.quantity) { - List lottoOneList = Randoms.pickUniqueNumbersInRange(Number.Rule.MIN.toNumber(), Number.Rule.MAX.toNumber(), Number.Rule.SIZE.toNumber()); - Lotto lottoOneSet = new Lotto(lottoOneList); - myLotto.lottoSet.add(lottoOneSet); - } - } - - private void printPurchasedLotto() { - System.out.println(Message.Output.PURCHASE_QUANTITY.toQuantityFormat(myLotto.quantity)); - for(Lotto lotto : myLotto.lottoSet) { - System.out.println(lotto.getNumbers()); - } - } - - private void inputWinnerNumber() { - System.out.println(Message.Input.WINNER_NUMBER); - String winnerString = Console.readLine(); - validateWinnerString(winnerString); - winnerLotto.parseWinnerNumber(winnerString); - } - - private void inputBonusNumber() { - System.out.println(Message.Input.BONUS_NUMBER); - String bonusNumber = Console.readLine(); - validateBonusNumber(bonusNumber); - winnerLotto.bonusNumber = Integer.parseInt(bonusNumber); - } - - private void calculateResultLotto() { - for (Lotto lottoOneSet : myLotto.lottoSet) { - int matchCount = countNumberOfLottoMatches(lottoOneSet); - boolean isBonusMatch = isMatchWithBonusNumber(lottoOneSet); - resultLotto.update(matchCount, isBonusMatch); + public Lotto generate(int min, int max, int size) { + List lottoOneList = Randoms.pickUniqueNumbersInRange(min, max, size); + return new Lotto(lottoOneList); + } + + public Score calculate(List myLottoSet, Lotto winnerLotto, int bonusNumber) { + int threeMatchCount = 0; + int fourMatchCount = 0; + int fiveMatchCount = 0; + int fiveAndBonusMatchCount = 0; + int sixMatchCount = 0; + for (Lotto myLottoOneSet : myLottoSet) { + int matchCount = countNumberOfLottoMatches(myLottoOneSet, winnerLotto); + boolean isBonusMatch = myLottoOneSet.getNumbers().contains(bonusNumber); + if (matchCount == 3) { + threeMatchCount++; + continue; + } + if (matchCount == 4) { + fourMatchCount++; + continue; + } + if (matchCount == 5) { + if (isBonusMatch) { + fiveAndBonusMatchCount++; + continue; + } + fiveMatchCount++; + continue; + } + if (matchCount == 6) { + sixMatchCount++; + } } - resultLotto.calculateProfit(); - resultLotto.calculateRate(myLotto.money); + return new Score(threeMatchCount, fourMatchCount, fiveMatchCount, + fiveAndBonusMatchCount, sixMatchCount); } - private int countNumberOfLottoMatches(Lotto lottoOneSet) { + private int countNumberOfLottoMatches(Lotto myLottoOneSet, Lotto winnerLotto) { int matchCount = 0; - for (int number : lottoOneSet.getNumbers()) { - if (winnerLotto.number.getNumbers().contains(number)) { + for (int number : myLottoOneSet.getNumbers()) { + if (winnerLotto.getNumbers().contains(number)) { matchCount++; } } return matchCount; } - - private boolean isMatchWithBonusNumber(Lotto lottoOneSet) { - return lottoOneSet.getNumbers().contains(winnerLotto.bonusNumber); - } - - private void printResultLotto() { - System.out.println(Message.Output.RESULT_STAT); - System.out.println(Message.Output.RESULT_CONTENTS.toContentsFormat(resultLotto)); - System.out.println(Message.Output.RESULT_RATE.toRateFormat(resultLotto.rate)); - } - - private void validatePurchaseMoney(String input) throws IllegalArgumentException { - for(char c : input.toCharArray()) { - if(c < '0' || c > '9') { - throw new IllegalArgumentException(Message.Error.PURCHASE_AMOUNT.toErrorFormat()); - } - } - int purchaseMoney = Integer.parseInt(input); - if(purchaseMoney % Number.Rule.PRICE.toNumber() != 0) { - throw new IllegalArgumentException(Message.Error.PURCHASE_AMOUNT.toErrorFormat()); - } - } - - private void validateWinnerString(String input) { - try { - String[] stringArray = input.split(","); - for (String str : stringArray) { - int num = Integer.parseInt(str); - } - } catch (Exception e) { - throw new IllegalArgumentException(Message.Error.LOTTO_NUMBER.toErrorFormat()); - } - } - - private void validateBonusNumber(String input) { - try { - Integer.parseInt(input); - } catch (NumberFormatException e) { - throw new IllegalArgumentException(Message.Error.BONUS_NUMBER.toErrorFormat()); - } - - int bonusNumber = Integer.parseInt(input); - if(bonusNumber < Number.Rule.MIN.toNumber() || bonusNumber > Number.Rule.MAX.toNumber()) { - throw new IllegalArgumentException(Message.Error.BONUS_NUMBER.toErrorFormat()); - } - } } From c66fc000fb6a408b2924511beb9332a7bf1925ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Tue, 18 Jul 2023 13:32:42 +0900 Subject: [PATCH 29/32] feat (Score) : add Score --- src/main/java/lotto/Score.java | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/lotto/Score.java diff --git a/src/main/java/lotto/Score.java b/src/main/java/lotto/Score.java new file mode 100644 index 0000000000..19ce4b3b75 --- /dev/null +++ b/src/main/java/lotto/Score.java @@ -0,0 +1,34 @@ +package lotto; + +public class Score { + private final int threeMatchCount, fourMatchCount, fiveMatchCount, fiveAndBonusMatchCount, sixMatchCount; + + public Score(int threeMatchCount, int fourMatchCount, + int fiveMatchCount, int fiveAndBonusMatchCount, int sixMatchCount) { + this.threeMatchCount = threeMatchCount; + this.fourMatchCount = fourMatchCount; + this.fiveMatchCount = fiveMatchCount; + this.fiveAndBonusMatchCount = fiveAndBonusMatchCount; + this.sixMatchCount = sixMatchCount; + } + + public double calculateRate(int purchaseMoney) { + double money = purchaseMoney; + int totalProfit = threeMatchCount * Number.Prize.THREE_MATCH.toNumber() + + fourMatchCount * Number.Prize.FOUR_MATCH.toNumber() + + fiveMatchCount * Number.Prize.FIVE_MATCH.toNumber() + + fiveAndBonusMatchCount * Number.Prize.FIVE_BONUS_MATCH.toNumber() + + sixMatchCount * Number.Prize.SIX_MATCH.toNumber(); + return (totalProfit / money) * 100.0; + } + + @Override + public String toString() { + return String.format(Message.Output.RESULT_CONTENTS.toString(), + Number.Prize.THREE_MATCH.toDecimalFormat(), threeMatchCount, + Number.Prize.FOUR_MATCH.toDecimalFormat(), fourMatchCount, + Number.Prize.FIVE_MATCH.toDecimalFormat(), fiveMatchCount, + Number.Prize.FIVE_BONUS_MATCH.toDecimalFormat(), fiveAndBonusMatchCount, + Number.Prize.SIX_MATCH.toDecimalFormat(), sixMatchCount); + } +} From 92d4d50a80ef0308bec0c94fc928d666e77ec1e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Tue, 18 Jul 2023 13:33:03 +0900 Subject: [PATCH 30/32] feat (Message) : update Message function --- src/main/java/lotto/Message.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/main/java/lotto/Message.java b/src/main/java/lotto/Message.java index 1dd503b986..76d44b903b 100644 --- a/src/main/java/lotto/Message.java +++ b/src/main/java/lotto/Message.java @@ -32,6 +32,7 @@ public enum Output { 6๊ฐœ ์ผ์น˜ (%s์›) - %d๊ฐœ"""); private final String outputMessage; + Output(String message) { outputMessage = message; } @@ -46,15 +47,6 @@ public String toRateFormat(double rate) { return String.format(outputMessage, roundedNumber); } - public String toContentsFormat(ResultLottoData resultData) { - return String.format(outputMessage, - Number.Prize.THREE_MATCH.toDecimalFormat(), resultData.threeMatchCount, - Number.Prize.FOUR_MATCH.toDecimalFormat(), resultData.fourMatchCount, - Number.Prize.FIVE_MATCH.toDecimalFormat(), resultData.fiveMatchCount, - Number.Prize.FIVE_BONUS_MATCH.toDecimalFormat(), resultData.fiveAndBonusMatchCount, - Number.Prize.SIX_MATCH.toDecimalFormat(), resultData.sixMatchCount); - } - @Override public String toString() { return outputMessage; @@ -72,7 +64,8 @@ public enum Error { this.errorMessage = input; } - public String toErrorFormat() { + @Override + public String toString() { return "[ERROR] " + errorMessage; } } From 285e4b9246cdfeef8ccbd4ffad6f02492733b4a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Tue, 18 Jul 2023 13:33:35 +0900 Subject: [PATCH 31/32] feat (Application) : make gamecontroller object in application file --- src/main/java/lotto/Application.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java index 9ee6db8b64..de3822f8d5 100644 --- a/src/main/java/lotto/Application.java +++ b/src/main/java/lotto/Application.java @@ -3,6 +3,7 @@ public class Application { public static void main(String[] args) { LottoManager lottoManager = new LottoManager(); - lottoManager.play(); + GameController game = new GameController(lottoManager); + game.play(); } } \ No newline at end of file From 71e93caf4017bb750dce61ac1daf05a4dc3b7401 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=AE=E1=84=86?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Tue, 18 Jul 2023 13:37:23 +0900 Subject: [PATCH 32/32] chore(lotto) : update code newline --- src/main/java/lotto/GameController.java | 6 ++++-- src/main/java/lotto/LottoManager.java | 4 ++-- src/main/java/lotto/Score.java | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/lotto/GameController.java b/src/main/java/lotto/GameController.java index 93dd0f9272..de6d002f9f 100644 --- a/src/main/java/lotto/GameController.java +++ b/src/main/java/lotto/GameController.java @@ -20,7 +20,8 @@ public void play() { int quantity = money / Number.Rule.PRICE.toNumber(); List myLottoSet = new ArrayList<>(); for (int i = 0; i < quantity; i++) { - Lotto lottoOneSet = lottoManager.generate(Number.Rule.MIN.toNumber(), Number.Rule.MAX.toNumber(), Number.Rule.SIZE.toNumber()); + Lotto lottoOneSet = lottoManager.generate(Number.Rule.MIN.toNumber(), + Number.Rule.MAX.toNumber(), Number.Rule.SIZE.toNumber()); myLottoSet.add(lottoOneSet); } @@ -34,9 +35,10 @@ public void play() { int bonusNumber = readBonus(); Score score = lottoManager.calculate(myLottoSet, winnerNumber, bonusNumber); + double rate = score.calculateRate(money); System.out.println(Message.Output.RESULT_STAT); System.out.println(score); - System.out.println(Message.Output.RESULT_RATE.toRateFormat(score.calculateRate(money))); + System.out.println(Message.Output.RESULT_RATE.toRateFormat(rate)); } private int readMoney() { diff --git a/src/main/java/lotto/LottoManager.java b/src/main/java/lotto/LottoManager.java index 015b911e54..a0dec31427 100644 --- a/src/main/java/lotto/LottoManager.java +++ b/src/main/java/lotto/LottoManager.java @@ -40,8 +40,8 @@ public Score calculate(List myLottoSet, Lotto winnerLotto, int bonusNumbe sixMatchCount++; } } - return new Score(threeMatchCount, fourMatchCount, fiveMatchCount, - fiveAndBonusMatchCount, sixMatchCount); + return new Score(threeMatchCount, fourMatchCount, + fiveMatchCount, fiveAndBonusMatchCount, sixMatchCount); } private int countNumberOfLottoMatches(Lotto myLottoOneSet, Lotto winnerLotto) { diff --git a/src/main/java/lotto/Score.java b/src/main/java/lotto/Score.java index 19ce4b3b75..4b49a835f4 100644 --- a/src/main/java/lotto/Score.java +++ b/src/main/java/lotto/Score.java @@ -1,7 +1,8 @@ package lotto; public class Score { - private final int threeMatchCount, fourMatchCount, fiveMatchCount, fiveAndBonusMatchCount, sixMatchCount; + private final int threeMatchCount, fourMatchCount, + fiveMatchCount, fiveAndBonusMatchCount, sixMatchCount; public Score(int threeMatchCount, int fourMatchCount, int fiveMatchCount, int fiveAndBonusMatchCount, int sixMatchCount) {