diff --git a/.gitignore b/.gitignore index 5dca701a7..9d23512ef 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,36 @@ build/ .springBeans .sts4-cache +# User-specific configurations +.idea/caches/ +.idea/libraries/ +.idea/shelf/ +.idea/workspace.xml +.idea/tasks.xml +.idea/.name +.idea/compiler.xml +.idea/copyright/profiles_settings.xml +.idea/encodings.xml +.idea/misc.xml +.idea/modules.xml +.idea/scopes/scope_settings.xml +.idea/dictionaries +.idea/vcs.xml +.idea/jsLibraryMappings.xml +.idea/datasources.xml +.idea/dataSources.ids +.idea/sqlDataSources.xml +.idea/dynamic.xml +.idea/uiDesigner.xml +.idea/assetWizardSettings.xml +.idea/gradle.xml +.idea/jarRepositories.xml +.idea/navEditor.xml + +### Kotlin ### +# Compiled class file +*.class + ### IntelliJ IDEA ### .idea *.iws @@ -31,5 +61,11 @@ out/ ### VS Code ### .vscode/ -### Mac OS ### +### macOS ### +# General .DS_Store +.AppleDouble +.LSOverride + +# Local configuration file (sdk path, etc) +local.properties diff --git a/README.md b/README.md index 4fc0ae874..031c22b20 100644 --- a/README.md +++ b/README.md @@ -1 +1,230 @@ -# kotlin-lotto-precourse +# [3์ฃผ์ฐจ] ๋กœ๋˜ (kotlin-lotto-precourse) + +### ๐Ÿ” ์ง„ํ–‰ ๋ฐฉ์‹ +- ๋ฏธ์…˜์€ ๊ณผ์ œ ์ง„ํ–‰ ์š”๊ตฌ ์‚ฌํ•ญ, ๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ, ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ ์„ธ ๊ฐ€์ง€๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค. +- ์„ธ ๊ฐœ์˜ ์š”๊ตฌ ์‚ฌํ•ญ์„ ๋งŒ์กฑํ•˜๊ธฐ ์œ„ํ•ด ๋…ธ๋ ฅํ•œ๋‹ค. ํŠนํžˆ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์ „์— ๊ธฐ๋Šฅ ๋ชฉ๋ก์„ ๋งŒ๋“ค๊ณ , ๊ธฐ๋Šฅ ๋‹จ์œ„๋กœ ์ปค๋ฐ‹ ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ์ง„ํ–‰ํ•œ๋‹ค. +- ๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ์— ๊ธฐ์žฌ๋˜์ง€ ์•Š์€ ๋‚ด์šฉ์€ ์Šค์Šค๋กœ ํŒ๋‹จํ•˜์—ฌ ๊ตฌํ˜„ํ•œ๋‹ค. + +
+ +### ๐Ÿ“ฎ ๋ฏธ์…˜ ์ œ์ถœ ๋ฐฉ๋ฒ• +- ๋ฏธ์…˜ ๊ตฌํ˜„์„ ์™„๋ฃŒํ•œ ํ›„ GitHub์„ ํ†ตํ•ด ์ œ์ถœํ•ด์•ผ ํ•œ๋‹ค. + - GitHub์„ ํ™œ์šฉํ•œ ์ œ์ถœ ๋ฐฉ๋ฒ•์€ [ํ”„๋ฆฌ์ฝ”์Šค ๊ณผ์ œ ์ œ์ถœ ๋ฌธ์„œ](https://github.com/woowacourse/woowacourse-docs/tree/main/precourse)๋ฅผ ์ฐธ๊ณ ํ•ด ์ œ์ถœํ•œ๋‹ค. +- GitHub์— ๋ฏธ์…˜์„ ์ œ์ถœํ•œ ํ›„ ์šฐ์•„ํ•œํ…Œํฌ์ฝ”์Šค ์ง€์› ํ”Œ๋žซํผ์— **PR ๋งํฌ๋ฅผ ํฌํ•จํ•˜์—ฌ ์ตœ์ข… ์ œ์ถœ**ํ•œ๋‹ค. + - ์ž์„ธํ•œ ์•ˆ๋‚ด๋Š” [์ œ์ถœ ๊ฐ€์ด๋“œ](https://github.com/woowacourse/woowacourse-docs/tree/main/precourse#%EC%A0%9C%EC%B6%9C-%EA%B0%80%EC%9D%B4%EB%93%9C)๋ฅผ ์ฐธ๊ณ ํ•œ๋‹ค. + - ๊ณผ์ œ๋ฅผ ์ˆ˜ํ–‰ํ•˜๋ฉด์„œ ๋Š๋‚€ ์ , ๋ฐฐ์šด ์ , ๋งŽ์€ ์‹œ๊ฐ„์„ ํˆฌ์žํ•œ ๋ถ€๋ถ„ ๋“ฑ ์ž์œ ๋กญ๊ฒŒ ์ž‘์„ฑํ•œ๋‹ค. + +
+ +### โœ”๏ธ ๊ณผ์ œ ์ œ์ถœ ์ „ ์ฒดํฌ ๋ฆฌ์ŠคํŠธ +- ๊ธฐ๋Šฅ์„ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ๊ตฌํ˜„ํ–ˆ๋”๋ผ๋„ ์š”๊ตฌ ์‚ฌํ•ญ์— ๋ช…์‹œ๋œ ์ถœ๋ ฅ ํ˜•์‹์„ ๋”ฐ๋ฅด์ง€ ์•Š์œผ๋ฉด 0์ ์„ ๋ฐ›๊ฒŒ ๋œ๋‹ค. +- ๊ธฐ๋Šฅ ๊ตฌํ˜„์„ ์™„๋ฃŒํ•œ ํ›„ ์•„๋ž˜ ๊ฐ€์ด๋“œ์— ๋”ฐ๋ผ ๋ชจ๋“  ํ…Œ์ŠคํŠธ๊ฐ€ ์„ฑ๊ณต์ ์œผ๋กœ ์‹คํ–‰๋˜๋Š”์ง€ ํ™•์ธํ•œ๋‹ค. +- ํ…Œ์ŠคํŠธ๊ฐ€ ์‹คํŒจํ•˜๋ฉด ์ ์ˆ˜๊ฐ€ 0์ ์ด ๋˜๋ฏ€๋กœ ์ œ์ถœํ•˜๊ธฐ ์ „์— ๋ฐ˜๋“œ์‹œ ํ™•์ธํ•œ๋‹ค. + +#### ํ…Œ์ŠคํŠธ ์‹คํ–‰ ๊ฐ€์ด๋“œ +- IntelliJ IDEA ๋˜๋Š” Android Studio์™€ ๊ฐ™์€ IDE์—์„œ ```Kotlin 1.9.24```๋กœ ์‹คํ–‰๋˜๋Š”์ง€ ํ™•์ธํ•œ๋‹ค. +- ํ„ฐ๋ฏธ๋„์—์„œ Mac ๋˜๋Š” Linux ์‚ฌ์šฉ์ž์˜ ๊ฒฝ์šฐ ```./gradlew clean test``` ๋ช…๋ น์„ ์‹คํ–‰ํ•˜๊ณ , Windows ์‚ฌ์šฉ์ž์˜ ๊ฒฝ์šฐ ```gradlew.bat clean test``` ๋˜๋Š” ```.\gradlew.bat clean test``` ๋ช…๋ น์„ ์‹คํ–‰ํ•  ๋•Œ ๋ชจ๋“  ํ…Œ์ŠคํŠธ๊ฐ€ ์•„๋ž˜์™€ ๊ฐ™์ด ํ†ต๊ณผํ•˜๋Š”์ง€ ํ™•์ธํ•œ๋‹ค. + +``` +BUILD SUCCESSFUL in 0s +``` + +

