diff --git a/README.md b/README.md index 81b03cdba2..208116daa2 100644 --- a/README.md +++ b/README.md @@ -1,207 +1,63 @@ -# ๊ณผ์ œ - ๋กœ๋˜ +# Lotto -## ๐Ÿ” ์ง„ํ–‰ ๋ฐฉ์‹ +1. Lotto ์ƒ˜ํ”Œ์„ ๋ณต์‚ฌํ•ด์˜จ๋‹ค. +2. ์šฐ์Šน ๋ณต๊ถŒ๊ณผ ๋น„๊ตํ•˜์—ฌ ๋ช‡๊ฐœ์˜ ์ˆซ์ž๊ฐ€ ๋งž์•˜๋Š”์ง€ ํ™•์ธํ•˜๋Š” ๋กœ์ง์„ ๋งŒ๋“ ๋‹ค. +3. ๋ณด๋„ˆ์Šค๊ฐ€ ์ผ์น˜ํ•˜๋Š”์ง€๋ฅผ ํ™•์ธํ•˜๋Š” ๋กœ์ง์„ ๋งŒ๋“ ๋‹ค. +4. Lotto์˜ ๊ฐ’์„ ์ถœ๋ ฅํ•˜๋Š” ๋กœ์ง์„ ๊ตฌํ˜„. -- ๊ณผ์ œ๋Š” **๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ, ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ, ๊ณผ์ œ ์ง„ํ–‰ ์š”๊ตฌ ์‚ฌํ•ญ** ์„ธ ๊ฐ€์ง€๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค. -- ์„ธ ๊ฐœ์˜ ์š”๊ตฌ ์‚ฌํ•ญ์„ ๋งŒ์กฑํ•˜๊ธฐ ์œ„ํ•ด ๋…ธ๋ ฅํ•œ๋‹ค. ํŠนํžˆ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์ „์— ๊ธฐ๋Šฅ ๋ชฉ๋ก์„ ๋งŒ๋“ค๊ณ , ๊ธฐ๋Šฅ ๋‹จ์œ„๋กœ ์ปค๋ฐ‹ ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ง„ํ–‰ํ•œ๋‹ค. -- ๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ์— ๊ธฐ์žฌ๋˜์ง€ ์•Š์€ ๋‚ด์šฉ์€ ์Šค์Šค๋กœ ํŒ๋‹จํ•˜์—ฌ ๊ตฌํ˜„ํ•œ๋‹ค. +# WinningLotto ---- +1. ์šฐ์Šน ๋ณต๊ถŒ์˜ ์ •๋ณด๋ฅผ ์ €์žฅํ•œ๋‹ค. +2. ์—ฌ๊ธฐ์—” Lotto์˜ ๊ฐ์ฒด์™€, bonus ์ •๋ณด๋ฅผ ์ €์žฅํ•œ๋‹ค. -## ๐Ÿ“ˆ ๊ณผ์ œ ์ง„ํ–‰ ๋ฐ ์ œ์ถœ ๋ฐฉ๋ฒ• +# ENUM -- ๊ณผ์ œ๋Š” [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 ์ƒ์„ฑํ•˜๋ฉด๋จ +1. Lotto์— ๋Œ€ํ•œ ์ƒ์ˆ˜๊ฐ’๋“ค์„ ์ •์˜ํ•˜๋Š” class RandomRange ์ƒ์„ฑ +2. ์ƒ๊ธˆ์— ๋Œ€ํ•œ ์ƒ์ˆ˜๊ฐ’๋“ค์„ ์ •์˜ํ•˜๋Š” class Prize ์ƒ์„ฑ -
+# CheckException -### ํ…Œ์ŠคํŠธ ์‹คํ–‰ ๊ฐ€์ด๋“œ +1. winningLotto๋ฅผ ์ž…๋ ฅ๋ฐ›์„๋•Œ, ์ž˜๋ชป ๋ฐ›๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ์œ„ํ•œ ์ธํ„ฐํŽ˜์ด์Šค -- ํ„ฐ๋ฏธ๋„์—์„œ `java -version`์„ ์‹คํ–‰ํ•˜์—ฌ Java ๋ฒ„์ „์ด 14์ธ์ง€ ํ™•์ธํ•œ๋‹ค. ๋˜๋Š” Eclipse ๋˜๋Š” IntelliJ IDEA์™€ ๊ฐ™์€ IDE์—์„œ Java 14๋กœ ์‹คํ–‰๋˜๋Š”์ง€ ํ™•์ธํ•œ๋‹ค. -- ํ„ฐ๋ฏธ๋„์—์„œ Mac ๋˜๋Š” Linux ์‚ฌ์šฉ์ž์˜ ๊ฒฝ์šฐ `./gradlew clean test` ๋ช…๋ น์„ ์‹คํ–‰ ํ•˜๊ณ , - Windows ์‚ฌ์šฉ์ž์˜ ๊ฒฝ์šฐ `gradlew.bat clean test` ๋ช…๋ น์„ ์‹คํ–‰ํ•  ๋•Œ ๋™์ž‘ ํ•˜๋Š”์ง€ ๋งŒ ํ™•์ธ(ํ…Œ์ŠคํŠธ๋Š” ์‹คํŒจ). +# CheckExceptionImpl ---- +1. CheckException์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌํ˜„ํ•œ ํด๋ž˜์Šค -## ๐Ÿš€ ๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ +# BuyMoney -๋กœ๋˜ ๊ฒŒ์ž„ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•ด์•ผ ํ•œ๋‹ค. ๋กœ๋˜ ๊ฒŒ์ž„์€ ์•„๋ž˜์™€ ๊ฐ™์€ ๊ทœ์น™์œผ๋กœ ์ง„ํ–‰๋œ๋‹ค. +1. ๊ตฌ๋งค ๊ธˆ์•ก์„ ์ž…๋ ฅ๋ฐ›๊ณ , ํ˜•์‹์„ ๊ฒ€์ฆํ•œ๋‹ค. +2. ๊ธˆ์•ก์ด ์ž…๋ ฅ๋˜๋ฉด ๊ธˆ์•ก์œผ๋กœ ๋ช‡์žฅ์„ ๊ตฌ๋งคํ–ˆ๋Š”์ง€ ์ถœ๋ ฅํ•œ๋‹ค. -``` -- ๋กœ๋˜ ๋ฒˆํ˜ธ์˜ ์ˆซ์ž ๋ฒ”์œ„๋Š” 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์› -``` +# InputWinningLotto -- ๋กœ๋˜ ๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅํ•˜๋ฉด ๊ตฌ์ž… ๊ธˆ์•ก์— ํ•ด๋‹นํ•˜๋Š” ๋งŒํผ ๋กœ๋˜๋ฅผ ๋ฐœํ–‰ํ•ด์•ผ ํ•œ๋‹ค. -- ๋กœ๋˜ 1์žฅ์˜ ๊ฐ€๊ฒฉ์€ 1,000์›์ด๋‹ค. -- ๋‹น์ฒจ ๋ฒˆํ˜ธ์™€ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. -- ์‚ฌ์šฉ์ž๊ฐ€ ๊ตฌ๋งคํ•œ ๋กœ๋˜ ๋ฒˆํ˜ธ์™€ ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ๋น„๊ตํ•˜์—ฌ ๋‹น์ฒจ ๋‚ด์—ญ ๋ฐ ์ˆ˜์ต๋ฅ ์„ ์ถœ๋ ฅํ•˜๊ณ  ๋กœ๋˜ ๊ฒŒ์ž„์„ ์ข…๋ฃŒํ•œ๋‹ค. -- ์‚ฌ์šฉ์ž๊ฐ€ ์ž˜๋ชป๋œ ๊ฐ’์„ ์ž…๋ ฅํ•  ๊ฒฝ์šฐ `IllegalArgumentException`๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๊ณ , "[ERROR]"๋กœ ์‹œ์ž‘ํ•˜๋Š” ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅ ํ›„ ์ข…๋ฃŒํ•œ๋‹ค. +1. ์šฐ์Šน ๋กœ๋˜๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. +2. CheckException์œผ๋กœ ์˜ค๋ฅ˜๋ฅผ ํ™•์ธํ•œ๋‹ค. -## โœ๐Ÿป ์ž…์ถœ๋ ฅ ์š”๊ตฌ์‚ฌํ•ญ +# Rank + +1. lotto์™€ win lotto๋ฅผ ์ „๋‹ฌ๋ฐ›์•„์„œ ๋ช‡๊ฐœ๊ฐ€ match์ธ์ง€, bonus๊ฐ€ ๋งž์•˜๋Š”์ง€๋ฅผ ํ™•์ธํ•œ๋‹ค. + +## rankValue() + +1. 1~5๋“ฑ๊นŒ์ง€ ํ•ด๋‹นํ•˜๋Š” ํšŸ์ˆ˜๋ฅผ ์ฆ๊ฐ€์‹œํ‚จ๋‹ค. + +# EarnMoney + +## addMoney() + +1. ๋‹น์ฒจ๋œ ๊ธˆ์•ก๋งŒํผ ํ˜„์žฌ ์†Œ์ง€๊ธˆ์„ ์ฆ๊ฐ€์‹œํ‚จ๋‹ค. + +# PrintCorrectCount + +## print() + +1. ๊ฐ๊ฐ์˜ ๋“ฑ์ˆ˜๋ณ„๋กœ ๋ช‡ํšŒ ๋‹น์ฒจ๋˜์—ˆ๋Š”์ง€ ์ถœ๋ ฅํ•œ๋‹ค. +2. ์ด ์ˆ˜์ต๋ฅ ์„ ์ถœ๋ ฅํ•œ๋‹ค. + +# Game, LottoGame +1. Game์€ ๋‹จ์ˆœํ•œ ์ธํ„ฐํŽ˜์ด์Šค +2. LottoGame ์— Game์„ ๊ตฌํ˜„ +3. LottoGame์—์„œ ๊ฒŒ์ž„ ๋กœ์ง ์ง„ํ–‰. -### โŒจ๏ธ ์ž…๋ ฅ -- ๋กœ๋˜ ๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅ ๋ฐ›๋Š”๋‹ค. ๊ตฌ์ž… ๊ธˆ์•ก์€ 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: ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ -} -``` diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java index 367ee30584..f39a21e1fc 100644 --- a/src/main/java/lotto/Application.java +++ b/src/main/java/lotto/Application.java @@ -1,7 +1,12 @@ package lotto; +import lotto.game.Game; +import lotto.game.LottoGame; + public class Application { public static void main(String[] args) { // TODO: ํ”„๋กœ๊ทธ๋žจ ๊ตฌํ˜„ + Game lottoGame = new LottoGame(); + lottoGame.play(); } } \ No newline at end of file diff --git a/src/main/java/lotto/checkexception/CheckCharException.java b/src/main/java/lotto/checkexception/CheckCharException.java new file mode 100644 index 0000000000..59d27d8254 --- /dev/null +++ b/src/main/java/lotto/checkexception/CheckCharException.java @@ -0,0 +1,12 @@ +package lotto.checkexception; + +public class CheckCharException { + public void checkCharException(String input){ + for(int i = 0; i < input.length(); i++){ + if(input.charAt(i) >= '0' && input.charAt(i) <= '9'){ + continue; + } + throw new IllegalArgumentException("[ERROR]์ˆซ์ž๋งŒ ์ž…๋ ฅํ•˜์„ธ์š”."); + } + } +} diff --git a/src/main/java/lotto/checkexception/CheckException.java b/src/main/java/lotto/checkexception/CheckException.java new file mode 100644 index 0000000000..6cf946da14 --- /dev/null +++ b/src/main/java/lotto/checkexception/CheckException.java @@ -0,0 +1,5 @@ +package lotto.checkexception; + +public interface CheckException { + void checkException(int check); +} diff --git a/src/main/java/lotto/checkexception/CheckExceptionImpl.java b/src/main/java/lotto/checkexception/CheckExceptionImpl.java new file mode 100644 index 0000000000..9eb8a033a4 --- /dev/null +++ b/src/main/java/lotto/checkexception/CheckExceptionImpl.java @@ -0,0 +1,12 @@ +package lotto.checkexception; + +import lotto.numbers.RandomRange; + +public class CheckExceptionImpl implements CheckException{ + public void checkException(int check) { + if (check > RandomRange.MAX_VALUE.getValue() || check < RandomRange.MIN_VALUE.getValue()) { + throw new IllegalArgumentException("[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 1๋ถ€ํ„ฐ 45 ์‚ฌ์ด์˜ ์ˆซ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."); + } + } + +} diff --git a/src/main/java/lotto/game/Game.java b/src/main/java/lotto/game/Game.java new file mode 100644 index 0000000000..df7b6c0384 --- /dev/null +++ b/src/main/java/lotto/game/Game.java @@ -0,0 +1,5 @@ +package lotto.game; + +public interface Game { + public void play(); +} diff --git a/src/main/java/lotto/game/InputWinLotto.java b/src/main/java/lotto/game/InputWinLotto.java new file mode 100644 index 0000000000..f0876ecfc3 --- /dev/null +++ b/src/main/java/lotto/game/InputWinLotto.java @@ -0,0 +1,47 @@ +package lotto.game; + +import camp.nextstep.edu.missionutils.Console; +import lotto.checkexception.CheckCharException; +import lotto.lotto.Lotto; +import lotto.lotto.WinningLotto; +import lotto.checkexception.CheckException; +import lotto.checkexception.CheckExceptionImpl; +import lotto.numbers.RandomRange; + +import java.util.ArrayList; +import java.util.List; + +public class InputWinLotto { + private final WinningLotto winningLotto; + private final Lotto lotto; + + public InputWinLotto(){ + System.out.println("๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + String input = Console.readLine().toString(); + String[] words = input.split(","); + List list = new ArrayList<>(); + CheckException checkException = new CheckExceptionImpl(); + CheckCharException checkCharException = new CheckCharException(); + for (String word : words) { + checkCharException.checkCharException(word); + int check = Integer.parseInt(word); + checkException.checkException(check); + if(list.contains(check)) throw new IllegalArgumentException("[ERROR]๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” ์ค‘๋ณต๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); + list.add(check); + } + if(list.size() != RandomRange.SIZE.getValue()) throw new IllegalArgumentException("[ERROR]์ˆซ์ž 6๊ฐœ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”."); + + lotto = new Lotto(list); + System.out.println("๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + String inputBonus = Console.readLine(); + checkCharException.checkCharException(inputBonus); + int bonus = Integer.parseInt(inputBonus); + checkException.checkException(bonus); + if(list.contains(bonus)) throw new IllegalArgumentException("[ERROR]๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” ์ค‘๋ณต๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."); + winningLotto = new WinningLotto(lotto,bonus); + } + + public WinningLotto getWinningLotto() { + return winningLotto; + } +} diff --git a/src/main/java/lotto/game/LottoGame.java b/src/main/java/lotto/game/LottoGame.java new file mode 100644 index 0000000000..e9062db9bf --- /dev/null +++ b/src/main/java/lotto/game/LottoGame.java @@ -0,0 +1,57 @@ +package lotto.game; + +import camp.nextstep.edu.missionutils.Randoms; +import lotto.lotto.Lotto; +import lotto.game.money.BuyMoney; +import lotto.game.money.EarnMoney; +import lotto.numbers.RandomRange; + +import java.util.ArrayList; +import java.util.List; + +public class LottoGame implements Game{ + + private int [] prize = {0,0,0,0,0,0}; + public LottoGame(){ + + } + @Override + public void play() { + try { + BuyMoney buyMoney = new BuyMoney(); + int count = buyMoney.getBuyCount(); + List lottoList = new ArrayList<>(); + makeNewLottoList(count, lottoList); + for (Lotto lotto : lottoList) { + lotto.printValues(); + } + InputWinLotto inputWinLotto = new InputWinLotto(); + + for (Lotto lotto : lottoList) { + Rank rank = new Rank(lotto, inputWinLotto.getWinningLotto()); + rank.rankValue(prize); + } + EarnMoney earnMoney = new EarnMoney(); + earnMoney.addMoney(prize); + + + PrintCorrectCount printCorrectCount = new PrintCorrectCount(prize); + printCorrectCount.print(calculateRate(buyMoney, earnMoney)); + }catch(IllegalArgumentException e){ + System.out.println(e.getMessage()); + } + + } + + private static double calculateRate(BuyMoney buyMoney, EarnMoney earnMoney) { + double result = (double)earnMoney.getEarnMoney() / (double)buyMoney.getBuyMoney() * 100; + return Double.parseDouble(String.format("%.1f",result)); + } + + private static void makeNewLottoList(int count, List lottoList) { + for(int i = 0; i < count; i++){ + List ranNum = Randoms.pickUniqueNumbersInRange(RandomRange.MIN_VALUE.getValue(), RandomRange.MAX_VALUE.getValue(),RandomRange.SIZE.getValue()); + lottoList.add(new Lotto(ranNum)); + } + } +} diff --git a/src/main/java/lotto/game/PrintCorrectCount.java b/src/main/java/lotto/game/PrintCorrectCount.java new file mode 100644 index 0000000000..fcba8d1818 --- /dev/null +++ b/src/main/java/lotto/game/PrintCorrectCount.java @@ -0,0 +1,20 @@ +package lotto.game; + +public class PrintCorrectCount { + private final int[] prize; + + public PrintCorrectCount(int [] prizeParam){ + prize = prizeParam; + } + + public void print(double temp){ + System.out.println("3๊ฐœ ์ผ์น˜ (5,000์›) - " + prize[5]+ "๊ฐœ\n" + + "4๊ฐœ ์ผ์น˜ (50,000์›) - " + prize[4]+ "๊ฐœ\n" + + "5๊ฐœ ์ผ์น˜ (1,500,000์›) - " + prize[3]+ "๊ฐœ\n"+ + "5๊ฐœ ์ผ์น˜, ๋ณด๋„ˆ์Šค ๋ณผ ์ผ์น˜ (30,000,000์›) - " + prize[2]+ "๊ฐœ\n" + + "6๊ฐœ ์ผ์น˜ (2,000,000,000์›) - " + prize[1]+ "๊ฐœ\n" + + "์ด ์ˆ˜์ต๋ฅ ์€ " + temp + "%์ž…๋‹ˆ๋‹ค." + ); + + } +} diff --git a/src/main/java/lotto/game/Rank.java b/src/main/java/lotto/game/Rank.java new file mode 100644 index 0000000000..880d88ba83 --- /dev/null +++ b/src/main/java/lotto/game/Rank.java @@ -0,0 +1,32 @@ +package lotto.game; + +import lotto.lotto.Lotto; +import lotto.lotto.WinningLotto; + +public class Rank { + private final int count; + private final boolean isBonus; + Rank(Lotto lotto, WinningLotto winLotto){ + count = lotto.countMatch(winLotto); + isBonus = lotto.isBonus(winLotto); + } + + public void rankValue(int [] arr) { + if(count == 3) { + arr[5]++; + } + else if(count == 4) { + arr[4]++; + } + else if(count == 5 && !isBonus) { + arr[3]++; + } + else if(count == 5 && isBonus) { + arr[2]++; + } + else if(count == 6) { + arr[1]++; + } + } + +} diff --git a/src/main/java/lotto/game/money/BuyMoney.java b/src/main/java/lotto/game/money/BuyMoney.java new file mode 100644 index 0000000000..2c5053118c --- /dev/null +++ b/src/main/java/lotto/game/money/BuyMoney.java @@ -0,0 +1,31 @@ +package lotto.game.money; + +import camp.nextstep.edu.missionutils.Console; +import lotto.checkexception.CheckCharException; + +public class BuyMoney { + private final int buyMoney; + private final int buyCount; + private final String inputBuyMoney; + public BuyMoney(){ + System.out.println("๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + inputBuyMoney = Console.readLine(); + CheckCharException checkCharException = new CheckCharException(); + checkCharException.checkCharException(inputBuyMoney); + buyMoney = Integer.parseInt(inputBuyMoney); + if(buyMoney % 1000 != 0){ + throw new IllegalArgumentException("[ERROR]1000์› ๋‹จ์œ„๋กœ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."); + } + + buyCount = buyMoney / 1000; + System.out.println(buyCount + "๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค."); + } + + public int getBuyMoney() { + return buyMoney; + } + public int getBuyCount(){ + return buyCount; + } + +} diff --git a/src/main/java/lotto/game/money/EarnMoney.java b/src/main/java/lotto/game/money/EarnMoney.java new file mode 100644 index 0000000000..478487e70a --- /dev/null +++ b/src/main/java/lotto/game/money/EarnMoney.java @@ -0,0 +1,22 @@ +package lotto.game.money; + +import lotto.numbers.Prize; + +public class EarnMoney { + private long earnMoney; + public EarnMoney(){ + earnMoney = 0; + } + + public void addMoney(int[] prizeParam){ + earnMoney += Prize.FIRST.getValue() * prizeParam[1]; + earnMoney += Prize.SECOND.getValue()* prizeParam[2]; + earnMoney += Prize.THIRD.getValue()* prizeParam[3]; + earnMoney += Prize.FOURTH.getValue()* prizeParam[4]; + earnMoney += Prize.FIFTH.getValue()* prizeParam[5]; + } + + public long getEarnMoney() { + return earnMoney; + } +} diff --git a/src/main/java/lotto/lotto/Lotto.java b/src/main/java/lotto/lotto/Lotto.java new file mode 100644 index 0000000000..7699dcc7ee --- /dev/null +++ b/src/main/java/lotto/lotto/Lotto.java @@ -0,0 +1,42 @@ +package lotto.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(); + } + } + + // TODO: ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ + public int countMatch(WinningLotto lotto){ + int count = 0; + for (Integer number : this.numbers) { + if(lotto.getLotto().numbers.contains(number)) count++; + } + return count; + } + + public boolean isBonus(WinningLotto lotto){ + return this.numbers.contains(lotto.getBonus()); + } + + public void printValues(){ + String str = "["; + for (Integer number : numbers) { + str += number.toString(); + str += ", "; + } + str = str.substring(0, str.length() - 2); + str += "]"; + System.out.println(str); + } +} \ No newline at end of file diff --git a/src/main/java/lotto/lotto/WinningLotto.java b/src/main/java/lotto/lotto/WinningLotto.java new file mode 100644 index 0000000000..6676752f00 --- /dev/null +++ b/src/main/java/lotto/lotto/WinningLotto.java @@ -0,0 +1,18 @@ +package lotto.lotto; + +public class WinningLotto { + private final Lotto lotto; + private final int bonus; + public WinningLotto(Lotto lotto, int bonus){ + this.lotto = lotto; + this.bonus = bonus; + } + + public Lotto getLotto() { + return lotto; + } + + public int getBonus() { + return bonus; + } +} diff --git a/src/main/java/lotto/numbers/Prize.java b/src/main/java/lotto/numbers/Prize.java new file mode 100644 index 0000000000..c7d9f52667 --- /dev/null +++ b/src/main/java/lotto/numbers/Prize.java @@ -0,0 +1,17 @@ +package lotto.numbers; + +public enum Prize { + NONE(0),FIFTH(5000),FOURTH(50000), + THIRD(1500000),SECOND(30000000),FIRST(2000000000); + + private final long value; + + private Prize(long value){ + this.value = value; + } + + public long getValue() { + return value; + } + +} diff --git a/src/main/java/lotto/numbers/RandomRange.java b/src/main/java/lotto/numbers/RandomRange.java new file mode 100644 index 0000000000..abe18b0ccf --- /dev/null +++ b/src/main/java/lotto/numbers/RandomRange.java @@ -0,0 +1,15 @@ +package lotto.numbers; + +public enum RandomRange { + MIN_VALUE(1),MAX_VALUE(45),SIZE(6); + + private final int value; + + RandomRange(int value){ + this.value = value; + } + + public int getValue(){ + return value; + } +}