From 545ebfb889de3e98278af506f24258c153ba8c40 Mon Sep 17 00:00:00 2001
From: d11210920 <109078590+d11210920@users.noreply.github.com>
Date: Sat, 8 Jul 2023 01:47:54 +0900
Subject: [PATCH 01/19] Update README.md
---
README.md | 207 +-----------------------------------------------------
1 file changed, 3 insertions(+), 204 deletions(-)
diff --git a/README.md b/README.md
index 81b03cdba2..77bc83c372 100644
--- a/README.md
+++ b/README.md
@@ -1,207 +1,6 @@
-# ๊ณผ์ - ๋ก๋
+# Lotto
-## ๐ ์งํ ๋ฐฉ์
-- ๊ณผ์ ๋ **๊ธฐ๋ฅ ์๊ตฌ ์ฌํญ, ํ๋ก๊ทธ๋๋ฐ ์๊ตฌ ์ฌํญ, ๊ณผ์ ์งํ ์๊ตฌ ์ฌํญ** ์ธ ๊ฐ์ง๋ก ๊ตฌ์ฑ๋์ด ์๋ค.
-- ์ธ ๊ฐ์ ์๊ตฌ ์ฌํญ์ ๋ง์กฑํ๊ธฐ ์ํด ๋
ธ๋ ฅํ๋ค. ํนํ ๊ธฐ๋ฅ์ ๊ตฌํํ๊ธฐ ์ ์ ๊ธฐ๋ฅ ๋ชฉ๋ก์ ๋ง๋ค๊ณ , ๊ธฐ๋ฅ ๋จ์๋ก ์ปค๋ฐ ํ๋ ๋ฐฉ์์ผ๋ก ์งํํ๋ค.
-- ๊ธฐ๋ฅ ์๊ตฌ ์ฌํญ์ ๊ธฐ์ฌ๋์ง ์์ ๋ด์ฉ์ ์ค์ค๋ก ํ๋จํ์ฌ ๊ตฌํํ๋ค.
+1. Lotto ์ํ์ ๋ณต์ฌํด์์ ์ฐ์น ๋ณต๊ถ๊ณผ ๋น๊ตํ์ฌ ๋ช๊ฐ์ ์ซ์๊ฐ ๋ง์๋์ง, ๋ณด๋์ค๊ฐ ์ผ์นํ๋์ง๋ฅผ ํ์ธํ๋ ๋ก์ง๊ณผ, Lotto์ ๊ฐ์ ์ถ๋ ฅํ๋ ๋ก์ง์ ๊ตฌํ.
----
-
-## ๐ ๊ณผ์ ์งํ ๋ฐ ์ ์ถ ๋ฐฉ๋ฒ
-
-- ๊ณผ์ ๋ [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 ์์ฑํ๋ฉด๋จ
-
-
-
-### ํ
์คํธ ์คํ ๊ฐ์ด๋
-
-- ํฐ๋ฏธ๋์์ `java -version`์ ์คํํ์ฌ Java ๋ฒ์ ์ด 14์ธ์ง ํ์ธํ๋ค. ๋๋ Eclipse ๋๋ IntelliJ IDEA์ ๊ฐ์ IDE์์ Java 14๋ก ์คํ๋๋์ง ํ์ธํ๋ค.
-- ํฐ๋ฏธ๋์์ Mac ๋๋ Linux ์ฌ์ฉ์์ ๊ฒฝ์ฐ `./gradlew clean test` ๋ช
๋ น์ ์คํ ํ๊ณ ,
- Windows ์ฌ์ฉ์์ ๊ฒฝ์ฐ `gradlew.bat clean test` ๋ช
๋ น์ ์คํํ ๋ ๋์ ํ๋์ง ๋ง ํ์ธ(ํ
์คํธ๋ ์คํจ).
-
----
-
-## ๐ ๊ธฐ๋ฅ ์๊ตฌ ์ฌํญ
-
-๋ก๋ ๊ฒ์ ๊ธฐ๋ฅ์ ๊ตฌํํด์ผ ํ๋ค. ๋ก๋ ๊ฒ์์ ์๋์ ๊ฐ์ ๊ท์น์ผ๋ก ์งํ๋๋ค.
-
-```
-- ๋ก๋ ๋ฒํธ์ ์ซ์ ๋ฒ์๋ 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]"๋ก ์์ํ๋ ์๋ฌ ๋ฉ์์ง๋ฅผ ์ถ๋ ฅ ํ ์ข
๋ฃํ๋ค.
-
-## โ๐ป ์
์ถ๋ ฅ ์๊ตฌ์ฌํญ
-
-### โจ๏ธ ์
๋ ฅ
-
-- ๋ก๋ ๊ตฌ์
๊ธ์ก์ ์
๋ ฅ ๋ฐ๋๋ค. ๊ตฌ์
๊ธ์ก์ 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: ์ถ๊ฐ ๊ธฐ๋ฅ ๊ตฌํ
-}
-```
+2.
From 3b21c1a25f856abd34440b13ec68f78eb487f965 Mon Sep 17 00:00:00 2001
From: d11210920 <109078590+d11210920@users.noreply.github.com>
Date: Sat, 8 Jul 2023 02:28:45 +0900
Subject: [PATCH 02/19] Update README.md
---
README.md | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 59 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index 77bc83c372..208116daa2 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,63 @@
# Lotto
+1. Lotto ์ํ์ ๋ณต์ฌํด์จ๋ค.
+2. ์ฐ์น ๋ณต๊ถ๊ณผ ๋น๊ตํ์ฌ ๋ช๊ฐ์ ์ซ์๊ฐ ๋ง์๋์ง ํ์ธํ๋ ๋ก์ง์ ๋ง๋ ๋ค.
+3. ๋ณด๋์ค๊ฐ ์ผ์นํ๋์ง๋ฅผ ํ์ธํ๋ ๋ก์ง์ ๋ง๋ ๋ค.
+4. Lotto์ ๊ฐ์ ์ถ๋ ฅํ๋ ๋ก์ง์ ๊ตฌํ.
+
+# WinningLotto
+
+1. ์ฐ์น ๋ณต๊ถ์ ์ ๋ณด๋ฅผ ์ ์ฅํ๋ค.
+2. ์ฌ๊ธฐ์ Lotto์ ๊ฐ์ฒด์, bonus ์ ๋ณด๋ฅผ ์ ์ฅํ๋ค.
+
+# ENUM
+
+1. Lotto์ ๋ํ ์์๊ฐ๋ค์ ์ ์ํ๋ class RandomRange ์์ฑ
+2. ์๊ธ์ ๋ํ ์์๊ฐ๋ค์ ์ ์ํ๋ class Prize ์์ฑ
+
+# CheckException
+
+1. winningLotto๋ฅผ ์
๋ ฅ๋ฐ์๋, ์๋ชป ๋ฐ๋์ง ํ์ธํ๊ธฐ์ํ ์ธํฐํ์ด์ค
+
+# CheckExceptionImpl
+
+1. CheckException์ธํฐํ์ด์ค๋ฅผ ๊ตฌํํ ํด๋์ค
+
+# BuyMoney
+
+1. ๊ตฌ๋งค ๊ธ์ก์ ์
๋ ฅ๋ฐ๊ณ , ํ์์ ๊ฒ์ฆํ๋ค.
+2. ๊ธ์ก์ด ์
๋ ฅ๋๋ฉด ๊ธ์ก์ผ๋ก ๋ช์ฅ์ ๊ตฌ๋งคํ๋์ง ์ถ๋ ฅํ๋ค.
+
+# InputWinningLotto
+
+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. Lotto ์ํ์ ๋ณต์ฌํด์์ ์ฐ์น ๋ณต๊ถ๊ณผ ๋น๊ตํ์ฌ ๋ช๊ฐ์ ์ซ์๊ฐ ๋ง์๋์ง, ๋ณด๋์ค๊ฐ ์ผ์นํ๋์ง๋ฅผ ํ์ธํ๋ ๋ก์ง๊ณผ, Lotto์ ๊ฐ์ ์ถ๋ ฅํ๋ ๋ก์ง์ ๊ตฌํ.
-2.
From 8f289580168603a3a201f641e9513e65385e4776 Mon Sep 17 00:00:00 2001
From: gimdongha
Date: Sat, 8 Jul 2023 11:15:12 +0900
Subject: [PATCH 03/19] feat(Lotto):add Lotto class to save lotto lists
---
src/main/java/lotto/lotto/Lotto.java | 42 ++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
create mode 100644 src/main/java/lotto/lotto/Lotto.java
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
From b9fc5fe206b6f140cbb469c017ce15fd65eba08e Mon Sep 17 00:00:00 2001
From: gimdongha
Date: Sat, 8 Jul 2023 11:15:41 +0900
Subject: [PATCH 04/19] feat(WinningLotto):add WinningLotto class to save
WinLotto
---
src/main/java/lotto/lotto/WinningLotto.java | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
create mode 100644 src/main/java/lotto/lotto/WinningLotto.java
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;
+ }
+}
From 0483ff309158adf52980d2680d59a91896118676 Mon Sep 17 00:00:00 2001
From: gimdongha
Date: Sat, 8 Jul 2023 11:16:26 +0900
Subject: [PATCH 05/19] feat(Prize):add ENUM class to save constant related
prize
---
src/main/java/lotto/numbers/Prize.java | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
create mode 100644 src/main/java/lotto/numbers/Prize.java
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;
+ }
+
+}
From 1346471df8bae5072e48bad7b4b97cbfbb9ecd17 Mon Sep 17 00:00:00 2001
From: gimdongha
Date: Sat, 8 Jul 2023 11:16:43 +0900
Subject: [PATCH 06/19] feat(RandomRange):add ENUM class to save constant
related lotto Range
---
src/main/java/lotto/numbers/RandomRange.java | 15 +++++++++++++++
1 file changed, 15 insertions(+)
create mode 100644 src/main/java/lotto/numbers/RandomRange.java
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;
+ }
+}
From 0b727129b01298d6896acbd856612f0d20882c09 Mon Sep 17 00:00:00 2001
From: gimdongha
Date: Sat, 8 Jul 2023 11:17:20 +0900
Subject: [PATCH 07/19] feat(CheckException):add CheckException interface
---
src/main/java/lotto/checkexception/CheckException.java | 5 +++++
1 file changed, 5 insertions(+)
create mode 100644 src/main/java/lotto/checkexception/CheckException.java
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);
+}
From 4d38c3acabd9e890fb047197c86e57053298f134 Mon Sep 17 00:00:00 2001
From: gimdongha
Date: Sat, 8 Jul 2023 11:17:40 +0900
Subject: [PATCH 08/19] feat(CheckExceptionImpl):add CheckExceptionImpl class
to check Exception
---
.../lotto/checkexception/CheckExceptionImpl.java | 12 ++++++++++++
1 file changed, 12 insertions(+)
create mode 100644 src/main/java/lotto/checkexception/CheckExceptionImpl.java
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 ์ฌ์ด์ ์ซ์์ฌ์ผ ํฉ๋๋ค.");
+ }
+ }
+
+}
From e5a7bd7240f98d75c1d87702757009d5a94f9b0a Mon Sep 17 00:00:00 2001
From: gimdongha
Date: Sat, 8 Jul 2023 11:18:45 +0900
Subject: [PATCH 09/19] feat(BuyMoney):add BuyMoney class to save how many
lottos to buy
---
src/main/java/lotto/game/money/BuyMoney.java | 37 ++++++++++++++++++++
1 file changed, 37 insertions(+)
create mode 100644 src/main/java/lotto/game/money/BuyMoney.java
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..3aa55c06a4
--- /dev/null
+++ b/src/main/java/lotto/game/money/BuyMoney.java
@@ -0,0 +1,37 @@
+package lotto.game.money;
+
+import camp.nextstep.edu.missionutils.Console;
+
+public class BuyMoney {
+ private final int buyMoney;
+ private final int buyCount;
+ private final String inputBuyMoney;
+ public BuyMoney(){
+ System.out.println("๊ตฌ์
๊ธ์ก์ ์
๋ ฅํด ์ฃผ์ธ์.");
+ inputBuyMoney = Console.readLine();
+ for(int i = 0; i < inputBuyMoney.length(); i++){
+ checkError(inputBuyMoney.charAt(i));
+ }
+ 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;
+ }
+
+ private void checkError(char input){
+ if(input >= '0' && input <= '9'){
+ return;
+ }
+ throw new IllegalArgumentException("[ERROR]์ซ์๋ง ์
๋ ฅํ์ธ์.");
+ }
+}
From 3d93b0d1e3df5f47a3a7f58f2d3594980f9a6c30 Mon Sep 17 00:00:00 2001
From: gimdongha
Date: Sat, 8 Jul 2023 11:19:15 +0900
Subject: [PATCH 10/19] feat(BuyMoney):add InputWinLotto class to input win
lotto
---
src/main/java/lotto/game/InputWinLotto.java | 38 +++++++++++++++++++++
1 file changed, 38 insertions(+)
create mode 100644 src/main/java/lotto/game/InputWinLotto.java
diff --git a/src/main/java/lotto/game/InputWinLotto.java b/src/main/java/lotto/game/InputWinLotto.java
new file mode 100644
index 0000000000..91c7e1744e
--- /dev/null
+++ b/src/main/java/lotto/game/InputWinLotto.java
@@ -0,0 +1,38 @@
+package lotto.game;
+
+import camp.nextstep.edu.missionutils.Console;
+import lotto.lotto.Lotto;
+import lotto.lotto.WinningLotto;
+import lotto.checkexception.CheckException;
+import lotto.checkexception.CheckExceptionImpl;
+
+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<>();
+ for (String word : words) {
+ CheckException checkException = new CheckExceptionImpl();
+ int check = Integer.parseInt(word);
+ checkException.checkException(check);
+ list.add(check);
+ }
+
+ lotto = new Lotto(list);
+ System.out.println("๋ณด๋์ค ๋ฒํธ๋ฅผ ์
๋ ฅํด ์ฃผ์ธ์.");
+ String inputBonus = Console.readLine();
+ int bonus = Integer.parseInt(inputBonus);
+ winningLotto = new WinningLotto(lotto,bonus);
+ }
+
+ public WinningLotto getWinningLotto() {
+ return winningLotto;
+ }
+}
From 42a6e25c999cc43f4e74a9fd46e2ef04682e01f6 Mon Sep 17 00:00:00 2001
From: gimdongha
Date: Sat, 8 Jul 2023 11:19:39 +0900
Subject: [PATCH 11/19] feat(BuyMoney):add InputWinLotto class to calculate
what prize I earn
---
src/main/java/lotto/game/Rank.java | 32 ++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
create mode 100644 src/main/java/lotto/game/Rank.java
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]++;
+ }
+ }
+
+}
From 036e636518d7ec5ebc5ff02f41103a528cc148d2 Mon Sep 17 00:00:00 2001
From: gimdongha
Date: Sat, 8 Jul 2023 11:20:20 +0900
Subject: [PATCH 12/19] feat(EarnMoney):add EarnMoney class to save how much
money I earn
---
src/main/java/lotto/game/money/EarnMoney.java | 22 +++++++++++++++++++
1 file changed, 22 insertions(+)
create mode 100644 src/main/java/lotto/game/money/EarnMoney.java
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;
+ }
+}
From 9cc5f5b7b2d0e5439099520f237762eaebdd470d Mon Sep 17 00:00:00 2001
From: gimdongha
Date: Sat, 8 Jul 2023 11:21:04 +0900
Subject: [PATCH 13/19] feat(PrintCorrectCount):add PrintCorrectCount class to
print each prize times
---
.../java/lotto/game/PrintCorrectCount.java | 20 +++++++++++++++++++
1 file changed, 20 insertions(+)
create mode 100644 src/main/java/lotto/game/PrintCorrectCount.java
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 + "%์
๋๋ค."
+ );
+
+ }
+}
From db3e4712fb84dcfc9d41a7d89481e2a870b64be6 Mon Sep 17 00:00:00 2001
From: gimdongha
Date: Sat, 8 Jul 2023 11:21:30 +0900
Subject: [PATCH 14/19] feat(Game):add Game interface
---
src/main/java/lotto/game/Game.java | 5 +++++
1 file changed, 5 insertions(+)
create mode 100644 src/main/java/lotto/game/Game.java
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();
+}
From 5cc00b6e0417eb9997fa8403c79939e3b9a1c747 Mon Sep 17 00:00:00 2001
From: gimdongha
Date: Sat, 8 Jul 2023 11:21:53 +0900
Subject: [PATCH 15/19] feat(LottoGame):add LottoGame to play Lotto Game
---
src/main/java/lotto/game/LottoGame.java | 57 +++++++++++++++++++++++++
1 file changed, 57 insertions(+)
create mode 100644 src/main/java/lotto/game/LottoGame.java
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));
+ }
+ }
+}
From a2649ee5cff8e6bcf60cf97d0b0d1fa44079f3e1 Mon Sep 17 00:00:00 2001
From: gimdongha
Date: Sat, 8 Jul 2023 11:22:29 +0900
Subject: [PATCH 16/19] refactor(Application): add logic to play the game
---
src/main/java/lotto/Application.java | 5 +++++
1 file changed, 5 insertions(+)
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
From 8957f4ef59886f0c5053c2365d90e81ccc7cbbb9 Mon Sep 17 00:00:00 2001
From: gimdongha
Date: Sat, 8 Jul 2023 15:03:39 +0900
Subject: [PATCH 17/19] refactor(BuyMoney): refactor logic to check Exception
---
src/main/java/lotto/game/money/BuyMoney.java | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/src/main/java/lotto/game/money/BuyMoney.java b/src/main/java/lotto/game/money/BuyMoney.java
index 3aa55c06a4..2c5053118c 100644
--- a/src/main/java/lotto/game/money/BuyMoney.java
+++ b/src/main/java/lotto/game/money/BuyMoney.java
@@ -1,6 +1,7 @@
package lotto.game.money;
import camp.nextstep.edu.missionutils.Console;
+import lotto.checkexception.CheckCharException;
public class BuyMoney {
private final int buyMoney;
@@ -9,9 +10,8 @@ public class BuyMoney {
public BuyMoney(){
System.out.println("๊ตฌ์
๊ธ์ก์ ์
๋ ฅํด ์ฃผ์ธ์.");
inputBuyMoney = Console.readLine();
- for(int i = 0; i < inputBuyMoney.length(); i++){
- checkError(inputBuyMoney.charAt(i));
- }
+ CheckCharException checkCharException = new CheckCharException();
+ checkCharException.checkCharException(inputBuyMoney);
buyMoney = Integer.parseInt(inputBuyMoney);
if(buyMoney % 1000 != 0){
throw new IllegalArgumentException("[ERROR]1000์ ๋จ์๋ก ์
๋ ฅํด ์ฃผ์ธ์.");
@@ -28,10 +28,4 @@ public int getBuyCount(){
return buyCount;
}
- private void checkError(char input){
- if(input >= '0' && input <= '9'){
- return;
- }
- throw new IllegalArgumentException("[ERROR]์ซ์๋ง ์
๋ ฅํ์ธ์.");
- }
}
From 07afd35612617e5db400dbabeda6b071c4b63781 Mon Sep 17 00:00:00 2001
From: gimdongha
Date: Sat, 8 Jul 2023 15:04:44 +0900
Subject: [PATCH 18/19] feat(CheckCharException): add CheckCharException class
to check Exception when input char type
---
.../lotto/checkexception/CheckCharException.java | 12 ++++++++++++
1 file changed, 12 insertions(+)
create mode 100644 src/main/java/lotto/checkexception/CheckCharException.java
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]์ซ์๋ง ์
๋ ฅํ์ธ์.");
+ }
+ }
+}
From a0ab29c0d38b7dbd93b917ed90bddc0450fb3c02 Mon Sep 17 00:00:00 2001
From: gimdongha
Date: Sat, 8 Jul 2023 15:05:26 +0900
Subject: [PATCH 19/19] refactor(InputWinLotto):refactor logic to check
exception
---
src/main/java/lotto/game/InputWinLotto.java | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/src/main/java/lotto/game/InputWinLotto.java b/src/main/java/lotto/game/InputWinLotto.java
index 91c7e1744e..f0876ecfc3 100644
--- a/src/main/java/lotto/game/InputWinLotto.java
+++ b/src/main/java/lotto/game/InputWinLotto.java
@@ -1,10 +1,12 @@
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;
@@ -18,17 +20,24 @@ public InputWinLotto(){
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) {
- CheckException checkException = new CheckExceptionImpl();
+ 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);
}