+ +------------- +### ๐Ÿ“ ๊ณผ์ œ ์ง„ํ–‰ ์š”๊ตฌ ์‚ฌํ•ญ +- ๋ฏธ์…˜์€ [๋กœ๋˜ ์ €์žฅ์†Œ](https://github.com/woowacourse-precourse/kotlin-lotto-7)๋ฅผ ํฌํฌํ•˜๊ณ  ํด๋ก ํ•˜๋Š” ๊ฒƒ์œผ๋กœ ์‹œ์ž‘ํ•œ๋‹ค. +- ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•˜๊ธฐ ์ „ README.md์— ๊ตฌํ˜„ํ•  ๊ธฐ๋Šฅ ๋ชฉ๋ก์„ ์ •๋ฆฌํ•ด ์ถ”๊ฐ€ํ•œ๋‹ค. +- Git์˜ ์ปค๋ฐ‹ ๋‹จ์œ„๋Š” ์•ž ๋‹จ๊ณ„์—์„œ README.md์— ์ •๋ฆฌํ•œ ๊ธฐ๋Šฅ ๋ชฉ๋ก ๋‹จ์œ„๋กœ ์ถ”๊ฐ€ํ•œ๋‹ค. + - [AngularJS Git Commit Message Conventions](https://gist.github.com/stephenparish/9941e89d80e2bc58a153)์„ ์ฐธ๊ณ ํ•ด ์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€๋ฅผ ์ž‘์„ฑํ•œ๋‹ค. +- ์ž์„ธํ•œ ๊ณผ์ œ ์ง„ํ–‰ ๋ฐฉ๋ฒ•์€ ํ”„๋ฆฌ์ฝ”์Šค ์ง„ํ–‰ ๊ฐ€์ด๋“œ ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•œ๋‹ค. + +
+ +### ๐Ÿš€ ๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ +๊ฐ„๋‹จํ•œ ๋กœ๋˜ ๋ฐœ๋งค๊ธฐ๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค. + +- ๋กœ๋˜ ๋ฒˆํ˜ธ์˜ ์ˆซ์ž ๋ฒ”์œ„๋Š” 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` ๋“ฑ๊ณผ ๊ฐ™์€ ๋ช…ํ™•ํ•œ ์œ ํ˜•์„ ์ฒ˜๋ฆฌํ•œ๋‹ค. + +--- +- [ ] ๋กœ๋˜ ๊ตฌ์ž… ๊ธˆ์•ก ์ž…๋ ฅ ๋ฐ›๊ธฐ (1000์› ๋‹จ์œ„) +- [ ] ๋กœ๋˜ ๋‹น์ฒจ ๋ฒˆํ˜ธ + ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ ์ž…๋ ฅ ๋ฐ›๊ธฐ (์‰ผํ‘œ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๊ตฌ๋ถ„) +- [ ] ๋กœ๋˜ ๊ตฌ์ž… ๊ธˆ์•ก์— ํ•ด๋‹นํ•˜๋Š” ๋งŒํผ ๋กœ๋˜๋ฅผ ๋ฐœํ–‰ (๋กœ๋˜ 1์žฅ ๊ฐ€๊ฒฉ : 1000์›) +- [ ] 1~45๊นŒ์ง€์˜ ์ˆซ์ž ์ค‘ ์ค‘๋ณต๋˜์ง€ ์•Š๋Š” 6๊ฐœ์˜ ์ˆซ์ž์™€ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ 1๊ฐœ ์ˆซ์ž ์ถ”์ถœ +- [ ] ์‚ฌ์šฉ์ž๊ฐ€ ๊ตฌ๋งคํ•œ ๋กœ๋˜ ๋ฒˆํ˜ธ์™€ ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ๋น„๊ต โ†’ ๋‹น์ฒจ ๋‚ด์—ญ ๋ฐ ์ˆ˜์ต๋ฅ (์†Œ์ˆ˜์  ๋‘˜์งธ ์ž๋ฆฌ์—์„œ ๋ฐ˜์˜ฌ๋ฆผ) ์ถœ๋ ฅ ํ›„ ๋กœ๋˜ ๊ฒŒ์ž„ ์ข…๋ฃŒ +- [ ] ์‚ฌ์šฉ์ž๊ฐ€ ์ž˜๋ชป๋œ ๊ฐ’์„ ์ž…๋ ฅํ•  ๊ฒฝ์šฐ `IllegalArgumentException`์„ ๋ฐœ์ƒ(`[ERROR]`๋กœ ์‹œ์ž‘ํ•˜๋Š” ์—๋Ÿฌ ๋ฉ”์‹œ์ง€)์‹œํ‚จ ํ›„ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ์ข…๋ฃŒ + - [ ] ๋กœ๋˜ ๊ตฌ์ž… ๊ธˆ์•ก์ด 1,000์›์œผ๋กœ ๋‚˜๋ˆ„์–ด ๋–จ์–ด์ง€์ง€ ์•Š๋Š” ๊ฒฝ์šฐ + - [ ] ๋กœ๋˜ ๊ตฌ์ž… ๊ธˆ์•ก์ด ๊ณต๋ฐฑ์ธ ๊ฒฝ์šฐ + - [ ] ๋‹น์ฒจ ๋ฒˆํ˜ธ๊ฐ€ ๊ณต๋ฐฑ์ธ ๊ฒฝ์šฐ + - [ ] ๋‹น์ฒจ ๋ฒˆํ˜ธ์— ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๋‹ค๋ฅธ ๋ฌธ์ž์—ด์ด ํฌํ•จ๋œ ๊ฒฝ์šฐ + - [ ] ๋‹น์ฒจ ๋ฒˆํ˜ธ๊ฐ€ 1~45๊นŒ์ง€์˜ ์ˆซ์ž์— ํฌํ•จ๋˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ + - [ ] ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๊ฐ€ ๊ณต๋ฐฑ์ธ ๊ฒฝ์šฐ + - [ ] ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๊ฐ€ ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๋‹ค๋ฅธ ๋ฌธ์ž์—ด์ธ ๊ฒฝ์šฐ + - [ ] ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๊ฐ€ 1~45๊นŒ์ง€์˜ ์ˆซ์ž์— ํฌํ•จ๋˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ + - [ ] ๋‹น์ฒจ ๋ฒˆํ˜ธ ๋ฐ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ์— ์ค‘๋ณต๋œ ์ˆซ์ž๊ฐ€ ์žˆ๋Š” ๊ฒฝ์šฐ +--- + + +#### ๐Ÿ’ฌ ์ž…์ถœ๋ ฅ ์š”๊ตฌ ์‚ฌํ•ญ +- ์ž…๋ ฅ : + - ๋กœ๋˜ ๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅ ๋ฐ›๋Š”๋‹ค. ๊ตฌ์ž… ๊ธˆ์•ก์€ 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%์ž…๋‹ˆ๋‹ค. + ``` + +
+ +### ๐Ÿ–ฅ๏ธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ +- Kotlin **1.9.24**์—์„œ ์‹คํ–‰ ๊ฐ€๋Šฅํ•ด์•ผ ํ•œ๋‹ค. +- Java ์ฝ”๋“œ๊ฐ€ ์•„๋‹Œ **Kotlin ์ฝ”๋“œ**๋กœ๋งŒ ๊ตฌํ˜„ํ•ด์•ผ ํ•œ๋‹ค. +- ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰์˜ ์‹œ์ž‘์ ์€ ```Application์˜ main()```์ด๋‹ค. +- build.gradle.kts ํŒŒ์ผ์€ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†์œผ๋ฉฐ, ์ œ๊ณต๋œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ด์™ธ์˜ ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค. +- ํ”„๋กœ๊ทธ๋žจ ์ข…๋ฃŒ ์‹œ ```System.exit()``` ๋˜๋Š” ```exitProcess()```๋ฅผ ํ˜ธ์ถœํ•˜์ง€ ์•Š๋Š”๋‹ค. +- ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ์—์„œ ๋‹ฌ๋ฆฌ ๋ช…์‹œํ•˜์ง€ ์•Š๋Š” ํ•œ ํŒŒ์ผ, ํŒจํ‚ค์ง€ ๋“ฑ์˜ ์ด๋ฆ„์„ ๋ฐ”๊พธ๊ฑฐ๋‚˜ ์ด๋™ํ•˜์ง€ ์•Š๋Š”๋‹ค. +- ์ฝ”ํ‹€๋ฆฐ ์ฝ”๋“œ ์ปจ๋ฒค์…˜์„ ์ง€ํ‚ค๋ฉด์„œ ํ”„๋กœ๊ทธ๋ž˜๋ฐํ•œ๋‹ค. +- ๊ธฐ๋ณธ์ ์œผ๋กœ [Kotlin Style Guide](https://github.com/woowacourse/woowacourse-docs/tree/main/styleguide/kotlin)๋ฅผ ์›์น™์œผ๋กœ ํ•œ๋‹ค. + +### ๐Ÿ–ฅ๏ธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ2 +- indent(์ธ๋ดํŠธ, ๋“ค์—ฌ์“ฐ๊ธฐ) depth๋ฅผ 3์ด ๋„˜์ง€ ์•Š๋„๋ก ๊ตฌํ˜„ํ•œ๋‹ค. 2๊นŒ์ง€๋งŒ ํ—ˆ์šฉํ•œ๋‹ค. + - ์˜ˆ๋ฅผ ๋“ค์–ด while๋ฌธ ์•ˆ์— if๋ฌธ์ด ์žˆ์œผ๋ฉด ๋“ค์—ฌ์“ฐ๊ธฐ๋Š” 2์ด๋‹ค. + - ํžŒํŠธ: indent(์ธ๋ดํŠธ, ๋“ค์—ฌ์“ฐ๊ธฐ) depth๋ฅผ ์ค„์ด๋Š” ์ข‹์€ ๋ฐฉ๋ฒ•์€ ํ•จ์ˆ˜(๋˜๋Š” ๋ฉ”์„œ๋“œ)๋ฅผ ๋ถ„๋ฆฌํ•˜๋ฉด ๋œ๋‹ค. +- ํ•จ์ˆ˜(๋˜๋Š” ๋ฉ”์„œ๋“œ)๊ฐ€ ํ•œ ๊ฐ€์ง€ ์ผ๋งŒ ํ•˜๋„๋ก ์ตœ๋Œ€ํ•œ ์ž‘๊ฒŒ ๋งŒ๋“ค์–ด๋ผ. +- JUnit 5์™€ AssertJ๋ฅผ ์ด์šฉํ•˜์—ฌ ์ •๋ฆฌํ•œ ๊ธฐ๋Šฅ ๋ชฉ๋ก์ด ์ •์ƒ์ ์œผ๋กœ ์ž‘๋™ํ•˜๋Š”์ง€ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋กœ ํ™•์ธํ•œ๋‹ค. + - ํ…Œ์ŠคํŠธ ๋„๊ตฌ ์‚ฌ์šฉ๋ฒ•์ด ์ต์ˆ™ํ•˜์ง€ ์•Š๋‹ค๋ฉด ์•„๋ž˜ ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ํ•™์Šตํ•œ ํ›„ ํ…Œ์ŠคํŠธ๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค. + - [JUnit 5 User Guide](https://junit.org/junit5/docs/current/user-guide/) + - [AssertJ User Guide](https://assertj.github.io/doc/) + - [AssertJ Exception Assertions](https://www.baeldung.com/assertj-exception-assertion) + - [Guide to JUnit 5 Parameterized Tests](https://www.baeldung.com/parameterized-tests-junit-5) + +### ๐Ÿ–ฅ๏ธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ3 +- ํ•จ์ˆ˜(๋˜๋Š” ๋ฉ”์„œ๋“œ)์˜ ๊ธธ์ด๊ฐ€ 15๋ผ์ธ์„ ๋„˜์–ด๊ฐ€์ง€ ์•Š๋„๋ก ๊ตฌํ˜„ํ•œ๋‹ค. + - ํ•จ์ˆ˜(๋˜๋Š” ๋ฉ”์„œ๋“œ)๊ฐ€ ํ•œ ๊ฐ€์ง€ ์ผ๋งŒ ์ž˜ ํ•˜๋„๋ก ๊ตฌํ˜„ํ•œ๋‹ค. +- else๋ฅผ ์ง€์–‘ํ•œ๋‹ค. + - ๋•Œ๋กœ๋Š” if/else, when๋ฌธ์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ๋” ๊น”๋”ํ•ด ๋ณด์ผ ์ˆ˜ ์žˆ๋‹ค. ์–ด๋Š ๊ฒฝ์šฐ์— ์“ฐ๋Š” ๊ฒƒ์ด ์ ์ ˆํ• ์ง€ ์Šค์Šค๋กœ ๊ณ ๋ฏผํ•ด ๋ณธ๋‹ค. + - ํžŒํŠธ: if ์กฐ๊ฑด์ ˆ์—์„œ ๊ฐ’์„ returnํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ•˜๋ฉด else๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค. +- Enum ํด๋ž˜์Šค๋ฅผ ์ ์šฉํ•˜์—ฌ ํ”„๋กœ๊ทธ๋žจ์„ ๊ตฌํ˜„ํ•œ๋‹ค. +- ๊ตฌํ˜„ํ•œ ๊ธฐ๋Šฅ์— ๋Œ€ํ•œ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋ฅผ ์ž‘์„ฑํ•œ๋‹ค. ๋‹จ, UI(System.out, System.in, Scanner) ๋กœ์ง์€ ์ œ์™ธํ•œ๋‹ค. + - ๋‹จ์œ„ ํ…Œ์ŠคํŠธ ์ž‘์„ฑ์ด ์ต์ˆ™ํ•˜์ง€ ์•Š๋‹ค๋ฉด `LottoTest`๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ํ•™์Šตํ•œ ํ›„ ํ…Œ์ŠคํŠธ๋ฅผ ์ž‘์„ฑํ•œ๋‹ค. + + + +#### ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ +- ```camp.nextstep.edu.missionutils```์—์„œ ์ œ๊ณตํ•˜๋Š” ```Randoms ๋ฐ Console API```๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌํ˜„ํ•ด์•ผ ํ•œ๋‹ค. + - Random ๊ฐ’ ์ถ”์ถœ์€ ```camp.nextstep.edu.missionutils.Randoms์˜ pickUniqueNumbersInRange()```๋ฅผ ํ™œ์šฉํ•œ๋‹ค. + - ์‚ฌ์šฉ์ž๊ฐ€ ์ž…๋ ฅํ•˜๋Š” ๊ฐ’์€ ```camp.nextstep.edu.missionutils.Console์˜ readLine()```์„ ํ™œ์šฉํ•œ๋‹ค. + +> ์‚ฌ์šฉ ์˜ˆ์‹œ : 1์—์„œ 45 ์‚ฌ์ด์˜ ์ค‘๋ณต๋˜์ง€ ์•Š์€ ์ •์ˆ˜ 6๊ฐœ ๋ฐ˜ํ™˜ + +``` +Randoms.pickUniqueNumbersInRange(1, 45, 6) +``` + +#### Lotto ํด๋ž˜์Šค +- ์ œ๊ณต๋œ `Lotto ํด๋ž˜์Šค`๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ตฌํ˜„ํ•ด์•ผ ํ•œ๋‹ค. +- `Lotto`์— `numbers` ์ด์™ธ์˜ ํ•„๋“œ(์ธ์Šคํ„ด์Šค ๋ณ€์ˆ˜)๋ฅผ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์—†๋‹ค. +- `numbers`์˜ ์ ‘๊ทผ ์ œ์–ด์ž์ธ `private`์€ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†๋‹ค. +- `Lotto`์˜ ํŒจํ‚ค์ง€๋ฅผ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋‹ค. + +``` +package lotto + +class Lotto(private val numbers: List) { + init { + require(numbers.size == 6) { "[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 6๊ฐœ์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค." } + } + + // TODO: ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ +} +``` + diff --git a/src/main/kotlin/lotto/Application.kt b/src/main/kotlin/lotto/Application.kt index 151821c9c..c0477a6af 100644 --- a/src/main/kotlin/lotto/Application.kt +++ b/src/main/kotlin/lotto/Application.kt @@ -1,5 +1,5 @@ package lotto fun main() { - // TODO: ํ”„๋กœ๊ทธ๋žจ ๊ตฌํ˜„ + LottoController().run() } diff --git a/src/main/kotlin/lotto/InputValidation.kt b/src/main/kotlin/lotto/InputValidation.kt new file mode 100644 index 000000000..94f0aa719 --- /dev/null +++ b/src/main/kotlin/lotto/InputValidation.kt @@ -0,0 +1,40 @@ +package lotto + +class InputValidation { + + fun checkPayment(payment: Int) { + if(payment <= 0) { + throw IllegalArgumentException("[ERROR] ๊ตฌ์ž… ๊ธˆ์•ก์€ 1000์› ์ด์ƒ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.") + } + + if((payment%1000) != 0) { + throw IllegalArgumentException("[ERROR] ๊ตฌ์ž… ๊ธˆ์•ก์€ 1000์› ๋‹จ์œ„๋กœ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.") + } + } + + fun checkLottoNum(lottoNum: List) { + lottoNum.forEach { num -> + val lottoNumber = num.toIntOrNull() ?: throw IllegalArgumentException("[ERROR] ๋‹น์ฒจ ๋ฒˆํ˜ธ๋Š” ์ •์ˆ˜๋กœ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.") + + if (lottoNumber !in 1..45) { + throw IllegalArgumentException("[ERROR] ๋‹น์ฒจ ๋ฒˆํ˜ธ๋Š” 1~45๊นŒ์ง€์˜ ์ˆซ์ž๋กœ๋งŒ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. : $num") + } + } + + if(lottoNum.size != 6) { + throw IllegalArgumentException("[ERROR] ๋‹น์ฒจ ๋ฒˆํ˜ธ๋Š” 6๊ฐœ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.") + } + } + + fun checkBonusLottoNum(bonusLottoNum: Int) { + if(bonusLottoNum !in 1..45) { + throw IllegalArgumentException("[ERROR] ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋Š” 1~45๊นŒ์ง€์˜ ์ˆซ์ž๋กœ๋งŒ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. : $bonusLottoNum") + } + } + + fun checkDuplicate(lottoNum: List, bonusLottoNum: Int) { + if(lottoNum.contains(bonusLottoNum)) { + throw IllegalArgumentException("[ERROR] ๋กœ๋˜ ๋‹น์ฒจ ๋ฒˆํ˜ธ๋Š” ์ค‘๋ณต์ด ์•„๋‹Œ 6๊ฐœ์˜ ์ˆซ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค.") + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/lotto/Lotto.kt b/src/main/kotlin/lotto/Lotto.kt index b97abc385..d7946451b 100644 --- a/src/main/kotlin/lotto/Lotto.kt +++ b/src/main/kotlin/lotto/Lotto.kt @@ -1,9 +1,37 @@ package lotto + class Lotto(private val numbers: List) { + init { require(numbers.size == 6) { "[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 6๊ฐœ์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค." } + require(numbers.size == numbers.distinct().size) { "[ERROR] ๋กœ๋˜ ๋‹น์ฒจ ๋ฒˆํ˜ธ๋Š” ์ค‘๋ณต์ด ์•„๋‹Œ 6๊ฐœ์˜ ์ˆซ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค." } + require(numbers.all { it in 1..45}) {"[ERROR] ๋กœ๋˜ ๋‹น์ฒจ ๋ฒˆํ˜ธ๋Š” 1~45๊นŒ์ง€์˜ ์ˆซ์ž๋กœ๋งŒ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."} + require(numbers.isNotEmpty()) {"[ERROR] ๋กœ๋˜ ๋‹น์ฒจ ๋ฒˆํ˜ธ๋Š” ์ค‘๋ณต์ด ์•„๋‹Œ 6๊ฐœ์˜ ์ˆซ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."} + } + + fun checkMatch(outputLottoNumbers: MutableList>, bonusLottoNum: Int): MutableList { + val results = MutableList(5) { 0 } + + outputLottoNumbers.forEach { outputNum -> + val count = outputNum.count { it in numbers } + val isBonusMatch = bonusLottoNum in outputNum + val rank = checkWinning(count, isBonusMatch) + + rank?.let { results[it] += 1 } + } + + return results } - // TODO: ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ + fun checkWinning(count: Int, bonusMatch: Boolean): Int? { + return when { + count == 6 -> 4 // 1๋“ฑ + count == 5 && bonusMatch -> 3 // 2๋“ฑ + count == 5 -> 2 // 3๋“ฑ + count == 4 -> 1 // 4๋“ฑ + count == 3 -> 0 // 5๋“ฑ + else -> null + } + } } diff --git a/src/main/kotlin/lotto/LottoController.kt b/src/main/kotlin/lotto/LottoController.kt new file mode 100644 index 000000000..0bedf5928 --- /dev/null +++ b/src/main/kotlin/lotto/LottoController.kt @@ -0,0 +1,20 @@ +package lotto + +import lotto.View.InputView +import lotto.View.OutputView + +class LottoController { + + private var inputView = InputView() + private var outputView = OutputView() + + + fun run() { + val lottoAmount = inputView.inputPurchaseLotto() + val outputLottoNum = outputView.outputLottoNum(lottoAmount) + val lottoNum = inputView.inputLottoNum().map { it.toIntOrNull() ?: throw IllegalArgumentException("[ERROR] ๋‹น์ฒจ ๋ฒˆํ˜ธ๋Š” ์ •์ˆ˜๋กœ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.")} + val bonusLottoNum = inputView.inputBonusLottoNum(lottoNum) + + outputView.outputResult(lottoAmount*1000, outputLottoNum, lottoNum, bonusLottoNum) + } +} \ No newline at end of file diff --git a/src/main/kotlin/lotto/LottoResult.kt b/src/main/kotlin/lotto/LottoResult.kt new file mode 100644 index 000000000..8420c1b1f --- /dev/null +++ b/src/main/kotlin/lotto/LottoResult.kt @@ -0,0 +1,24 @@ +package lotto + +class LottoResult { + + fun checkAmount(payment: Int): Int { + InputValidation().checkPayment(payment) + + return (payment / 1000) + } + + fun calculateRevenueRate(payment: Int, results: List): Double { + val revenue = calculateRevenue(results) + + return if (payment == 0) 0.00 else String.format("%.2f", (revenue / payment) * 100).toDouble() + } + + fun calculateRevenue(results: List): Double { + val earningPerRank = listOf(5000, 50000, 1500000, 30000000, 2000000000) + + val totalEarnings = results.zip(earningPerRank).sumOf { (count, earning) -> count * earning } + + return totalEarnings.toDouble() + } +} \ No newline at end of file diff --git a/src/main/kotlin/lotto/View/InputView.kt b/src/main/kotlin/lotto/View/InputView.kt new file mode 100644 index 000000000..51ae733a3 --- /dev/null +++ b/src/main/kotlin/lotto/View/InputView.kt @@ -0,0 +1,60 @@ +package lotto.View + +import camp.nextstep.edu.missionutils.Console +import lotto.InputValidation +import lotto.Lotto +import lotto.LottoResult + +class InputView { + fun inputPurchaseLotto(): Int { + println("๊ตฌ์ž…๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.") + + while (true) { + try { + val lottoPayment = Console.readLine().toIntOrNull() + ?: throw IllegalArgumentException("[ERROR] ๊ตฌ์ž… ๊ธˆ์•ก์€ ์ˆซ์ž๋กœ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.") + + val lottoAmount = LottoResult().checkAmount(lottoPayment) + + return lottoAmount + } catch (e: IllegalArgumentException) { + println(e.message) + } + } + + } + + fun inputLottoNum(): List { + println("๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.") + + while (true) { + try { + val lottoNum = Console.readLine().split(",") + + InputValidation().checkLottoNum(lottoNum) + + return lottoNum + } catch (e: IllegalArgumentException) { + println(e.message) + } + } + } + + fun inputBonusLottoNum(lottoNum: List): Int { + println("๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.") + while (true) { + try { + val bonusLottoNum = Console.readLine().toIntOrNull() + ?: throw IllegalArgumentException("[ERROR] ๊ตฌ์ž… ๊ธˆ์•ก์€ ์ˆซ์ž๋กœ ์ž…๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.") + + InputValidation().checkBonusLottoNum(bonusLottoNum) + InputValidation().checkDuplicate(lottoNum, bonusLottoNum) + + return bonusLottoNum + } catch (e: IllegalArgumentException) { + // ์˜ˆ์™ธ ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅํ•˜๊ณ  ์žฌ์ž…๋ ฅ์„ ๋ฐ›๋„๋ก ํ•œ๋‹ค. + println(e.message) + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/lotto/View/OutputView.kt b/src/main/kotlin/lotto/View/OutputView.kt new file mode 100644 index 000000000..ac86d18b2 --- /dev/null +++ b/src/main/kotlin/lotto/View/OutputView.kt @@ -0,0 +1,52 @@ +package lotto.View + +import camp.nextstep.edu.missionutils.Randoms +import lotto.Lotto +import lotto.LottoResult + +class OutputView { + + fun outputLottoNum(amount: Int): MutableList> { + + println("${amount}๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค.") + + var outputLotto = mutableListOf>() + + for (num in 0 until amount) { + outputLotto.add(Randoms.pickUniqueNumbersInRange(1, 45, 6).sorted()) + } + + outputLotto.forEach { lottoNumbers -> + println(lottoNumbers) + } + + return outputLotto + } + + fun outputResult( + payment: Int, + outputLottoNum: MutableList>, + lottoNum: List, + bonusLottoNum: Int + ) { + println("๋‹น์ฒจ ํ†ต๊ณ„\n---") + + val matchResult = Lotto(lottoNum).checkMatch(outputLottoNum, bonusLottoNum) + + val matchCountLabels = listOf( + "3๊ฐœ ์ผ์น˜ (5,000์›) -", + "4๊ฐœ ์ผ์น˜ (50,000์›) -", + "5๊ฐœ ์ผ์น˜ (1,500,000์›) -", + "5๊ฐœ ์ผ์น˜, ๋ณด๋„ˆ์Šค ๋ณผ ์ผ์น˜ (30,000,000์›) -", + "6๊ฐœ ์ผ์น˜ (2,000,000,000์›) -" + ) + + matchResult.forEachIndexed { index, count -> + println("${matchCountLabels[index]} ${count}๊ฐœ") + } + + val revenue = LottoResult().calculateRevenueRate(payment, matchResult) + + println("์ด ์ˆ˜์ต๋ฅ ์€ ${revenue}%์ž…๋‹ˆ๋‹ค.") + } +} \ No newline at end of file diff --git a/src/test/kotlin/lotto/LottoTest.kt b/src/test/kotlin/lotto/LottoTest.kt index 122fae572..080cfdead 100644 --- a/src/test/kotlin/lotto/LottoTest.kt +++ b/src/test/kotlin/lotto/LottoTest.kt @@ -20,4 +20,54 @@ class LottoTest { } // TODO: ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„์— ๋”ฐ๋ฅธ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ž‘์„ฑ + @Test + fun `๋กœ๋˜ ๋ฒˆํ˜ธ์˜ ๊ฐœ์ˆ˜๊ฐ€ 6๊ฐœ ์ดํ•˜๋ฉด ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค`() { + assertThrows { + Lotto(listOf(1, 2, 3, 4, 5)) + } + } + + @Test + fun `๋กœ๋˜ ๋ฒˆํ˜ธ๊ฐ€ 1~45๊นŒ์ง€์˜ ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค`() { + assertThrows { + Lotto(listOf(1, 2, 3, 4, 5, 55)) + } + + assertThrows { + Lotto(listOf(1, 2, 3, 4, 5, 0)) + } + } + + @Test + fun `๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๊ฐ€ 1~45๊นŒ์ง€์˜ ์ˆซ์ž๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค`() { + + assertThrows { + val bonusLottoNum = 46 + InputValidation().checkBonusLottoNum(bonusLottoNum) + } + + assertThrows { + val bonusLottoNum = 0 + InputValidation().checkBonusLottoNum(bonusLottoNum) + } + } + + @Test + fun `๋‹น์ฒจ ๋ฒˆํ˜ธ ๋ฐ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ์— ์ค‘๋ณต๋œ ์ˆซ์ž๊ฐ€ ์žˆ์œผ๋ฉด ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค`() { + val lottoNum = listOf(1, 2, 3, 4, 5, 6) + val bonusLottoNum = 1 + + assertThrows { + InputValidation().checkDuplicate(lottoNum, bonusLottoNum) + } + } + + @Test + fun `๋กœ๋˜ ๊ตฌ์ž… ๊ธˆ์•ก์ด 1,000์›์œผ๋กœ ๋‚˜๋ˆ„์–ด ๋–จ์–ด์ง€์ง€ ์•Š์œผ๋ฉด ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค`() { + val lottoPayment = 1500 + + assertThrows { + InputValidation().checkPayment(lottoPayment) + } + } }