From 0ab2ae2389c2cd070ecc3cbb06cf607f0e81cf7a Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Thu, 31 Oct 2024 17:37:40 +0900 Subject: [PATCH 01/28] =?UTF-8?q?docs:=20README=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5fa2560b46..548d024b64 100644 --- a/README.md +++ b/README.md @@ -1 +1,96 @@ -# java-lotto-precourse +# ๐ŸŽŸ๏ธ java-lotto-precourse + +## ๐Ÿ“‹ ๊ธฐ๋Šฅ ์š”๊ตฌ ์‚ฌํ•ญ + +> ๊ฐ„๋‹จํ•œ ๋กœ๋˜ ๋ฐœ๋งค๊ธฐ๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค. + +- ๋กœ๋˜ ๋ฒˆํ˜ธ์˜ ์ˆซ์ž ๋ฒ”์œ„๋Š” 1~45๊นŒ์ง€์ด๋‹ค. +- 1๊ฐœ์˜ ๋กœ๋˜๋ฅผ ๋ฐœํ–‰ํ•  ๋•Œ ์ค‘๋ณต๋˜์ง€ ์•Š๋Š” 6๊ฐœ์˜ ์ˆซ์ž๋ฅผ ๋ฝ‘๋Š”๋‹ค. +- ๋‹น์ฒจ ๋ฒˆํ˜ธ ์ถ”์ฒจ ์‹œ ์ค‘๋ณต๋˜์ง€ ์•Š๋Š” ์ˆซ์ž 6๊ฐœ์™€ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ 1๊ฐœ๋ฅผ ๋ฝ‘๋Š”๋‹ค. +- ๋‹น์ฒจ์€ 1๋“ฑ๋ถ€ํ„ฐ 5๋“ฑ๊นŒ์ง€ ์žˆ๋‹ค. ๋‹น์ฒจ ๊ธฐ์ค€๊ณผ ๊ธˆ์•ก์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค. + - 1๋“ฑ: 6๊ฐœ ๋ฒˆํ˜ธ ์ผ์น˜ / 2,000,000,000์› + - 2๋“ฑ: 5๊ฐœ ๋ฒˆํ˜ธ + ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ ์ผ์น˜ / 30,000,000์› + - 3๋“ฑ: 5๊ฐœ ๋ฒˆํ˜ธ ์ผ์น˜ / 1,500,000์› + - 4๋“ฑ: 4๊ฐœ ๋ฒˆํ˜ธ ์ผ์น˜ / 50,000์› + - 5๋“ฑ: 3๊ฐœ ๋ฒˆํ˜ธ ์ผ์น˜ / 5,000์› +- ๋กœ๋˜ ๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅํ•˜๋ฉด ๊ตฌ์ž… ๊ธˆ์•ก์— ํ•ด๋‹นํ•˜๋Š” ๋งŒํผ ๋กœ๋˜๋ฅผ ๋ฐœํ–‰ํ•ด์•ผ ํ•œ๋‹ค. +- ๋กœ๋˜ 1์žฅ์˜ ๊ฐ€๊ฒฉ์€ 1,000์›์ด๋‹ค. +- ๋‹น์ฒจ ๋ฒˆํ˜ธ์™€ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. +- ์‚ฌ์šฉ์ž๊ฐ€ ๊ตฌ๋งคํ•œ ๋กœ๋˜ ๋ฒˆํ˜ธ์™€ ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ๋น„๊ตํ•˜์—ฌ ๋‹น์ฒจ ๋‚ด์—ญ ๋ฐ ์ˆ˜์ต๋ฅ ์„ ์ถœ๋ ฅํ•˜๊ณ  ๋กœ๋˜ ๊ฒŒ์ž„์„ ์ข…๋ฃŒํ•œ๋‹ค. +- ์‚ฌ์šฉ์ž๊ฐ€ ์ž˜๋ชป๋œ ๊ฐ’์„ ์ž…๋ ฅํ•  ๊ฒฝ์šฐ IllegalArgumentException์„ ๋ฐœ์ƒ์‹œํ‚ค๊ณ , "[ERROR]"๋กœ ์‹œ์ž‘ํ•˜๋Š” ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅ ํ›„ ๊ทธ ๋ถ€๋ถ„๋ถ€ํ„ฐ ์ž…๋ ฅ์„ ๋‹ค์‹œ ๋ฐ›๋Š”๋‹ค. + - Exception์ด ์•„๋‹Œ IllegalArgumentException, IllegalStateException ๋“ฑ๊ณผ ๊ฐ™์€ ๋ช…ํ™•ํ•œ ์œ ํ˜•์„ ์ฒ˜๋ฆฌํ•œ๋‹ค. + +## ๐Ÿ› ๏ธ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ 1 +- **JDK 21** ๋ฒ„์ „์—์„œ ์‹คํ–‰ ๊ฐ€๋Šฅํ•ด์•ผ ํ•œ๋‹ค. +- ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰์˜ ์‹œ์ž‘์ ์€ Application์˜ main()์ด๋‹ค. +- **build.gradle** ํŒŒ์ผ์€ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์—†์œผ๋ฉฐ, ์ œ๊ณต๋œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ด์™ธ์˜ ์™ธ๋ถ€ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค. +- ํ”„๋กœ๊ทธ๋žจ ์ข…๋ฃŒ ์‹œ System.exit()๋ฅผ ํ˜ธ์ถœํ•˜์ง€ ์•Š๋Š”๋‹ค. +- ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ์—์„œ ๋‹ฌ๋ฆฌ ๋ช…์‹œํ•˜์ง€ ์•Š๋Š” ํ•œ ํŒŒ์ผ, ํŒจํ‚ค์ง€ ๋“ฑ์˜ ์ด๋ฆ„์„ ๋ฐ”๊พธ๊ฑฐ๋‚˜ ์ด๋™ํ•˜์ง€ ์•Š๋Š”๋‹ค. +- ์ž๋ฐ” ์ฝ”๋“œ ์ปจ๋ฒค์…˜์„ ์ง€ํ‚ค๋ฉด์„œ ํ”„๋กœ๊ทธ๋ž˜๋ฐํ•œ๋‹ค. +- ๊ธฐ๋ณธ์ ์œผ๋กœ [Java Style Guide](https://github.com/woowacourse/woowacourse-docs/tree/main/styleguide/java)๋ฅผ ์›์น™์œผ๋กœ ํ•œ๋‹ค. + +## ๐Ÿ“ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ 2 +- **indent**(์ธ๋ดํŠธ, ๋“ค์—ฌ์“ฐ๊ธฐ) **depth**๋ฅผ 3์ด ๋„˜์ง€ ์•Š๋„๋ก ๊ตฌํ˜„ํ•œ๋‹ค. **2**๊นŒ์ง€๋งŒ ํ—ˆ์šฉํ•œ๋‹ค. + - ์˜ˆ๋ฅผ ๋“ค์–ด while๋ฌธ ์•ˆ์— if๋ฌธ์ด ์žˆ์œผ๋ฉด ๋“ค์—ฌ์“ฐ๊ธฐ๋Š” 2์ด๋‹ค. + - ํžŒํŠธ: indent(์ธ๋ดํŠธ, ๋“ค์—ฌ์“ฐ๊ธฐ) depth๋ฅผ ์ค„์ด๋Š” ์ข‹์€ ๋ฐฉ๋ฒ•์€ ํ•จ์ˆ˜(๋˜๋Š” ๋ฉ”์„œ๋“œ)๋ฅผ ๋ถ„๋ฆฌํ•˜๋ฉด ๋œ๋‹ค. +- **3ํ•ญ ์—ฐ์‚ฐ์ž**๋ฅผ ์“ฐ์ง€ ์•Š๋Š”๋‹ค. +- ํ•จ์ˆ˜(๋˜๋Š” ๋ฉ”์„œ๋“œ)๊ฐ€ **ํ•œ ๊ฐ€์ง€** ์ผ๋งŒ ํ•˜๋„๋ก ์ตœ๋Œ€ํ•œ ์ž‘๊ฒŒ ๋งŒ๋“ค์–ด๋ผ. +- `JUnit 5`์™€ `AssertJ`๋ฅผ ์ด์šฉํ•˜์—ฌ ์ •๋ฆฌํ•œ ๊ธฐ๋Šฅ ๋ชฉ๋ก์ด ์ •์ƒ์ ์œผ๋กœ ์ž‘๋™ํ•˜๋Š”์ง€ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋กœ ํ™•์ธํ•œ๋‹ค. + +## ๐Ÿ” ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์š”๊ตฌ ์‚ฌํ•ญ 3 +- ํ•จ์ˆ˜(๋˜๋Š” ๋ฉ”์„œ๋“œ)์˜ ๊ธธ์ด๊ฐ€ **15 ๋ผ์ธ**์„ ๋„˜์–ด๊ฐ€์ง€ ์•Š๋„๋ก ๊ตฌํ˜„ํ•œ๋‹ค. + - ํ•จ์ˆ˜(๋˜๋Š” ๋ฉ”์„œ๋“œ)๊ฐ€ **ํ•œ ๊ฐ€์ง€** ์ผ๋งŒ ์ž˜ ํ•˜๋„๋ก ๊ตฌํ˜„ํ•œ๋‹ค. +- **else ์˜ˆ์•ฝ์–ด**๋ฅผ ์“ฐ์ง€ ์•Š๋Š”๋‹ค. + - else๋ฅผ ์“ฐ์ง€ ๋ง๋ผ๊ณ  ํ•˜๋‹ˆ switch/case๋กœ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ๋Š”๋ฐ **switch/case**๋„ ํ—ˆ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค. + - ํžŒํŠธ: if ์กฐ๊ฑด์ ˆ์—์„œ ๊ฐ’์„ returnํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ•˜๋ฉด else๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค. +- **Java** `Enum`์„ ์ ์šฉํ•˜์—ฌ ํ”„๋กœ๊ทธ๋žจ์„ ๊ตฌํ˜„ํ•œ๋‹ค. +- ๊ตฌํ˜„ํ•œ ๊ธฐ๋Šฅ์— ๋Œ€ํ•œ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ๋ฅผ ์ž‘์„ฑํ•œ๋‹ค. ๋‹จ, UI(System.out, System.in, Scanner) ๋กœ์ง์€ ์ œ์™ธํ•œ๋‹ค. + - ๋‹จ์œ„ ํ…Œ์ŠคํŠธ ์ž‘์„ฑ์ด ์ต์ˆ™ํ•˜์ง€ ์•Š๋‹ค๋ฉด `LottoTest`๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ํ•™์Šตํ•œ ํ›„ ํ…Œ์ŠคํŠธ๋ฅผ ์ž‘์„ฑํ•œ๋‹ค. + +## ๐Ÿš€ ๊ตฌํ˜„ํ•  ๊ธฐ๋Šฅ ๋ชฉ๋ก + +### 1. ์ž…๋ ฅ ์ฒ˜๋ฆฌ +- [ ] ์‚ฌ์šฉ์ž๊ฐ€ ๊ตฌ์ž…ํ•  ๋กœ๋˜์˜ ์ด ๊ธˆ์•ก์„ **1,000 ๋‹จ์œ„**๋กœ ์ž…๋ ฅ +- [ ] ๋‹น์ฒจ ๋ฒˆํ˜ธ์ธ 6๊ฐœ์˜ ์ˆซ์ž ์ž…๋ ฅ (๋ฒˆํ˜ธ๋Š” ์‰ผํ‘œ(,)๋กœ ๊ตฌ๋ถ„) +- [ ] ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ์ธ 1๊ฐœ์˜ ์ˆซ์ž ์ž…๋ ฅ + +### 2. ๋กœ๋˜ ๋ฒˆํ˜ธ ์ƒ์„ฑ +- [ ] ์‚ฌ์šฉ์ž๊ฐ€ ๊ตฌ๋งคํ•œ ๊ธˆ์•ก์— ๋”ฐ๋ผ ํ•ด๋‹น ์ˆ˜๋Ÿ‰๋งŒํผ ๋กœ๋˜ ๋ฒˆํ˜ธ ์ƒ์„ฑ +- [ ] 1๋ถ€ํ„ฐ 45๊นŒ์ง€์˜ ์ˆซ์ž ์ค‘ ์ค‘๋ณต๋˜์ง€ ์•Š๋Š” 6๊ฐœ์˜ ๋กœ๋˜ ๋ฒˆํ˜ธ๋ฅผ ๋žœ๋คํ•˜๊ฒŒ ์ƒ์„ฑ + +### 3. ๋‹น์ฒจ ๋ฒˆํ˜ธ ์ €์žฅ +- [ ] ์ž…๋ ฅ๋ฐ›์€ ๋‹น์ฒจ ๋ฒˆํ˜ธ ๋ฐ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ ๋ฆฌ์ŠคํŠธ ์ƒ์„ฑ + +### 4. ๋‹น์ฒจ ๊ฒฐ๊ณผ ๋ฐ ์ˆ˜์ต๋ฅ  ๊ณ„์‚ฐ +- [ ] ๊ตฌ๋งคํ•œ ๋กœ๋˜ ๋ฒˆํ˜ธ์™€ ๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ๋น„๊ตํ•˜์—ฌ ์ผ์น˜ํ•˜๋Š” ๊ฐœ์ˆ˜ ๊ณ„์‚ฐ +- [ ] ๊ฐ ๋“ฑ์ˆ˜๋ณ„ ๋‹น์ฒจ ๊ธˆ์•ก์œผ๋กœ ์ด ์ˆ˜์ต์„ ๊ณ„์‚ฐ +- [ ] ๊ณ„์‚ฐ๋œ ์ˆ˜์ต๊ณผ ๊ตฌ์ž…ํ•œ ๋กœ๋˜์˜ ์ด ๊ธˆ์•ก์„ ๊ธฐ๋ฐ˜์œผ๋กœ ์†Œ์ˆ˜์  ๋‘˜์งธ ์ž๋ฆฌ์—์„œ ๋ฐ˜์˜ฌ๋ฆผํ•˜์—ฌ ์ˆ˜์ต๋ฅ  ๊ณ„์‚ฐ + +### 5. ์ถœ๋ ฅ ์ฒ˜๋ฆฌ +- [ ] ์‚ฌ์šฉ์ž๊ฐ€ ๊ตฌ๋งคํ•œ ๋กœ๋˜์˜ ๊ฐœ์ˆ˜์™€ ๋žœ๋ค ๋ฒˆํ˜ธ ์˜ค๋ฆ„์ฐจ์ˆœ ์ถœ๋ ฅ +- [ ] ๋“ฑ์ˆ˜๋ณ„ ๋‹น์ฒจ ๊ฐœ์ˆ˜์™€ ํ•ด๋‹น ์ƒ๊ธˆ ์ถœ๋ ฅ +- [ ] ๋‹น์ฒจ ๊ธˆ์•ก๊ณผ ์ด ์ˆ˜์ต๋ฅ  ์ถœ๋ ฅ + +### 6. ์˜ˆ์™ธ ์ฒ˜๋ฆฌ +- [ ] ๊ตฌ์ž… ๊ธˆ์•ก์ด 1,000์˜ ๋ฐฐ์ˆ˜๊ฐ€ ์•„๋‹ ์‹œ +- [ ] ๊ตฌ์ž… ๊ธˆ์•ก์ด 100,000์›์„ ์ดˆ๊ณผํ•  ์‹œ (๊ตฌ์ž…ํ•œ ๋กœ๋˜ ๊ฐœ์ˆ˜๊ฐ€ 100๊ฐœ๋ฅผ ์ดˆ๊ณผํ•  ์‹œ) +- [ ] ๋กœ๋˜ ๊ตฌ๋งค ๊ฐœ์ˆ˜๊ฐ€ 1๊ฐœ ์ดํ•˜์ผ ์‹œ +- [ ] ๋‹น์ฒจ ๋ฒˆํ˜ธ์˜ ๊ตฌ๋ถ„์ž๋กœ ์‰ผํ‘œ(,)๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์„ ์‹œ +- [ ] ๋‹น์ฒจ ๋ฒˆํ˜ธ๊ฐ€ ์ค‘๋ณต๋˜๊ฑฐ๋‚˜ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๊ฐ€ ๋‹น์ฒจ ๋ฒˆํ˜ธ์™€ ์ค‘๋ณต๋  ์‹œ +- [ ] ๋‹น์ฒจ ๋ฒˆํ˜ธ์™€ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๊ฐ€ 1๋ถ€ํ„ฐ 45 ์‚ฌ์ด์˜ ๋ฒ”์œ„๋ฅผ ๋ฒ—์–ด๋‚  ์‹œ +- [ ] ๋‹น์ฒจ ๋ฒˆํ˜ธ 6๊ฐœ, ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ 1๊ฐœ์˜ ๊ฐœ์ˆ˜์—์„œ ๋ฒ—์–ด๋‚  ์‹œ +- [ ] ์ž…๋ ฅ๋œ ๊ฐ’์˜ ํ˜•์‹์ด ์ˆซ์ž๊ฐ€ ์•„๋‹ ์‹œ (๋‹จ, ๋‹น์ฒจ ๋ฒˆํ˜ธ ์ž…๋ ฅ์—์„œ ๊ตฌ๋ถ„์ž๋Š” ํ—ˆ์šฉํ•จ) +- [ ] ์ž…๋ ฅ๋œ ๊ฐ’์ด ๊ณต๋ฐฑ ๋˜๋Š” ๋นˆ ๋ฌธ์ž์—ด์ผ ์‹œ + +### 7. ํ…Œ์ŠคํŠธ +- [ ] **๊ธฐ๋Šฅ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ**๋กœ ํ”„๋กœ๊ทธ๋žจ์˜ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์ด ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์ž‘๋™ํ•˜๋Š”์ง€ ๊ฒ€์ฆ +- [ ] **์˜ˆ์™ธ ๋‹จ์œ„ ํ…Œ์ŠคํŠธ**๋กœ ํ”„๋กœ๊ทธ๋žจ์ด ์˜ˆ์™ธ ์ƒํ™ฉ์— ์ ์ ˆํ•œ ์—๋Ÿฌ ๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅํ•˜๋Š”์ง€ ๊ฒ€์ฆ + +## ๐ŸŽฏ 3์ฃผ์ฐจ ๊ณผ์ œ์˜ ๋ชฉํ‘œ +2์ฃผ์ฐจ์˜ ์ฝ”๋“œ ๋ฆฌ๋ทฐ๋ฅผ ์ƒ๊ธฐํ•˜๋ฉฐ ํ”ผ๋“œ๋ฐฑ์— ๋”ฐ๋ผ ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜๊ธฐ + +1. if๋ฌธ ๋‚ด์—์„œ ์ค‘๊ด„ํ˜ธ๋ฅผ ์ƒ๋žตํ•˜๋ฉด ์•ˆ ๋จ (`Google Java Style Guide` ์–ด๊ธ‹๋‚จ) +2. ๋ฉ”์„œ๋“œ ๋„ค์ด๋ฐ ์ค‘ `is`๊ฐ€ ์ ‘๋‘์–ด๋กœ ์“ฐ์ด๋ฉด `boolean` ํƒ€์ž…์„ ๋ฐ˜ํ™˜ํ•  ๊ฒƒ ๊ฐ™์œผ๋‹ˆ ๋ฉ”์„œ๋“œ๋ช…์„ ๋ช…ํ™•ํ•˜๊ฒŒ ํ‘œํ˜„ํ•˜์ž +3. ํ•˜๋“œ ์ฝ”๋”ฉ ๋Œ€์‹  ๋ฒ”์œ„๋‚˜ ์กฐ๊ฑด ๊ฐ’์„ ์ƒ์ˆ˜๋กœ ์ฒ˜๋ฆฌํ•ด ์ผ๊ด€์„ฑ ๊ฐ€์ง€๊ธฐ (2์ฃผ์ฐจ ๊ณตํ†ต ํ”ผ๋“œ๋ฐฑ๊ณผ ์ผ๋งฅ์ƒํ†ต) +4. ์˜ˆ์™ธ์— ๋Œ€ํ•œ ํ…Œ์ŠคํŠธ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋„๋ฉ”์ธ ๋กœ์ง์— ๋Œ€ํ•œ ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ์ถ”๊ฐ€ํ•˜์ž +5. `String` ํด๋ž˜์Šค ๋ฉ”์„œ๋“œ์™€ ๊ฐ™์€ ํ•จ์ˆ˜๋ฅผ ํ™œ์šฉํ•ด ์ฝ”๋“œ์˜ ๊ฐ€๋…์„ฑ์„ ๋†’์ด์ž From 0c1c09b2359609844781fb692fa294851609cbb0 Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Thu, 31 Oct 2024 18:07:17 +0900 Subject: [PATCH 02/28] =?UTF-8?q?chore:=20.gitignore=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 5dca701a77..da90f3cc38 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ build/ !**/src/main/** !**/src/test/** +*.class + ### STS ### .apt_generated .classpath From 7da7a15e8a7a18d8bf7c7721a233f26f6edad2d2 Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Thu, 31 Oct 2024 19:07:01 +0900 Subject: [PATCH 03/28] =?UTF-8?q?feat:=20=EA=B5=AC=EC=9E=85=ED=95=A0=20?= =?UTF-8?q?=EB=A1=9C=EB=98=90=20=EA=B8=88=EC=95=A1=20=EC=9E=85=EB=A0=A5=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/main/java/lotto/view/InputView.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/main/java/lotto/view/InputView.java diff --git a/README.md b/README.md index 548d024b64..f6ca85567a 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ ## ๐Ÿš€ ๊ตฌํ˜„ํ•  ๊ธฐ๋Šฅ ๋ชฉ๋ก ### 1. ์ž…๋ ฅ ์ฒ˜๋ฆฌ -- [ ] ์‚ฌ์šฉ์ž๊ฐ€ ๊ตฌ์ž…ํ•  ๋กœ๋˜์˜ ์ด ๊ธˆ์•ก์„ **1,000 ๋‹จ์œ„**๋กœ ์ž…๋ ฅ +- [x] ์‚ฌ์šฉ์ž๊ฐ€ ๊ตฌ์ž…ํ•  ๋กœ๋˜์˜ ์ด ๊ธˆ์•ก์„ **1,000 ๋‹จ์œ„**๋กœ ์ž…๋ ฅ - [ ] ๋‹น์ฒจ ๋ฒˆํ˜ธ์ธ 6๊ฐœ์˜ ์ˆซ์ž ์ž…๋ ฅ (๋ฒˆํ˜ธ๋Š” ์‰ผํ‘œ(,)๋กœ ๊ตฌ๋ถ„) - [ ] ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ์ธ 1๊ฐœ์˜ ์ˆซ์ž ์ž…๋ ฅ diff --git a/src/main/java/lotto/view/InputView.java b/src/main/java/lotto/view/InputView.java new file mode 100644 index 0000000000..85587d951f --- /dev/null +++ b/src/main/java/lotto/view/InputView.java @@ -0,0 +1,12 @@ +package lotto.view; + +import camp.nextstep.edu.missionutils.Console; + +public class InputView { + private static final String PURCHASE_AMOUNT_INPUT = "๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."; + + public String readPurchaseAmount() { + System.out.println(PURCHASE_AMOUNT_INPUT); + return Console.readLine().strip(); + } +} \ No newline at end of file From de1b1b38ea7642e5bf8055abb34035efb5a26eb5 Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Thu, 31 Oct 2024 19:10:13 +0900 Subject: [PATCH 04/28] =?UTF-8?q?feat:=20=EB=8B=B9=EC=B2=A8=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=9E=85=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/main/java/lotto/view/InputView.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f6ca85567a..3f0ddae3ae 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ ### 1. ์ž…๋ ฅ ์ฒ˜๋ฆฌ - [x] ์‚ฌ์šฉ์ž๊ฐ€ ๊ตฌ์ž…ํ•  ๋กœ๋˜์˜ ์ด ๊ธˆ์•ก์„ **1,000 ๋‹จ์œ„**๋กœ ์ž…๋ ฅ -- [ ] ๋‹น์ฒจ ๋ฒˆํ˜ธ์ธ 6๊ฐœ์˜ ์ˆซ์ž ์ž…๋ ฅ (๋ฒˆํ˜ธ๋Š” ์‰ผํ‘œ(,)๋กœ ๊ตฌ๋ถ„) +- [x] ๋‹น์ฒจ ๋ฒˆํ˜ธ์ธ 6๊ฐœ์˜ ์ˆซ์ž ์ž…๋ ฅ (๋ฒˆํ˜ธ๋Š” ์‰ผํ‘œ(,)๋กœ ๊ตฌ๋ถ„) - [ ] ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ์ธ 1๊ฐœ์˜ ์ˆซ์ž ์ž…๋ ฅ ### 2. ๋กœ๋˜ ๋ฒˆํ˜ธ ์ƒ์„ฑ diff --git a/src/main/java/lotto/view/InputView.java b/src/main/java/lotto/view/InputView.java index 85587d951f..79e5f0dae0 100644 --- a/src/main/java/lotto/view/InputView.java +++ b/src/main/java/lotto/view/InputView.java @@ -4,9 +4,15 @@ public class InputView { private static final String PURCHASE_AMOUNT_INPUT = "๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."; + private static final String WINNING_NUMBERS_INPUT = "๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”"; public String readPurchaseAmount() { System.out.println(PURCHASE_AMOUNT_INPUT); return Console.readLine().strip(); } + + public String readWinningNumber() { + System.out.println(WINNING_NUMBERS_INPUT); + return Console.readLine().strip(); + } } \ No newline at end of file From 0ea8b8b1fec83aa9fda8268c8951225a4d274de7 Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Thu, 31 Oct 2024 19:13:50 +0900 Subject: [PATCH 05/28] =?UTF-8?q?feat:=20=EB=B3=B4=EB=84=88=EC=8A=A4=20?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=EC=9E=85=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/main/java/lotto/view/InputView.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3f0ddae3ae..610cfabf88 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ ### 1. ์ž…๋ ฅ ์ฒ˜๋ฆฌ - [x] ์‚ฌ์šฉ์ž๊ฐ€ ๊ตฌ์ž…ํ•  ๋กœ๋˜์˜ ์ด ๊ธˆ์•ก์„ **1,000 ๋‹จ์œ„**๋กœ ์ž…๋ ฅ - [x] ๋‹น์ฒจ ๋ฒˆํ˜ธ์ธ 6๊ฐœ์˜ ์ˆซ์ž ์ž…๋ ฅ (๋ฒˆํ˜ธ๋Š” ์‰ผํ‘œ(,)๋กœ ๊ตฌ๋ถ„) -- [ ] ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ์ธ 1๊ฐœ์˜ ์ˆซ์ž ์ž…๋ ฅ +- [x] ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ์ธ 1๊ฐœ์˜ ์ˆซ์ž ์ž…๋ ฅ ### 2. ๋กœ๋˜ ๋ฒˆํ˜ธ ์ƒ์„ฑ - [ ] ์‚ฌ์šฉ์ž๊ฐ€ ๊ตฌ๋งคํ•œ ๊ธˆ์•ก์— ๋”ฐ๋ผ ํ•ด๋‹น ์ˆ˜๋Ÿ‰๋งŒํผ ๋กœ๋˜ ๋ฒˆํ˜ธ ์ƒ์„ฑ diff --git a/src/main/java/lotto/view/InputView.java b/src/main/java/lotto/view/InputView.java index 79e5f0dae0..906ff734a1 100644 --- a/src/main/java/lotto/view/InputView.java +++ b/src/main/java/lotto/view/InputView.java @@ -5,6 +5,7 @@ public class InputView { private static final String PURCHASE_AMOUNT_INPUT = "๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."; private static final String WINNING_NUMBERS_INPUT = "๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”"; + private static final String BONUS_NUMBER_INPUT = "๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."; public String readPurchaseAmount() { System.out.println(PURCHASE_AMOUNT_INPUT); @@ -15,4 +16,9 @@ public String readWinningNumber() { System.out.println(WINNING_NUMBERS_INPUT); return Console.readLine().strip(); } + + public String readBonusNumber() { + System.out.println(BONUS_NUMBER_INPUT); + return Console.readLine().strip(); + } } \ No newline at end of file From e7907765bae60046eee7d2641547176c09b9eeaf Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Mon, 4 Nov 2024 17:35:29 +0900 Subject: [PATCH 06/28] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EB=9E=AD?= =?UTF-8?q?=ED=81=AC=20Enum=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/enums/LottoRank.java | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/lotto/enums/LottoRank.java diff --git a/src/main/java/lotto/enums/LottoRank.java b/src/main/java/lotto/enums/LottoRank.java new file mode 100644 index 0000000000..a5c09a9105 --- /dev/null +++ b/src/main/java/lotto/enums/LottoRank.java @@ -0,0 +1,32 @@ +package lotto.enums; + +public enum LottoRank { + NO_MATCH(0, 0, false), + THREE_MATCH(3, 5_000, false), + FOUR_MATCH(4, 50_000, false), + FIVE_MATCH(5, 1_500_000, false), + FIVE_MATCH_WITH_BONUS(5, 30_000_000, true), + SIX_MATCH(6, 2_000_000_000, false); + + private final int matchCount; + private final int reward; + private final boolean matchesBonus; + + LottoRank(int matchCount, int reward, boolean matchesBonus) { + this.matchCount = matchCount; + this.reward = reward; + this.matchesBonus = matchesBonus; + } + + public int getMatchCount() { + return matchCount; + } + + public int getReward() { + return reward; + } + + public boolean matchesBonus() { + return matchesBonus; + } +} \ No newline at end of file From dd5b3377ebbebc3b2f467d801c0f7e506bf3b070 Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Mon, 4 Nov 2024 17:35:54 +0900 Subject: [PATCH 07/28] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EB=A9=94=EC=8B=9C=EC=A7=80=20Enum=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lotto/enums/LottoErrorMessage.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main/java/lotto/enums/LottoErrorMessage.java diff --git a/src/main/java/lotto/enums/LottoErrorMessage.java b/src/main/java/lotto/enums/LottoErrorMessage.java new file mode 100644 index 0000000000..a0bc4a3132 --- /dev/null +++ b/src/main/java/lotto/enums/LottoErrorMessage.java @@ -0,0 +1,23 @@ +package lotto.enums; + +public enum LottoErrorMessage { + EMPTY_OR_BLANK_INPUT("[ERROR] ์ž…๋ ฅ ๊ฐ’์€ ๊ณต๋ฐฑ์ด๋‚˜ ๋นˆ ๋ฌธ์ž์—ด์ผ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."), + NON_NUMERIC_INPUT("[ERROR] ์ž…๋ ฅ ๊ฐ’์€ ์ˆซ์ž ํ˜•์‹์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."), + INVALID_PURCHASE_AMOUNT("[ERROR] ๊ตฌ์ž… ๊ธˆ์•ก์€ 1,000์˜ ๋ฐฐ์ˆ˜์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."), + INVALID_DELIMITER("[ERROR] ๋‹น์ฒจ ๋ฒˆํ˜ธ๋Š” ์‰ผํ‘œ(,)๋กœ ๊ตฌ๋ถ„ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."), + INVALID_NUMBER_COUNT("[ERROR] ๋‹น์ฒจ ๋ฒˆํ˜ธ๋Š” 5๊ฐœ, ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋Š” 1๊ฐœ์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."), + EXCEEDS_MAX_PURCHASE_AMOUNT("[ERROR] ๊ตฌ์ž… ๊ธˆ์•ก์€ 100,000์›์„ ์ดˆ๊ณผํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."), + BELOW_MINIMUM_PURCHASE_AMOUNT("[ERROR] ๋กœ๋˜ ๊ตฌ๋งค ๊ฐœ์ˆ˜๋Š” 1๊ฐœ ์ด์ƒ์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."), + DUPLICATE_WINNING_NUMBERS("[ERROR] ๋‹น์ฒจ ๋ฒˆํ˜ธ์™€ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋Š” ์ค‘๋ณต๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."), + NUMBER_OUT_OF_RANGE("[ERROR] ๋‹น์ฒจ ๋ฒˆํ˜ธ์™€ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋Š” 1๋ถ€ํ„ฐ 45 ์‚ฌ์ด์˜ ์ˆซ์ž์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."); + + private final String message; + + LottoErrorMessage(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } +} \ No newline at end of file From 699b792b20bfd91361d1b1cc2b20a6db1a6c0e98 Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Mon, 4 Nov 2024 17:36:20 +0900 Subject: [PATCH 08/28] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/exception/LottoException.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/main/java/lotto/exception/LottoException.java diff --git a/src/main/java/lotto/exception/LottoException.java b/src/main/java/lotto/exception/LottoException.java new file mode 100644 index 0000000000..22e14dd219 --- /dev/null +++ b/src/main/java/lotto/exception/LottoException.java @@ -0,0 +1,10 @@ +package lotto.exception; + +import lotto.enums.LottoErrorMessage; + +public class LottoException extends IllegalArgumentException { + + public LottoException(LottoErrorMessage lottoErrorMessage) { + super(lottoErrorMessage.getMessage()); + } +} \ No newline at end of file From eef86deacf14b6f147bd503375eaa0fbc0d303ff Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Mon, 4 Nov 2024 23:49:02 +0900 Subject: [PATCH 09/28] =?UTF-8?q?fix:=20=EC=83=81=EC=88=98=20String=20?= =?UTF-8?q?=EB=82=B4=EC=9A=A9=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/view/InputView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/lotto/view/InputView.java b/src/main/java/lotto/view/InputView.java index 906ff734a1..33aa26c635 100644 --- a/src/main/java/lotto/view/InputView.java +++ b/src/main/java/lotto/view/InputView.java @@ -4,7 +4,7 @@ public class InputView { private static final String PURCHASE_AMOUNT_INPUT = "๊ตฌ์ž… ๊ธˆ์•ก์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."; - private static final String WINNING_NUMBERS_INPUT = "๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”"; + private static final String WINNING_NUMBERS_INPUT = "๋‹น์ฒจ ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."; private static final String BONUS_NUMBER_INPUT = "๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”."; public String readPurchaseAmount() { From 6c36c1b9c04ff8495dc0189244043bc15936eb1e Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Tue, 5 Nov 2024 00:06:33 +0900 Subject: [PATCH 10/28] =?UTF-8?q?fix:=20=EC=97=90=EB=9F=AC=20=EB=82=B4?= =?UTF-8?q?=EC=9A=A9=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/enums/LottoErrorMessage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/lotto/enums/LottoErrorMessage.java b/src/main/java/lotto/enums/LottoErrorMessage.java index a0bc4a3132..68cade2ac9 100644 --- a/src/main/java/lotto/enums/LottoErrorMessage.java +++ b/src/main/java/lotto/enums/LottoErrorMessage.java @@ -5,7 +5,7 @@ public enum LottoErrorMessage { NON_NUMERIC_INPUT("[ERROR] ์ž…๋ ฅ ๊ฐ’์€ ์ˆซ์ž ํ˜•์‹์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."), INVALID_PURCHASE_AMOUNT("[ERROR] ๊ตฌ์ž… ๊ธˆ์•ก์€ 1,000์˜ ๋ฐฐ์ˆ˜์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."), INVALID_DELIMITER("[ERROR] ๋‹น์ฒจ ๋ฒˆํ˜ธ๋Š” ์‰ผํ‘œ(,)๋กœ ๊ตฌ๋ถ„ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."), - INVALID_NUMBER_COUNT("[ERROR] ๋‹น์ฒจ ๋ฒˆํ˜ธ๋Š” 5๊ฐœ, ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋Š” 1๊ฐœ์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."), + INVALID_NUMBER_COUNT("[ERROR] ๋‹น์ฒจ ๋ฒˆํ˜ธ๋Š” 6๊ฐœ, ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋Š” 1๊ฐœ์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."), EXCEEDS_MAX_PURCHASE_AMOUNT("[ERROR] ๊ตฌ์ž… ๊ธˆ์•ก์€ 100,000์›์„ ์ดˆ๊ณผํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."), BELOW_MINIMUM_PURCHASE_AMOUNT("[ERROR] ๋กœ๋˜ ๊ตฌ๋งค ๊ฐœ์ˆ˜๋Š” 1๊ฐœ ์ด์ƒ์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."), DUPLICATE_WINNING_NUMBERS("[ERROR] ๋‹น์ฒจ ๋ฒˆํ˜ธ์™€ ๋ณด๋„ˆ์Šค ๋ฒˆํ˜ธ๋Š” ์ค‘๋ณต๋  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."), From 4caf4bb91d5970ee3ddf96b7e50b4ff2142d977b Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Tue, 5 Nov 2024 11:35:10 +0900 Subject: [PATCH 11/28] =?UTF-8?q?refactor:=20Lotto=20=ED=81=B4=EB=9E=98?= =?UTF-8?q?=EC=8A=A4=20=EC=9C=84=EC=B9=98=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/Lotto.java | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 src/main/java/lotto/Lotto.java diff --git a/src/main/java/lotto/Lotto.java b/src/main/java/lotto/Lotto.java deleted file mode 100644 index 88fc5cf12b..0000000000 --- a/src/main/java/lotto/Lotto.java +++ /dev/null @@ -1,20 +0,0 @@ -package lotto; - -import java.util.List; - -public class Lotto { - private final List numbers; - - public Lotto(List numbers) { - validate(numbers); - this.numbers = numbers; - } - - private void validate(List numbers) { - if (numbers.size() != 6) { - throw new IllegalArgumentException("[ERROR] ๋กœ๋˜ ๋ฒˆํ˜ธ๋Š” 6๊ฐœ์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค."); - } - } - - // TODO: ์ถ”๊ฐ€ ๊ธฐ๋Šฅ ๊ตฌํ˜„ -} From 0807de84fab9acf07e3f9e4377aba571151a0972 Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Tue, 5 Nov 2024 11:36:20 +0900 Subject: [PATCH 12/28] =?UTF-8?q?fix:=20=EA=B2=80=EC=A6=9D=20=EB=B6=80?= =?UTF-8?q?=EB=B6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/model/Lotto.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/main/java/lotto/model/Lotto.java diff --git a/src/main/java/lotto/model/Lotto.java b/src/main/java/lotto/model/Lotto.java new file mode 100644 index 0000000000..55f36c076e --- /dev/null +++ b/src/main/java/lotto/model/Lotto.java @@ -0,0 +1,18 @@ +package lotto.model; + +import lotto.validation.WinningNumberValidation; + +import java.util.List; + +public class Lotto { + private final List numbers; + + public Lotto(List numbers) { + WinningNumberValidation.validate(numbers); + this.numbers = numbers; + } + + public List getNumbers() { + return numbers; + } +} \ No newline at end of file From 588f6a9d31069f1d5c141f6b5653c2fc6e5f953c Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Tue, 5 Nov 2024 11:37:54 +0900 Subject: [PATCH 13/28] =?UTF-8?q?fix:=20=EB=8B=B9=EC=B2=A8=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=EC=99=80=20=EC=9D=BC=EC=B9=98=ED=95=98=EB=8A=94?= =?UTF-8?q?=EC=A7=80=20=EC=97=AC=EB=B6=80=20=EC=B0=BE=EB=8A=94=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EB=B0=8F=20=EC=88=AB=EC=9E=90=20=ED=91=9C=ED=98=84?= =?UTF-8?q?=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/enums/LottoRank.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/lotto/enums/LottoRank.java b/src/main/java/lotto/enums/LottoRank.java index a5c09a9105..9bbd11b005 100644 --- a/src/main/java/lotto/enums/LottoRank.java +++ b/src/main/java/lotto/enums/LottoRank.java @@ -2,11 +2,11 @@ public enum LottoRank { NO_MATCH(0, 0, false), - THREE_MATCH(3, 5_000, false), - FOUR_MATCH(4, 50_000, false), - FIVE_MATCH(5, 1_500_000, false), - FIVE_MATCH_WITH_BONUS(5, 30_000_000, true), - SIX_MATCH(6, 2_000_000_000, false); + THREE_MATCH(3, 5000, false), + FOUR_MATCH(4, 50000, false), + FIVE_MATCH(5, 1500000, false), + FIVE_MATCH_WITH_BONUS(5, 30000000, true), + SIX_MATCH(6, 2000000000, false); private final int matchCount; private final int reward; @@ -29,4 +29,13 @@ public int getReward() { public boolean matchesBonus() { return matchesBonus; } + + public static LottoRank matchCountAndRank(int matchCount, boolean bonusMatch) { + for (LottoRank rank : values()) { + if (rank.getMatchCount() == matchCount && rank.matchesBonus() == bonusMatch) { + return rank; + } + } + return NO_MATCH; + } } \ No newline at end of file From c0e3e9d7290fb409bb4419bd10cb88a84491b68e Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Tue, 5 Nov 2024 11:39:55 +0900 Subject: [PATCH 14/28] =?UTF-8?q?fix:=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=EC=97=90=EA=B2=8C=20=EC=9E=85=EB=A0=A5=EB=B0=9B=EC=9D=80=20?= =?UTF-8?q?=EB=A1=9C=EB=98=90=20=EA=B0=92=20=EA=B2=80=EC=A6=9D=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../validation/LottoPurchaseValidation.java | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/main/java/lotto/validation/LottoPurchaseValidation.java diff --git a/src/main/java/lotto/validation/LottoPurchaseValidation.java b/src/main/java/lotto/validation/LottoPurchaseValidation.java new file mode 100644 index 0000000000..bd0a06229d --- /dev/null +++ b/src/main/java/lotto/validation/LottoPurchaseValidation.java @@ -0,0 +1,58 @@ +package lotto.validation; + +import lotto.enums.LottoErrorMessage; +import lotto.exception.LottoException; + +public class LottoPurchaseValidation { + private static final int MIN_PURCHASE_AMOUNT = 1000; + private static final int MAX_PURCHASE_AMOUNT = 100000; + + public static int validatePurchaseAmount(String input) { + validateEmptyOrBlank(input); + validateNumericInput(input); + int purchaseAmount = parsePurchaseAmount(input); + validate(purchaseAmount); + return purchaseAmount; + } + + private static void validateNumericInput(String input) { + if (!input.matches("\\d+")) { + throw new LottoException(LottoErrorMessage.NON_NUMERIC_INPUT); + } + } + + private static void validate(int purchaseAmount) { + validateMinimumPurchaseAmount(purchaseAmount); + validateMaximumPurchaseAmount(purchaseAmount); + validateMultipleOfMinimum(purchaseAmount); + } + + private static int parsePurchaseAmount(String purchaseAmountInput) { + validateEmptyOrBlank(purchaseAmountInput); + return Integer.parseInt(purchaseAmountInput); + } + + private static void validateEmptyOrBlank(String purchaseAmountInput) { + if (purchaseAmountInput.strip().isBlank()) { + throw new LottoException(LottoErrorMessage.EMPTY_OR_BLANK_INPUT); + } + } + + private static void validateMinimumPurchaseAmount(int purchaseAmount) { + if (purchaseAmount < MIN_PURCHASE_AMOUNT) { + throw new LottoException(LottoErrorMessage.BELOW_MINIMUM_PURCHASE_AMOUNT); + } + } + + private static void validateMaximumPurchaseAmount(int purchaseAmount) { + if (purchaseAmount > MAX_PURCHASE_AMOUNT) { + throw new LottoException(LottoErrorMessage.EXCEEDS_MAX_PURCHASE_AMOUNT); + } + } + + private static void validateMultipleOfMinimum(int purchaseAmount) { + if (purchaseAmount % MIN_PURCHASE_AMOUNT != 0) { + throw new LottoException(LottoErrorMessage.INVALID_PURCHASE_AMOUNT); + } + } +} \ No newline at end of file From 1c915ba3868fdc87343d77c01a16ba9591505a34 Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Tue, 5 Nov 2024 11:40:04 +0900 Subject: [PATCH 15/28] =?UTF-8?q?fix:=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=EC=97=90=EA=B2=8C=20=EC=9E=85=EB=A0=A5=EB=B0=9B=EC=9D=80=20?= =?UTF-8?q?=EB=A1=9C=EB=98=90=20=EA=B0=92=20=EB=AA=A8=EB=8D=B8=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/model/LottoPurchase.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/main/java/lotto/model/LottoPurchase.java diff --git a/src/main/java/lotto/model/LottoPurchase.java b/src/main/java/lotto/model/LottoPurchase.java new file mode 100644 index 0000000000..71ea2a7e6d --- /dev/null +++ b/src/main/java/lotto/model/LottoPurchase.java @@ -0,0 +1,15 @@ +package lotto.model; + +public class LottoPurchase { + private static final int LOTTO_PRICE = 1000; + + private final int purchaseAmount; + + public LottoPurchase(int purchaseAmount) { + this.purchaseAmount = purchaseAmount; + } + + public int lottoCount() { + return purchaseAmount / LOTTO_PRICE; + } +} \ No newline at end of file From bf420a55b9f1af8015b4f67558ca466a1347e048 Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Tue, 5 Nov 2024 11:41:38 +0900 Subject: [PATCH 16/28] =?UTF-8?q?fix:=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=EC=97=90=EA=B2=8C=20=EC=9E=85=EB=A0=A5=EB=B0=9B=EC=9D=80=20?= =?UTF-8?q?=EB=8B=B9=EC=B2=A8=20=EB=B2=88=ED=98=B8=EC=99=80=20=EB=A1=9C?= =?UTF-8?q?=EB=98=90=20=EA=B2=80=EC=A6=9D=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lotto/validation/LottoValidation.java | 77 +++++++++++++++++++ .../validation/WinningNumberValidation.java | 43 +++++++++++ 2 files changed, 120 insertions(+) create mode 100644 src/main/java/lotto/validation/LottoValidation.java create mode 100644 src/main/java/lotto/validation/WinningNumberValidation.java diff --git a/src/main/java/lotto/validation/LottoValidation.java b/src/main/java/lotto/validation/LottoValidation.java new file mode 100644 index 0000000000..9a72486231 --- /dev/null +++ b/src/main/java/lotto/validation/LottoValidation.java @@ -0,0 +1,77 @@ +package lotto.validation; + +import lotto.enums.LottoErrorMessage; +import lotto.exception.LottoException; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +public class LottoValidation { + private static final int MIN_NUMBER = 1; + private static final int MAX_NUMBER = 45; + + public static List validateWinningNumbers(String winningNumbersInput) { + validateEmptyOrBlank(winningNumbersInput); + List winningNumbers = parseWinningNumbers(winningNumbersInput); + + validateDuplicateWinningNumbers(winningNumbers); + validateWinningNumberRange(winningNumbers); + + return winningNumbers; + } + + public static int validateBonusNumber(String bonusNumberInput) { + validateEmptyOrBlank(bonusNumberInput); + int bonusNumber = parseBonusNumber(bonusNumberInput); + bonusNumberRange(bonusNumber); + + return bonusNumber; + } + + public void validateBonusNumber(int bonusNumber, List winningNumbers) { + if (winningNumbers.contains(bonusNumber)) { + throw new LottoException(LottoErrorMessage.DUPLICATE_WINNING_NUMBERS); + } + } + + private static void bonusNumberRange(int bonusNumber) { + if (bonusNumber < MIN_NUMBER || bonusNumber > MAX_NUMBER) { + throw new LottoException(LottoErrorMessage.NUMBER_OUT_OF_RANGE); + } + } + + private static int parseBonusNumber(String bonusNumberInput) { + return Integer.parseInt(bonusNumberInput); + } + + private static void validateEmptyOrBlank(String input) { + if (input.strip().isBlank()) { + throw new LottoException(LottoErrorMessage.EMPTY_OR_BLANK_INPUT); + } + } + + private static List parseWinningNumbers(String winningNumbersInput) { + return List.of(winningNumbersInput.split(",")) + .stream() + .map(String::trim) + .map(Integer::parseInt) + .collect(Collectors.toList()); + } + + private static void validateDuplicateWinningNumbers(List winningNumbers) { + Set uniqueNumbers = new HashSet<>(winningNumbers); + if (uniqueNumbers.size() != winningNumbers.size()) { + throw new LottoException(LottoErrorMessage.DUPLICATE_WINNING_NUMBERS); + } + } + + private static void validateWinningNumberRange(List winningNumbers) { + for (int number : winningNumbers) { + if (number < MIN_NUMBER || number > MAX_NUMBER) { + throw new LottoException(LottoErrorMessage.NUMBER_OUT_OF_RANGE); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/lotto/validation/WinningNumberValidation.java b/src/main/java/lotto/validation/WinningNumberValidation.java new file mode 100644 index 0000000000..df5cc3852b --- /dev/null +++ b/src/main/java/lotto/validation/WinningNumberValidation.java @@ -0,0 +1,43 @@ +package lotto.validation; + +import lotto.enums.LottoErrorMessage; +import lotto.exception.LottoException; + +import java.util.HashSet; +import java.util.List; + +public class WinningNumberValidation { + private static final int MIN_NUMBER = 1; + private static final int MAX_NUMBER = 45; + private static final int WINNING_NUMBER_COUNT = 6; + + private WinningNumberValidation() { + } + + public static void validate(List numbers) { + validateNumberRange(numbers); + validateDuplicateNumbers(numbers); + validateWinningNumberCount(numbers); + } + + private static void validateNumberRange(List numbers) { + for (Integer number : numbers) { + if (number < MIN_NUMBER || number > MAX_NUMBER) { + throw new LottoException(LottoErrorMessage.NUMBER_OUT_OF_RANGE); + } + } + } + + private static void validateDuplicateNumbers(List numbers) { + HashSet uniqueNumbers = new HashSet<>(numbers); + if (uniqueNumbers.size() != numbers.size()) { + throw new LottoException(LottoErrorMessage.DUPLICATE_WINNING_NUMBERS); + } + } + + private static void validateWinningNumberCount(List numbers) { + if (numbers.size() != WINNING_NUMBER_COUNT) { + throw new LottoException(LottoErrorMessage.INVALID_NUMBER_COUNT); + } + } +} \ No newline at end of file From 79b6398e8591d036cc43ab2a2b302d7fe011453d Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Tue, 5 Nov 2024 11:59:41 +0900 Subject: [PATCH 17/28] =?UTF-8?q?fix:=20=EB=9E=9C=EB=8D=A4=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=83=9D=EC=84=B1=EB=90=98=EB=8A=94=20=EB=A1=9C?= =?UTF-8?q?=EB=98=90=20=EB=AA=A8=EB=8D=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/model/LottoTicket.java | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/java/lotto/model/LottoTicket.java diff --git a/src/main/java/lotto/model/LottoTicket.java b/src/main/java/lotto/model/LottoTicket.java new file mode 100644 index 0000000000..c481509a28 --- /dev/null +++ b/src/main/java/lotto/model/LottoTicket.java @@ -0,0 +1,25 @@ +package lotto.model; + +import camp.nextstep.edu.missionutils.Randoms; + +import java.util.List; + +public class LottoTicket { + private static final int MIN_LOTTO_NUM = 1; + private static final int MAX_LOTTO_NUM = 45; + private static final int MAIN_NUMBER_COUNT = 6; + + private final List lottoNumbers; + + public LottoTicket() { + this.lottoNumbers = createLottoNumbers(); + } + + private List createLottoNumbers() { + return Randoms.pickUniqueNumbersInRange(MIN_LOTTO_NUM, MAX_LOTTO_NUM, MAIN_NUMBER_COUNT); + } + + public List getLottoNumbers() { + return lottoNumbers; + } +} \ No newline at end of file From ae3cba187850f567fce6793aa236731558df8814 Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Tue, 5 Nov 2024 11:59:58 +0900 Subject: [PATCH 18/28] =?UTF-8?q?fix:=20=EB=A1=9C=EB=98=90=20=EB=A8=B8?= =?UTF-8?q?=EC=8B=A0=20=EB=AA=A8=EB=8D=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/model/LottoMachine.java | 34 +++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/lotto/model/LottoMachine.java diff --git a/src/main/java/lotto/model/LottoMachine.java b/src/main/java/lotto/model/LottoMachine.java new file mode 100644 index 0000000000..d9e69d701d --- /dev/null +++ b/src/main/java/lotto/model/LottoMachine.java @@ -0,0 +1,34 @@ +package lotto.model; + +import lotto.enums.LottoRank; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class LottoMachine { + private final Lotto winningLottoNumbers; + + public LottoMachine(Lotto winningLottoNumbers) { + this.winningLottoNumbers = winningLottoNumbers; + } + + public Map match(List tickets) { + Map result = new HashMap<>(); + + for (LottoTicket ticket : tickets) { + LottoRank rank = getRank(ticket.getLottoNumbers()); + result.put(rank, result.getOrDefault(rank, 0) + 1); + } + + return result; + } + + private LottoRank getRank(List lottoNumbers) { + int matchCount = (int) lottoNumbers.stream() + .filter(winningLottoNumbers.getNumbers()::contains) + .count(); + + return LottoRank.matchCountAndRank(matchCount, false); + } +} \ No newline at end of file From e7a5571ccf7fd6961d2ad5be6a7165a6ec2a6455 Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Tue, 5 Nov 2024 12:00:48 +0900 Subject: [PATCH 19/28] =?UTF-8?q?fix:=20=EC=9E=85=EB=A0=A5=EB=B0=9B?= =?UTF-8?q?=EC=9D=80=20=EA=B0=92=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lotto/service/LottoInputService.java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/main/java/lotto/service/LottoInputService.java diff --git a/src/main/java/lotto/service/LottoInputService.java b/src/main/java/lotto/service/LottoInputService.java new file mode 100644 index 0000000000..ea0cc0e01e --- /dev/null +++ b/src/main/java/lotto/service/LottoInputService.java @@ -0,0 +1,47 @@ +package lotto.service; + +import lotto.exception.LottoException; +import lotto.model.Lotto; +import lotto.model.LottoBonusNumber; +import lotto.validation.LottoPurchaseValidation; +import lotto.validation.LottoValidation; +import lotto.view.InputView; + +import java.util.List; + +public class LottoInputService { + private final InputView inputView; + + public LottoInputService(InputView inputView) { + this.inputView = inputView; + } + + public int purchaseAmount() { + while (true) { + try { + String input = inputView.readPurchaseAmount(); + return LottoPurchaseValidation.validatePurchaseAmount(input); + } catch (LottoException exception) { + System.out.println(exception.getMessage()); + } + } + } + + public Lotto winningLotto() { + String winningNumbersInput = inputView.readWinningNumber(); + List winningNumbers = LottoValidation.validateWinningNumbers(winningNumbersInput); + return new Lotto(winningNumbers); + } + + public LottoBonusNumber bonusNumber(List winningNumbers) { + while (true) { + try { + String bonusNumberInput = inputView.readBonusNumber(); + int bonusNumber = LottoValidation.validateBonusNumber(bonusNumberInput); + return new LottoBonusNumber(bonusNumber, winningNumbers); + } catch (LottoException exception) { + System.out.println(exception.getMessage()); + } + } + } +} From 8a94c7ed5c16582259caeb6b3c952838a476abda Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Tue, 5 Nov 2024 12:01:19 +0900 Subject: [PATCH 20/28] =?UTF-8?q?fix:=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=EC=97=90=EA=B2=8C=20=EC=9E=85=EB=A0=A5=EB=B0=9B=EC=9D=80=20?= =?UTF-8?q?=EB=B3=B4=EB=84=88=EC=8A=A4=20=EB=B2=88=ED=98=B8=20=EB=AA=A8?= =?UTF-8?q?=EB=8D=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lotto/model/LottoBonusNumber.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/java/lotto/model/LottoBonusNumber.java diff --git a/src/main/java/lotto/model/LottoBonusNumber.java b/src/main/java/lotto/model/LottoBonusNumber.java new file mode 100644 index 0000000000..446758365f --- /dev/null +++ b/src/main/java/lotto/model/LottoBonusNumber.java @@ -0,0 +1,31 @@ +package lotto.model; + +import lotto.enums.LottoErrorMessage; +import lotto.exception.LottoException; + +import java.util.List; + +public class LottoBonusNumber { + private static final int MIN_NUMBER = 1; + private static final int MAX_NUMBER = 45; + + private final int bonusNumber; + + public LottoBonusNumber(int bonusNumber, List winningNumbers) { + validateBonusNumber(bonusNumber, winningNumbers); + this.bonusNumber = bonusNumber; + } + + private void validateBonusNumber(int bonusNumber, List winningNumbers) { + if (bonusNumber < MIN_NUMBER || bonusNumber > MAX_NUMBER) { + throw new LottoException(LottoErrorMessage.NUMBER_OUT_OF_RANGE); + } + if (winningNumbers.contains(bonusNumber)) { + throw new LottoException(LottoErrorMessage.DUPLICATE_WINNING_NUMBERS); + } + } + + public int getBonusNumber() { + return bonusNumber; + } +} \ No newline at end of file From a64206fa2baf7874511f705f76798a9d26c91320 Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Tue, 5 Nov 2024 12:02:19 +0900 Subject: [PATCH 21/28] =?UTF-8?q?fix:=20=EB=A1=9C=EB=98=90=20=ED=8B=B0?= =?UTF-8?q?=EC=BC=93=20=EA=B0=9C=EC=88=98=EB=A7=8C=ED=81=BC=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=ED=95=98=EB=8A=94=20=EC=84=9C=EB=B9=84=EC=8A=A4=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lotto/service/LottoTicketService.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/lotto/service/LottoTicketService.java diff --git a/src/main/java/lotto/service/LottoTicketService.java b/src/main/java/lotto/service/LottoTicketService.java new file mode 100644 index 0000000000..8e9530778a --- /dev/null +++ b/src/main/java/lotto/service/LottoTicketService.java @@ -0,0 +1,16 @@ +package lotto.service; + +import lotto.model.LottoTicket; + +import java.util.ArrayList; +import java.util.List; + +public class LottoTicketService { + public List createLottoTickets(int count) { + List tickets = new ArrayList<>(); + for (int i = 0; i < count; i++) { + tickets.add(new LottoTicket()); + } + return tickets; + } +} \ No newline at end of file From 58d017d9a76c1f2f8f4427e18b0a5c1ba4510d47 Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Tue, 5 Nov 2024 12:03:36 +0900 Subject: [PATCH 22/28] =?UTF-8?q?fix:=20=EA=B5=AC=EC=9E=85=ED=95=9C=20?= =?UTF-8?q?=EB=A1=9C=EB=98=90=20=EC=B6=9C=EB=A0=A5=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/view/OutputView.java | 71 ++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/main/java/lotto/view/OutputView.java diff --git a/src/main/java/lotto/view/OutputView.java b/src/main/java/lotto/view/OutputView.java new file mode 100644 index 0000000000..6e6d66bea7 --- /dev/null +++ b/src/main/java/lotto/view/OutputView.java @@ -0,0 +1,71 @@ +package lotto.view; + +import lotto.enums.LottoRank; +import lotto.model.LottoTicket; + +import java.text.NumberFormat; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +public class OutputView { + private static final String PURCHASE_OUTPUT = "%d๊ฐœ๋ฅผ ๊ตฌ๋งคํ–ˆ์Šต๋‹ˆ๋‹ค."; + private static final String WINNING_HEADER = "๋‹น์ฒจ ํ†ต๊ณ„"; + private static final String OUTPUT_SEPARATOR = "---"; + private static final String MATCH_OUTPUT_FORMAT = "%d๊ฐœ ์ผ์น˜%s (%s์›) - %d๊ฐœ%n"; + private static final String BONUS_MATCH_OUTPUT = ", ๋ณด๋„ˆ์Šค ๋ณผ ์ผ์น˜"; + private static final String YIELD_OUTPUT = "์ด ์ˆ˜์ต๋ฅ ์€ %.1f%%์ž…๋‹ˆ๋‹ค."; + + private static final int MATCH_THRESHOLD = 3; + private static final Locale KOREAN_LOCALE = Locale.KOREA; + + public void displayTickets(List tickets) { + System.out.printf(PURCHASE_OUTPUT + "%n", tickets.size()); + for (LottoTicket ticket : tickets) { + System.out.println(ticket.getLottoNumbers()); + } + } + + public void displayResults(Map results, int purchaseAmount) { + displayStatisticsHeader(); + displayAllRanks(results); + displayYield(results, purchaseAmount); + } + + private void displayStatisticsHeader() { + System.out.println(WINNING_HEADER); + System.out.println(OUTPUT_SEPARATOR); + } + + private void displayAllRanks(Map results) { + for (LottoRank rank : LottoRank.values()) { + displayRankResult(rank, results.getOrDefault(rank, 0)); + } + } + + private void displayRankResult(LottoRank rank, int count) { + if (rank.getMatchCount() >= MATCH_THRESHOLD || rank == LottoRank.FOUR_MATCH || rank == LottoRank.FIVE_MATCH) { + System.out.printf( + MATCH_OUTPUT_FORMAT, + rank.getMatchCount(), + rank.matchesBonus() ? BONUS_MATCH_OUTPUT : "", + formatPrizeMoney(rank.getReward()), + count + ); + } + } + + private void displayYield(Map results, int purchaseAmount) { + long totalPrizeMoney = results.entrySet().stream() + .mapToLong(entry -> entry.getKey().getReward() * entry.getValue()) + .sum(); + double yield = (double) totalPrizeMoney / purchaseAmount * 100; + + System.out.printf(YIELD_OUTPUT + "%n", yield); + } + + private String formatPrizeMoney(long prizeMoney) { // ๊ฐ€๋…์„ฑ์„ ์œ„ํ•œ ํฌ๋งทํŒ… + NumberFormat numberFormat = NumberFormat.getInstance(KOREAN_LOCALE); + return numberFormat.format(prizeMoney); + } +} \ No newline at end of file From 547a2713b6e79b3ef52507050201589f6ced9b6d Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Tue, 5 Nov 2024 12:03:41 +0900 Subject: [PATCH 23/28] =?UTF-8?q?fix:=20=EB=A1=9C=EB=98=90=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=20=EC=B6=9C=EB=A0=A5=ED=95=98=EB=8A=94=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lotto/service/LottoResultService.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/main/java/lotto/service/LottoResultService.java diff --git a/src/main/java/lotto/service/LottoResultService.java b/src/main/java/lotto/service/LottoResultService.java new file mode 100644 index 0000000000..916cd4caef --- /dev/null +++ b/src/main/java/lotto/service/LottoResultService.java @@ -0,0 +1,28 @@ +package lotto.service; + +import lotto.enums.LottoRank; +import lotto.model.Lotto; +import lotto.model.LottoBonusNumber; +import lotto.model.LottoMachine; +import lotto.model.LottoTicket; +import lotto.view.OutputView; + +import java.util.List; +import java.util.Map; + +public class LottoResultService { + private final OutputView outputView; + + public LottoResultService(OutputView outputView) { + this.outputView = outputView; + } + + public void displayResults(Map results, int purchaseAmount) { + outputView.displayResults(results, purchaseAmount); + } + + public Map calculateResults(List tickets, Lotto winningLotto, LottoBonusNumber bonusNumber) { + LottoMachine lottoMachine = new LottoMachine(winningLotto); + return lottoMachine.match(tickets); + } +} \ No newline at end of file From 94c32911f51a193d15cf4616192b8ed407b6048b Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Tue, 5 Nov 2024 12:04:20 +0900 Subject: [PATCH 24/28] =?UTF-8?q?fix:=20=EC=82=AC=EC=9A=A9=EC=9E=90?= =?UTF-8?q?=EA=B0=80=20=EB=84=A3=EC=9D=80=20=EA=B0=92=EC=9D=B4=20=EC=9C=A0?= =?UTF-8?q?=ED=9A=A8=ED=95=98=EC=A7=80=20=EC=95=8A=EC=9C=BC=EB=A9=B4=20?= =?UTF-8?q?=EB=8B=A4=EC=8B=9C=20=EC=9E=85=EB=A0=A5=EB=B0=9B=EB=8A=94=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/service/LottoService.java | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/main/java/lotto/service/LottoService.java diff --git a/src/main/java/lotto/service/LottoService.java b/src/main/java/lotto/service/LottoService.java new file mode 100644 index 0000000000..22154fa81a --- /dev/null +++ b/src/main/java/lotto/service/LottoService.java @@ -0,0 +1,75 @@ +package lotto.service; + +import lotto.enums.LottoRank; +import lotto.exception.LottoException; +import lotto.model.*; +import lotto.validation.LottoPurchaseValidation; +import lotto.validation.LottoValidation; +import lotto.view.InputView; +import lotto.view.OutputView; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class LottoService { + private final InputView inputView; + private final OutputView outputView; + + public LottoService(InputView inputView, OutputView outputView) { + this.inputView = inputView; + this.outputView = outputView; + } + + public void run() { + int purchaseAmount = purchaseAmount(); + LottoPurchase lottoPurchase = new LottoPurchase(purchaseAmount); + List tickets = createLottoTickets(lottoPurchase.lottoCount()); + + outputView.displayTickets(tickets); + + Lotto winningLotto = winningNumbers(); + LottoBonusNumber bonusNumber = getBonusNumber(winningLotto.getNumbers()); + LottoMachine lottoMachine = new LottoMachine(winningLotto); + + Map results = lottoMachine.match(tickets); + outputView.displayResults(results, purchaseAmount); + } + + private int purchaseAmount() { + while (true) { + try { + String input = inputView.readPurchaseAmount(); + return LottoPurchaseValidation.validatePurchaseAmount(input); + } catch (LottoException exception) { + System.out.println(exception.getMessage()); + } + } + } + + private List createLottoTickets(int ticketCount) { + List tickets = new ArrayList<>(); + for (int i = 0; i < ticketCount; i++) { + tickets.add(new LottoTicket()); + } + return tickets; + } + + private Lotto winningNumbers() { + String winningNumbersInput = inputView.readWinningNumber(); + List winningNumbers = LottoValidation.validateWinningNumbers(winningNumbersInput); + return new Lotto(winningNumbers); + } + + private LottoBonusNumber getBonusNumber(List winningNumbers) { + while (true) { + try { + String bonusNumberInput = inputView.readBonusNumber(); + int bonusNumber = LottoValidation.validateBonusNumber(bonusNumberInput); + return new LottoBonusNumber(bonusNumber, winningNumbers); + } catch (LottoException exception) { + System.out.println(exception.getMessage()); + } + } + } +} From 855ed2029cd0a40a407767ef21481b037ff05a62 Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Tue, 5 Nov 2024 12:04:44 +0900 Subject: [PATCH 25/28] =?UTF-8?q?fix:=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lotto/controller/LottoController.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/main/java/lotto/controller/LottoController.java diff --git a/src/main/java/lotto/controller/LottoController.java b/src/main/java/lotto/controller/LottoController.java new file mode 100644 index 0000000000..d99ccf263d --- /dev/null +++ b/src/main/java/lotto/controller/LottoController.java @@ -0,0 +1,17 @@ +package lotto.controller; + +import lotto.service.LottoService; +import lotto.view.InputView; +import lotto.view.OutputView; + +public class LottoController { + private final LottoService lottoService; + + public LottoController(InputView inputView, OutputView outputView) { + this.lottoService = new LottoService(inputView, outputView); + } + + public void run() { + lottoService.run(); + } +} \ No newline at end of file From 49aa69d87f7a030c45a4d6a21a464bb38737952c Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Tue, 5 Nov 2024 12:05:06 +0900 Subject: [PATCH 26/28] =?UTF-8?q?fix:=20=EC=8B=9C=EC=9E=91=ED=95=98?= =?UTF-8?q?=EB=8A=94=20Application=EC=97=90=EC=84=9C=20=EC=BB=A8=ED=8A=B8?= =?UTF-8?q?=EB=A1=A4=EB=9F=AC=20=EB=B6=88=EB=9F=AC=EC=98=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/Application.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java index d190922ba4..9924708541 100644 --- a/src/main/java/lotto/Application.java +++ b/src/main/java/lotto/Application.java @@ -1,7 +1,14 @@ package lotto; +import lotto.controller.LottoController; +import lotto.view.InputView; +import lotto.view.OutputView; + public class Application { public static void main(String[] args) { - // TODO: ํ”„๋กœ๊ทธ๋žจ ๊ตฌํ˜„ + InputView inputView = new InputView(); + OutputView outputView = new OutputView(); + LottoController lottoController = new LottoController(inputView, outputView); + lottoController.run(); } -} +} \ No newline at end of file From 537892903add018e41b961f01c25a65c69d51f81 Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Tue, 5 Nov 2024 12:09:35 +0900 Subject: [PATCH 27/28] =?UTF-8?q?refactor:=20=EC=95=88=20=EC=93=B0?= =?UTF-8?q?=EB=8A=94=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lotto/service/LottoInputService.java | 47 ------------------- .../lotto/service/LottoResultService.java | 28 ----------- .../lotto/service/LottoTicketService.java | 16 ------- 3 files changed, 91 deletions(-) delete mode 100644 src/main/java/lotto/service/LottoInputService.java delete mode 100644 src/main/java/lotto/service/LottoResultService.java delete mode 100644 src/main/java/lotto/service/LottoTicketService.java diff --git a/src/main/java/lotto/service/LottoInputService.java b/src/main/java/lotto/service/LottoInputService.java deleted file mode 100644 index ea0cc0e01e..0000000000 --- a/src/main/java/lotto/service/LottoInputService.java +++ /dev/null @@ -1,47 +0,0 @@ -package lotto.service; - -import lotto.exception.LottoException; -import lotto.model.Lotto; -import lotto.model.LottoBonusNumber; -import lotto.validation.LottoPurchaseValidation; -import lotto.validation.LottoValidation; -import lotto.view.InputView; - -import java.util.List; - -public class LottoInputService { - private final InputView inputView; - - public LottoInputService(InputView inputView) { - this.inputView = inputView; - } - - public int purchaseAmount() { - while (true) { - try { - String input = inputView.readPurchaseAmount(); - return LottoPurchaseValidation.validatePurchaseAmount(input); - } catch (LottoException exception) { - System.out.println(exception.getMessage()); - } - } - } - - public Lotto winningLotto() { - String winningNumbersInput = inputView.readWinningNumber(); - List winningNumbers = LottoValidation.validateWinningNumbers(winningNumbersInput); - return new Lotto(winningNumbers); - } - - public LottoBonusNumber bonusNumber(List winningNumbers) { - while (true) { - try { - String bonusNumberInput = inputView.readBonusNumber(); - int bonusNumber = LottoValidation.validateBonusNumber(bonusNumberInput); - return new LottoBonusNumber(bonusNumber, winningNumbers); - } catch (LottoException exception) { - System.out.println(exception.getMessage()); - } - } - } -} diff --git a/src/main/java/lotto/service/LottoResultService.java b/src/main/java/lotto/service/LottoResultService.java deleted file mode 100644 index 916cd4caef..0000000000 --- a/src/main/java/lotto/service/LottoResultService.java +++ /dev/null @@ -1,28 +0,0 @@ -package lotto.service; - -import lotto.enums.LottoRank; -import lotto.model.Lotto; -import lotto.model.LottoBonusNumber; -import lotto.model.LottoMachine; -import lotto.model.LottoTicket; -import lotto.view.OutputView; - -import java.util.List; -import java.util.Map; - -public class LottoResultService { - private final OutputView outputView; - - public LottoResultService(OutputView outputView) { - this.outputView = outputView; - } - - public void displayResults(Map results, int purchaseAmount) { - outputView.displayResults(results, purchaseAmount); - } - - public Map calculateResults(List tickets, Lotto winningLotto, LottoBonusNumber bonusNumber) { - LottoMachine lottoMachine = new LottoMachine(winningLotto); - return lottoMachine.match(tickets); - } -} \ No newline at end of file diff --git a/src/main/java/lotto/service/LottoTicketService.java b/src/main/java/lotto/service/LottoTicketService.java deleted file mode 100644 index 8e9530778a..0000000000 --- a/src/main/java/lotto/service/LottoTicketService.java +++ /dev/null @@ -1,16 +0,0 @@ -package lotto.service; - -import lotto.model.LottoTicket; - -import java.util.ArrayList; -import java.util.List; - -public class LottoTicketService { - public List createLottoTickets(int count) { - List tickets = new ArrayList<>(); - for (int i = 0; i < count; i++) { - tickets.add(new LottoTicket()); - } - return tickets; - } -} \ No newline at end of file From c6a097e3ae40094f7496574e7f5d47513c23d8b1 Mon Sep 17 00:00:00 2001 From: aprilnineteen Date: Tue, 5 Nov 2024 12:10:08 +0900 Subject: [PATCH 28/28] =?UTF-8?q?fix:=20=EC=95=88=20=EC=93=B0=EB=8A=94=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/service/LottoService.java | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/main/java/lotto/service/LottoService.java b/src/main/java/lotto/service/LottoService.java index 22154fa81a..4eb1d4dbe3 100644 --- a/src/main/java/lotto/service/LottoService.java +++ b/src/main/java/lotto/service/LottoService.java @@ -29,7 +29,6 @@ public void run() { outputView.displayTickets(tickets); Lotto winningLotto = winningNumbers(); - LottoBonusNumber bonusNumber = getBonusNumber(winningLotto.getNumbers()); LottoMachine lottoMachine = new LottoMachine(winningLotto); Map results = lottoMachine.match(tickets); @@ -60,16 +59,4 @@ private Lotto winningNumbers() { List winningNumbers = LottoValidation.validateWinningNumbers(winningNumbersInput); return new Lotto(winningNumbers); } - - private LottoBonusNumber getBonusNumber(List winningNumbers) { - while (true) { - try { - String bonusNumberInput = inputView.readBonusNumber(); - int bonusNumber = LottoValidation.validateBonusNumber(bonusNumberInput); - return new LottoBonusNumber(bonusNumber, winningNumbers); - } catch (LottoException exception) { - System.out.println(exception.getMessage()); - } - } - } }