From b50086680a683a12643661f21467b3e63530bdc2 Mon Sep 17 00:00:00 2001
From: kwonyonghyun <106018526+kwonyonghyun@users.noreply.github.com>
Date: Thu, 6 Jul 2023 11:46:02 +0900
Subject: [PATCH 01/19] Update README.md
---
README.md | 206 ++----------------------------------------------------
1 file changed, 6 insertions(+), 200 deletions(-)
diff --git a/README.md b/README.md
index 81b03cdba2..997ad9c9cf 100644
--- a/README.md
+++ b/README.md
@@ -1,207 +1,13 @@
-# 과제 - 로또
+1. 로또번호를 생성하는 클래스 RandomNumber class, RandomNumber 클래스 안의 getRandomNumber는 treeSet을 리턴함
+2. 입력을 string 형태로 받은 후, ','단위로 split을 하여 이를 size가 6인 리스트로 리턴하는 클래스 Input 클래스
+3. randomNumber와 input을 매개변수로 받은 후에 이를 비교하는 클래스 Compare클래스, Compare 클래스는 size가 6인 리스트를 리턴
+4. Compare 클래스를 인수로 받아 최종 메지시 출력, 수익률 출력 하는 클래스 Result클래스
+5. 변할 가능성이 있는 상수들을 포함하는 Constant 클래스
+6. 출력문을 포함하는 Message 클래스
-## 🔍 진행 방식
-- 과제는 **기능 요구 사항, 프로그래밍 요구 사항, 과제 진행 요구 사항** 세 가지로 구성되어 있다.
-- 세 개의 요구 사항을 만족하기 위해 노력한다. 특히 기능을 구현하기 전에 기능 목록을 만들고, 기능 단위로 커밋 하는 방식으로 진행한다.
-- 기능 요구 사항에 기재되지 않은 내용은 스스로 판단하여 구현한다.
----
-## 📈 과제 진행 및 제출 방법
-- 과제는 [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: 추가 기능 구현
-}
-```
From b12963cff4b2a855238932772a4b4e80b379e061 Mon Sep 17 00:00:00 2001
From: kwonyonghyun
Date: Thu, 6 Jul 2023 12:11:54 +0900
Subject: [PATCH 02/19] =?UTF-8?q?input,=20randomNumber=20=ED=81=B4?=
=?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=9E=91=EC=84=B1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/Application.java | 6 ++++++
src/main/java/lotto/Constant.java | 8 ++++++++
src/main/java/lotto/Input.java | 28 +++++++++++++++++++++++++++
src/main/java/lotto/Message.java | 20 +++++++++++++++++++
src/main/java/lotto/RandomNumber.java | 18 +++++++++++++++++
5 files changed, 80 insertions(+)
create mode 100644 src/main/java/lotto/Constant.java
create mode 100644 src/main/java/lotto/Input.java
create mode 100644 src/main/java/lotto/Message.java
create mode 100644 src/main/java/lotto/RandomNumber.java
diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java
index 367ee30584..2bba48889e 100644
--- a/src/main/java/lotto/Application.java
+++ b/src/main/java/lotto/Application.java
@@ -1,7 +1,13 @@
package lotto;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
public class Application {
public static void main(String[] args) {
// TODO: 프로그램 구현
+ Input input=new Input();
+ input.getInput();
}
}
\ No newline at end of file
diff --git a/src/main/java/lotto/Constant.java b/src/main/java/lotto/Constant.java
new file mode 100644
index 0000000000..af66bb8a4e
--- /dev/null
+++ b/src/main/java/lotto/Constant.java
@@ -0,0 +1,8 @@
+package lotto;
+
+public class Constant {
+ public final static int DIGITS=6;
+ public final static int MIN_BOUND=1;
+ final static int MAX_BOUND=45;
+
+}
diff --git a/src/main/java/lotto/Input.java b/src/main/java/lotto/Input.java
new file mode 100644
index 0000000000..88fe59a42b
--- /dev/null
+++ b/src/main/java/lotto/Input.java
@@ -0,0 +1,28 @@
+package lotto;
+
+import camp.nextstep.edu.missionutils.Console;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Input {
+
+ public List getInput(){
+ String input=Console.readLine();
+ String[] splitResult=input.split(",");
+ List result=new ArrayList<>();
+ for(String a:splitResult){
+ int oneInput=Integer.parseInt(a);
+ result.add(oneInput);
+ }
+ validate(result);
+ return result;
+ }
+ public void validate(List input){
+ for(int i=0;iConstant.MAX_BOUND){
+ throw new IllegalArgumentException();
+ }
+ }
+ }
+}
diff --git a/src/main/java/lotto/Message.java b/src/main/java/lotto/Message.java
new file mode 100644
index 0000000000..9c1956e0cc
--- /dev/null
+++ b/src/main/java/lotto/Message.java
@@ -0,0 +1,20 @@
+package lotto;
+
+public enum Message {
+
+
+ INPUT_PRICE("구입 금액을 입력해 주세요."),
+ OUTPUT_AMOUNT("개를 구매했습니다"),
+ INPUT_NUMBER("당첨 번호를 입력해 주세요"),
+ INPUT_BONUS("보너스 번호를 입력해 주세요"),
+ WINNING_RESULT("당첨 통계\n___"),
+ EQUAL_THREE("3개 일치 (5,000원) -"),
+ EQUAL_FOUR("4개 일치 (50,000원) -"),
+ EQUAL_FIVE("5개 일치 (1,500,000원) -"),
+ EQUAL_FIVE_BONUS("5개 일치, 보너스 볼 일치 (30,000,000원) -"),
+ EQUAL_SIX("6개 일치 (2,000,000,000원) -");
+
+ private final String value;
+ Message(String value) { this.value = value; }
+ public String getValue() { return value; }
+}
diff --git a/src/main/java/lotto/RandomNumber.java b/src/main/java/lotto/RandomNumber.java
new file mode 100644
index 0000000000..1eca41d514
--- /dev/null
+++ b/src/main/java/lotto/RandomNumber.java
@@ -0,0 +1,18 @@
+package lotto;
+
+import camp.nextstep.edu.missionutils.Randoms;
+
+import java.util.Set;
+import java.util.TreeSet;
+
+
+public class RandomNumber {
+ public Set getRandomNumber(){
+ Set result=new TreeSet<>();
+ while(result.size()< Constant.DIGITS){
+ int randomNumber=Randoms.pickNumberInRange(Constant.MIN_BOUND,Constant.MAX_BOUND);
+ result.add(randomNumber);
+ }
+ return result;
+ }
+}
From e040d127d8e07e4d21a4174a58a264bcaa0b3ad9 Mon Sep 17 00:00:00 2001
From: kwonyonghyun
Date: Thu, 6 Jul 2023 12:53:02 +0900
Subject: [PATCH 03/19] =?UTF-8?q?compare=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?=
=?UTF-8?q?=EC=B6=94=EA=B0=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/Compare.java | 36 +++++++++++++++++++++++++++++++
src/main/java/lotto/Constant.java | 3 +++
src/main/java/lotto/Game.java | 6 ++++++
src/main/java/lotto/Input.java | 5 +++++
4 files changed, 50 insertions(+)
create mode 100644 src/main/java/lotto/Compare.java
create mode 100644 src/main/java/lotto/Game.java
diff --git a/src/main/java/lotto/Compare.java b/src/main/java/lotto/Compare.java
new file mode 100644
index 0000000000..3798c89c29
--- /dev/null
+++ b/src/main/java/lotto/Compare.java
@@ -0,0 +1,36 @@
+package lotto;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+public class Compare {
+
+ private final List input;
+ private final Set randomNumber;
+
+ Compare(List input, Set randomNumber) {
+ this.input = input;
+ this.randomNumber = randomNumber;
+ }
+
+ public List compare() {
+ List result=new ArrayList<>();
+ for(int i=0;i list){
+ int [] result=new int[2];
+ result[0]=Collections.frequency(list,1);
+ result[1]=Collections.frequency(list,2);
+ return result;
+ }
+}
diff --git a/src/main/java/lotto/Constant.java b/src/main/java/lotto/Constant.java
index af66bb8a4e..d9204f9015 100644
--- a/src/main/java/lotto/Constant.java
+++ b/src/main/java/lotto/Constant.java
@@ -5,4 +5,7 @@ public class Constant {
public final static int MIN_BOUND=1;
final static int MAX_BOUND=45;
+
+
+
}
diff --git a/src/main/java/lotto/Game.java b/src/main/java/lotto/Game.java
new file mode 100644
index 0000000000..250788b8cb
--- /dev/null
+++ b/src/main/java/lotto/Game.java
@@ -0,0 +1,6 @@
+package lotto;
+
+public class Game {
+
+
+}
diff --git a/src/main/java/lotto/Input.java b/src/main/java/lotto/Input.java
index 88fe59a42b..777b487624 100644
--- a/src/main/java/lotto/Input.java
+++ b/src/main/java/lotto/Input.java
@@ -8,6 +8,7 @@
public class Input {
public List getInput(){
+ System.out.println(Message.INPUT_NUMBER.getValue());
String input=Console.readLine();
String[] splitResult=input.split(",");
List result=new ArrayList<>();
@@ -16,6 +17,10 @@ public List getInput(){
result.add(oneInput);
}
validate(result);
+ System.out.println(Message.INPUT_BONUS.getValue());
+ input=Console.readLine();
+ result.add(Integer.parseInt(input));
+ validate(result);
return result;
}
public void validate(List input){
From eea9215ac2bf0216668c6a7218512afe19e77af1 Mon Sep 17 00:00:00 2001
From: kwonyonghyun
Date: Thu, 6 Jul 2023 14:43:08 +0900
Subject: [PATCH 04/19] =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=8B=A4?=
=?UTF-8?q?=ED=8C=A8=20=EB=B2=84=EC=A0=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/Application.java | 10 +++-
src/main/java/lotto/Constant.java | 4 --
src/main/java/lotto/Game.java | 77 +++++++++++++++++++++++++++
src/main/java/lotto/Message.java | 10 ++--
src/main/java/lotto/Print.java | 30 +++++++++++
src/main/java/lotto/RandomNumber.java | 1 +
6 files changed, 122 insertions(+), 10 deletions(-)
create mode 100644 src/main/java/lotto/Print.java
diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java
index 2bba48889e..c2625d6e98 100644
--- a/src/main/java/lotto/Application.java
+++ b/src/main/java/lotto/Application.java
@@ -1,5 +1,7 @@
package lotto;
+import camp.nextstep.edu.missionutils.Console;
+
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
@@ -7,7 +9,13 @@
public class Application {
public static void main(String[] args) {
// TODO: 프로그램 구현
+ System.out.println(Message.INPUT_PRICE.getValue());
+ RandomNumber randomNumber=new RandomNumber();
+ Print print=new Print();
Input input=new Input();
- input.getInput();
+ int price= Integer.parseInt(Console.readLine());
+ print.printAmount(price/1000);
+ Game game=new Game(randomNumber,input,price);
+ game.run();
}
}
\ No newline at end of file
diff --git a/src/main/java/lotto/Constant.java b/src/main/java/lotto/Constant.java
index d9204f9015..3e7a3cf302 100644
--- a/src/main/java/lotto/Constant.java
+++ b/src/main/java/lotto/Constant.java
@@ -4,8 +4,4 @@ public class Constant {
public final static int DIGITS=6;
public final static int MIN_BOUND=1;
final static int MAX_BOUND=45;
-
-
-
-
}
diff --git a/src/main/java/lotto/Game.java b/src/main/java/lotto/Game.java
index 250788b8cb..b61fd2c5c2 100644
--- a/src/main/java/lotto/Game.java
+++ b/src/main/java/lotto/Game.java
@@ -1,6 +1,83 @@
package lotto;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
public class Game {
+ int firstPlace;
+ int secondPlace;
+ int thirdPlace;
+ int fourthPlace;
+ int fifthPlace;
+
+ private final RandomNumber randomNumber;
+ private final Input input;
+ private int count;
+ private int price;
+
+
+ Game(RandomNumber randomNumber,Input input,int price){
+ this.randomNumber=randomNumber;
+ this.input=input;
+ this.price=price;
+ count=price/1000;
+ firstPlace=0;
+ secondPlace=0;
+ thirdPlace=0;
+ fourthPlace=0;
+ fifthPlace=0;
+ }
+
+ public void run(){
+ List winCounts=new ArrayList<>();
+ List> list=new ArrayList<>();
+ for(int i=0;i randomNumbers=randomNumber.getRandomNumber();
+ System.out.println(randomNumbers);
+ list.add(randomNumbers);
+ //Compare compare=new Compare(input.getInput(),randomNumbers);
+ //winCounts.add(compare.winCount(compare.compare()));
+ }
+ List a=input.getInput();
+ for(int i=0;i getRandomNumber(){
while(result.size()< Constant.DIGITS){
int randomNumber=Randoms.pickNumberInRange(Constant.MIN_BOUND,Constant.MAX_BOUND);
result.add(randomNumber);
+
}
return result;
}
From bdb715b7be505492e12213ad091367fa19f4ba82 Mon Sep 17 00:00:00 2001
From: kwonyonghyun
Date: Thu, 6 Jul 2023 21:41:22 +0900
Subject: [PATCH 05/19] =?UTF-8?q?=EC=98=88=EC=99=B8=20=ED=85=8C=EC=8A=A4?=
=?UTF-8?q?=ED=8A=B8=EC=BC=80=EC=9D=B4=EC=8A=A4=20=ED=86=B5=EA=B3=BC=20?=
=?UTF-8?q?=EC=83=81=ED=83=9C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/Application.java | 16 ++++-----
src/main/java/lotto/Compare.java | 5 ++-
src/main/java/lotto/Constant.java | 2 ++
src/main/java/lotto/Game.java | 52 ++++++++++++++-------------
src/main/java/lotto/Input.java | 37 +++++++++++++++----
src/main/java/lotto/Print.java | 22 ++++++++++--
src/main/java/lotto/RandomNumber.java | 13 ++++++-
7 files changed, 101 insertions(+), 46 deletions(-)
diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java
index c2625d6e98..1c8d43dfa9 100644
--- a/src/main/java/lotto/Application.java
+++ b/src/main/java/lotto/Application.java
@@ -7,15 +7,15 @@
import java.util.TreeSet;
public class Application {
- public static void main(String[] args) {
+ public static void main(String[] args) throws IllegalArgumentException{
// TODO: 프로그램 구현
- System.out.println(Message.INPUT_PRICE.getValue());
- RandomNumber randomNumber=new RandomNumber();
- Print print=new Print();
Input input=new Input();
- int price= Integer.parseInt(Console.readLine());
- print.printAmount(price/1000);
- Game game=new Game(randomNumber,input,price);
- game.run();
+ int purchacePrice=0;
+ Game game=new Game(new RandomNumber(),new Input());
+ try {
+ game.run();
+ }catch (Exception e){
+ System.out.println(e.getMessage());
+ }
}
}
\ No newline at end of file
diff --git a/src/main/java/lotto/Compare.java b/src/main/java/lotto/Compare.java
index 3798c89c29..7d42873057 100644
--- a/src/main/java/lotto/Compare.java
+++ b/src/main/java/lotto/Compare.java
@@ -8,13 +8,12 @@
public class Compare {
private final List input;
- private final Set randomNumber;
+ private final List randomNumber;
- Compare(List input, Set randomNumber) {
+ Compare(List input, List randomNumber) {
this.input = input;
this.randomNumber = randomNumber;
}
-
public List compare() {
List result=new ArrayList<>();
for(int i=0;i winCounts=new ArrayList<>();
- List> list=new ArrayList<>();
+ List> list=new ArrayList<>();
+ price=input.getPurchacePrice();
+ count=price/1000;
for(int i=0;i randomNumbers=randomNumber.getRandomNumber();
- System.out.println(randomNumbers);
+ List randomNumbers=randomNumber.getRandomNumber();
list.add(randomNumbers);
//Compare compare=new Compare(input.getInput(),randomNumbers);
//winCounts.add(compare.winCount(compare.compare()));
}
- List a=input.getInput();
+ List a=input.getWiningNumber();
for(int i=0;i getInput(){
- System.out.println(Message.INPUT_NUMBER.getValue());
+ Input(){
+ print=new Print();
+ }
+
+ public int getPurchacePrice()throws IllegalArgumentException{
+ print.printGetPrice();
+ String input=Console.readLine();
+ validatePrice(input);
+ int result=Integer.parseInt(input);
+ return result;
+ }
+
+ public List getWiningNumber()throws IllegalArgumentException{
+ print.printWinningNumber();
String input=Console.readLine();
String[] splitResult=input.split(",");
List result=new ArrayList<>();
@@ -16,18 +29,28 @@ public List getInput(){
int oneInput=Integer.parseInt(a);
result.add(oneInput);
}
- validate(result);
- System.out.println(Message.INPUT_BONUS.getValue());
+ validateWinningNumber(result);
+ print.printBonusNumber();
input=Console.readLine();
result.add(Integer.parseInt(input));
- validate(result);
+ validateWinningNumber(result);
return result;
}
- public void validate(List input){
+ public void validatePrice(String input) throws IllegalArgumentException{
+ for(int i=0;iConstant.MAX_BOUND_CHAR){
+ System.out.println("[ERROR]");
+ throw new IllegalArgumentException("[ERROR]");
+ }
+ }
+ }
+ public void validateWinningNumber(List input) throws IllegalArgumentException{
for(int i=0;iConstant.MAX_BOUND){
- throw new IllegalArgumentException();
+ System.out.println("[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다.");
+ throw new IllegalArgumentException("[ERROR]");
}
}
}
+
}
diff --git a/src/main/java/lotto/Print.java b/src/main/java/lotto/Print.java
index e45addba6e..e611b2dfbd 100644
--- a/src/main/java/lotto/Print.java
+++ b/src/main/java/lotto/Print.java
@@ -21,10 +21,28 @@ public int printThree(int value){
System.out.println(Message.EQUAL_THREE.getValue()+value+" 개");
return 5000*value;
}
- public void printResult(int result,int price){
- System.out.println("총 수익률은 "+(double)result/price+"입니다.");
+ public void printProfitResult(int result, int price){
+ System.out.println("총 수익률은 "+(double)result/price+"%입니다.");
}
public void printAmount(int amount){
System.out.println(amount+Message.OUTPUT_AMOUNT.getValue());
}
+ public void printGetPrice(){
+ System.out.println(Message.INPUT_PRICE.getValue());
+ }
+ public void printWinningNumber(){
+ System.out.println(Message.INPUT_NUMBER.getValue());
+ }
+ public void printBonusNumber(){
+ System.out.println(Message.INPUT_BONUS.getValue());
+ }
+ public void printResult(int[] place,int price){
+ int result=0;
+ result+=printThree(place[4]);
+ result+=printFour(place[3]);
+ result+=printFive(place[2]);
+ result+=printFiveBonus(place[1]);
+ result+=printSix(place[0]);
+ printProfitResult(result,price);
+ }
}
diff --git a/src/main/java/lotto/RandomNumber.java b/src/main/java/lotto/RandomNumber.java
index ca5a5d498b..6bc2274f50 100644
--- a/src/main/java/lotto/RandomNumber.java
+++ b/src/main/java/lotto/RandomNumber.java
@@ -2,18 +2,29 @@
import camp.nextstep.edu.missionutils.Randoms;
+import java.util.Collections;
+import java.util.List;
import java.util.Set;
import java.util.TreeSet;
public class RandomNumber {
+ /*
public Set getRandomNumber(){
Set result=new TreeSet<>();
while(result.size()< Constant.DIGITS){
int randomNumber=Randoms.pickNumberInRange(Constant.MIN_BOUND,Constant.MAX_BOUND);
result.add(randomNumber);
-
}
+ System.out.println(result);
return result;
}
+
+ */
+ public List getRandomNumber(){
+ List randomNumber=Randoms.pickUniqueNumbersInRange(Constant.MIN_BOUND,Constant.MAX_BOUND,Constant.DIGITS);
+ Collections.sort(randomNumber);
+ System.out.println(randomNumber);
+ return randomNumber;
+ }
}
From 93ab3323cf4dc0c8bdd28aa97db144c66cb60f4c Mon Sep 17 00:00:00 2001
From: kwonyonghyun
Date: Thu, 6 Jul 2023 22:50:49 +0900
Subject: [PATCH 06/19] =?UTF-8?q?=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81=20?=
=?UTF-8?q?=EC=A0=84=20=EC=BD=94=EB=93=9C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/Application.java | 2 ++
src/main/java/lotto/Game.java | 11 +++++------
src/main/java/lotto/Input.java | 9 ++++-----
src/main/java/lotto/Message.java | 2 +-
src/main/java/lotto/Print.java | 15 ++++++++-------
src/main/java/lotto/RandomNumber.java | 7 ++-----
6 files changed, 22 insertions(+), 24 deletions(-)
diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java
index 1c8d43dfa9..8a2ab55543 100644
--- a/src/main/java/lotto/Application.java
+++ b/src/main/java/lotto/Application.java
@@ -12,9 +12,11 @@ public static void main(String[] args) throws IllegalArgumentException{
Input input=new Input();
int purchacePrice=0;
Game game=new Game(new RandomNumber(),new Input());
+
try {
game.run();
}catch (Exception e){
+ System.out.println(11);
System.out.println(e.getMessage());
}
}
diff --git a/src/main/java/lotto/Game.java b/src/main/java/lotto/Game.java
index 30b7fa70ee..3415811330 100644
--- a/src/main/java/lotto/Game.java
+++ b/src/main/java/lotto/Game.java
@@ -2,7 +2,6 @@
import java.util.ArrayList;
import java.util.List;
-import java.util.Set;
public class Game {
/*
@@ -17,7 +16,7 @@ public class Game {
private final RandomNumber randomNumber;
private final Input input;
- private int count;
+ private int amount;
private int price;
Print print;
@@ -31,7 +30,6 @@ public class Game {
thirdPlace=0;
fourthPlace=0;
fifthPlace=0;
-
*/
place=new int[5];
this.print=new Print();
@@ -41,15 +39,16 @@ public void run(){
List winCounts=new ArrayList<>();
List> list=new ArrayList<>();
price=input.getPurchacePrice();
- count=price/1000;
- for(int i=0;i randomNumbers=randomNumber.getRandomNumber();
list.add(randomNumbers);
//Compare compare=new Compare(input.getInput(),randomNumbers);
//winCounts.add(compare.winCount(compare.compare()));
}
List a=input.getWiningNumber();
- for(int i=0;i getWiningNumber()throws IllegalArgumentException{
+ public List getWiningNumber(){
print.printWinningNumber();
String input=Console.readLine();
String[] splitResult=input.split(",");
@@ -36,15 +36,14 @@ public List getWiningNumber()throws IllegalArgumentException{
validateWinningNumber(result);
return result;
}
- public void validatePrice(String input) throws IllegalArgumentException{
+ public void validatePrice(String input) {
for(int i=0;iConstant.MAX_BOUND_CHAR){
- System.out.println("[ERROR]");
throw new IllegalArgumentException("[ERROR]");
}
}
}
- public void validateWinningNumber(List input) throws IllegalArgumentException{
+ public void validateWinningNumber(List input) {
for(int i=0;iConstant.MAX_BOUND){
System.out.println("[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다.");
diff --git a/src/main/java/lotto/Message.java b/src/main/java/lotto/Message.java
index e72ed95ba7..48752754f7 100644
--- a/src/main/java/lotto/Message.java
+++ b/src/main/java/lotto/Message.java
@@ -4,7 +4,7 @@ public enum Message {
INPUT_PRICE("구입 금액을 입력해 주세요."),
- OUTPUT_AMOUNT("개를 구매했습니다"),
+ OUTPUT_AMOUNT("개를 구매했습니다."),
INPUT_NUMBER("당첨 번호를 입력해 주세요"),
INPUT_BONUS("보너스 번호를 입력해 주세요"),
WINNING_RESULT("당첨 통계\n___"),
diff --git a/src/main/java/lotto/Print.java b/src/main/java/lotto/Print.java
index e611b2dfbd..d71c7a9ef0 100644
--- a/src/main/java/lotto/Print.java
+++ b/src/main/java/lotto/Print.java
@@ -2,30 +2,30 @@
public class Print {
public int printSix(int value){
- System.out.println(Message.EQUAL_SIX.getValue()+value+" 개");
+ System.out.println(Message.EQUAL_SIX.getValue()+value+"개");
return 2000000000*value;
}
public int printFive(int value){
- System.out.println(Message.EQUAL_FIVE.getValue()+value+" 개");
+ System.out.println(Message.EQUAL_FIVE.getValue()+value+"개");
return 1500000*value;
}
public int printFiveBonus(int value){
- System.out.println(Message.EQUAL_FIVE_BONUS.getValue()+value+" 개");
+ System.out.println(Message.EQUAL_FIVE_BONUS.getValue()+value+"개");
return 30000000*value;
}
public int printFour(int value){
- System.out.println(Message.EQUAL_FOUR.getValue()+value+" 개");
+ System.out.println(Message.EQUAL_FOUR.getValue()+value+"개");
return 50000*value;
}
public int printThree(int value){
- System.out.println(Message.EQUAL_THREE.getValue()+value+" 개");
+ System.out.println(Message.EQUAL_THREE.getValue()+value+"개");
return 5000*value;
}
public void printProfitResult(int result, int price){
- System.out.println("총 수익률은 "+(double)result/price+"%입니다.");
+ System.out.println("총 수익률은 "+100*((double)result/price)+"%입니다.");
}
public void printAmount(int amount){
- System.out.println(amount+Message.OUTPUT_AMOUNT.getValue());
+ System.out.println(+amount+Message.OUTPUT_AMOUNT.getValue());
}
public void printGetPrice(){
System.out.println(Message.INPUT_PRICE.getValue());
@@ -45,4 +45,5 @@ public void printResult(int[] place,int price){
result+=printSix(place[0]);
printProfitResult(result,price);
}
+
}
diff --git a/src/main/java/lotto/RandomNumber.java b/src/main/java/lotto/RandomNumber.java
index 6bc2274f50..32b80ef75c 100644
--- a/src/main/java/lotto/RandomNumber.java
+++ b/src/main/java/lotto/RandomNumber.java
@@ -2,10 +2,7 @@
import camp.nextstep.edu.missionutils.Randoms;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-import java.util.TreeSet;
+import java.util.*;
public class RandomNumber {
@@ -22,7 +19,7 @@ public Set getRandomNumber(){
*/
public List getRandomNumber(){
- List randomNumber=Randoms.pickUniqueNumbersInRange(Constant.MIN_BOUND,Constant.MAX_BOUND,Constant.DIGITS);
+ List randomNumber= new ArrayList<>(Randoms.pickUniqueNumbersInRange(Constant.MIN_BOUND,Constant.MAX_BOUND,Constant.DIGITS));
Collections.sort(randomNumber);
System.out.println(randomNumber);
return randomNumber;
From 9f432dfedc585ed794cd0d6dffb12ca56365ef54 Mon Sep 17 00:00:00 2001
From: kwonyonghyun
Date: Thu, 6 Jul 2023 23:51:42 +0900
Subject: [PATCH 07/19] =?UTF-8?q?1=EC=B0=A8=20=EB=A6=AC=ED=8C=A9=ED=86=A0?=
=?UTF-8?q?=EB=A7=81=20=EC=99=84=EB=A3=8C?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/Application.java | 4 +-
src/main/java/lotto/Compare.java | 9 ++-
src/main/java/lotto/Constant.java | 2 +-
src/main/java/lotto/Game.java | 104 +++++++++++---------------
src/main/java/lotto/Input.java | 14 ++--
src/main/java/lotto/Print.java | 20 ++---
src/main/java/lotto/RandomNumber.java | 16 +---
7 files changed, 75 insertions(+), 94 deletions(-)
diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java
index 8a2ab55543..d091c8abba 100644
--- a/src/main/java/lotto/Application.java
+++ b/src/main/java/lotto/Application.java
@@ -10,9 +10,7 @@ public class Application {
public static void main(String[] args) throws IllegalArgumentException{
// TODO: 프로그램 구현
Input input=new Input();
- int purchacePrice=0;
- Game game=new Game(new RandomNumber(),new Input());
-
+ Game game=new Game(new RandomNumber(),new Input(),new Print());
try {
game.run();
}catch (Exception e){
diff --git a/src/main/java/lotto/Compare.java b/src/main/java/lotto/Compare.java
index 7d42873057..fd20555c4e 100644
--- a/src/main/java/lotto/Compare.java
+++ b/src/main/java/lotto/Compare.java
@@ -5,6 +5,8 @@
import java.util.List;
import java.util.Set;
+import static lotto.Constant.*;
+
public class Compare {
private final List input;
@@ -16,12 +18,13 @@ public class Compare {
}
public List compare() {
List result=new ArrayList<>();
- for(int i=0;i> getRandomNumbers(int amount) {
+ List> list = new ArrayList<>();
+ for (int i = 0; i < amount; i++) {
+ List randomNumbers = randomNumber.getRandomNumber();
+ list.add(randomNumbers);
+ }
+ return list;
+ }
+ private void calculateWinCounts(int[] place, int idx, List winCounts){
+ if(winCounts.get(idx)[0]==6){
+ place[0]++;
+ return;
+ }
+ if(winCounts.get(idx)[0]==5){
+ if(winCounts.get(idx)[1]==1){
+ place[1]++;
+ return;
+ }
+ place[2]++;
+ return;
+ }
+ if(winCounts.get(idx)[0]==4){
+ place[3]++;
+ return;
+ }
+ if(winCounts.get(idx)[0]==3){
+ place[4]++;
+ }
+ }
+ private int[] getWinCounts(List winCounts){
+ int [] place=new int[5];
+ for(int i=0;i winCounts=new ArrayList<>();
- List> list=new ArrayList<>();
- price=input.getPurchacePrice();
- amount =price/1000;
+ int price=input.getPurchacePrice();
+ int amount =price/1000;
+ List> list=getRandomNumbers(amount);
print.printAmount(amount);
+ List winningNumber=input.getWiningNumber();
for(int i = 0; i< amount; i++){
- List randomNumbers=randomNumber.getRandomNumber();
- list.add(randomNumbers);
- //Compare compare=new Compare(input.getInput(),randomNumbers);
- //winCounts.add(compare.winCount(compare.compare()));
- }
- List a=input.getWiningNumber();
- for(int i = 0; i< amount; i++){
- Compare compare=new Compare(a,list.get(i));
+ Compare compare=new Compare(winningNumber,list.get(i));
winCounts.add(compare.winCount(compare.compare()));
}
- for(int i=0;i getWiningNumber(){
String input=Console.readLine();
String[] splitResult=input.split(",");
List result=new ArrayList<>();
- for(String a:splitResult){
- int oneInput=Integer.parseInt(a);
+ for(String oneSplitResult:splitResult){
+ int oneInput=Integer.parseInt(oneSplitResult);
result.add(oneInput);
}
validateWinningNumber(result);
@@ -36,16 +38,16 @@ public List getWiningNumber(){
validateWinningNumber(result);
return result;
}
- public void validatePrice(String input) {
+ private void validatePrice(String input) {
for(int i=0;iConstant.MAX_BOUND_CHAR){
+ if(input.charAt(i)< MIN_BOUND_CHAR||input.charAt(i)> MAX_BOUND_CHAR){
throw new IllegalArgumentException("[ERROR]");
}
}
}
- public void validateWinningNumber(List input) {
+ private void validateWinningNumber(List input) {
for(int i=0;iConstant.MAX_BOUND){
+ if(input.get(i)< MIN_BOUND||input.get(i)> MAX_BOUND){
System.out.println("[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다.");
throw new IllegalArgumentException("[ERROR]");
}
diff --git a/src/main/java/lotto/Print.java b/src/main/java/lotto/Print.java
index d71c7a9ef0..a11047d285 100644
--- a/src/main/java/lotto/Print.java
+++ b/src/main/java/lotto/Print.java
@@ -1,40 +1,42 @@
package lotto;
+import static lotto.Message.*;
+
public class Print {
public int printSix(int value){
- System.out.println(Message.EQUAL_SIX.getValue()+value+"개");
+ System.out.println(EQUAL_SIX.getValue()+value+"개");
return 2000000000*value;
}
public int printFive(int value){
- System.out.println(Message.EQUAL_FIVE.getValue()+value+"개");
+ System.out.println(EQUAL_FIVE.getValue()+value+"개");
return 1500000*value;
}
public int printFiveBonus(int value){
- System.out.println(Message.EQUAL_FIVE_BONUS.getValue()+value+"개");
+ System.out.println(EQUAL_FIVE_BONUS.getValue()+value+"개");
return 30000000*value;
}
public int printFour(int value){
- System.out.println(Message.EQUAL_FOUR.getValue()+value+"개");
+ System.out.println(EQUAL_FOUR.getValue()+value+"개");
return 50000*value;
}
public int printThree(int value){
- System.out.println(Message.EQUAL_THREE.getValue()+value+"개");
+ System.out.println(EQUAL_THREE.getValue()+value+"개");
return 5000*value;
}
public void printProfitResult(int result, int price){
System.out.println("총 수익률은 "+100*((double)result/price)+"%입니다.");
}
public void printAmount(int amount){
- System.out.println(+amount+Message.OUTPUT_AMOUNT.getValue());
+ System.out.println(+amount+ OUTPUT_AMOUNT.getValue());
}
public void printGetPrice(){
- System.out.println(Message.INPUT_PRICE.getValue());
+ System.out.println(INPUT_PRICE.getValue());
}
public void printWinningNumber(){
- System.out.println(Message.INPUT_NUMBER.getValue());
+ System.out.println(INPUT_NUMBER.getValue());
}
public void printBonusNumber(){
- System.out.println(Message.INPUT_BONUS.getValue());
+ System.out.println(INPUT_BONUS.getValue());
}
public void printResult(int[] place,int price){
int result=0;
diff --git a/src/main/java/lotto/RandomNumber.java b/src/main/java/lotto/RandomNumber.java
index 32b80ef75c..eb17f885a8 100644
--- a/src/main/java/lotto/RandomNumber.java
+++ b/src/main/java/lotto/RandomNumber.java
@@ -4,22 +4,12 @@
import java.util.*;
+import static lotto.Constant.*;
-public class RandomNumber {
- /*
- public Set getRandomNumber(){
- Set result=new TreeSet<>();
- while(result.size()< Constant.DIGITS){
- int randomNumber=Randoms.pickNumberInRange(Constant.MIN_BOUND,Constant.MAX_BOUND);
- result.add(randomNumber);
- }
- System.out.println(result);
- return result;
- }
- */
+public class RandomNumber {
public List getRandomNumber(){
- List randomNumber= new ArrayList<>(Randoms.pickUniqueNumbersInRange(Constant.MIN_BOUND,Constant.MAX_BOUND,Constant.DIGITS));
+ List randomNumber= new ArrayList<>(Randoms.pickUniqueNumbersInRange(MIN_BOUND, MAX_BOUND, DIGITS));
Collections.sort(randomNumber);
System.out.println(randomNumber);
return randomNumber;
From 8803c6c4b603343e2517d3dda0d93a4b370fb441 Mon Sep 17 00:00:00 2001
From: kwonyonghyun
Date: Fri, 7 Jul 2023 00:00:04 +0900
Subject: [PATCH 08/19] =?UTF-8?q?=EC=9E=90=EB=8F=99=EC=A0=95=EB=A0=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/Application.java | 9 ++--
src/main/java/lotto/Compare.java | 20 ++++----
src/main/java/lotto/Constant.java | 10 ++--
src/main/java/lotto/Game.java | 53 ++++++++++----------
src/main/java/lotto/Input.java | 40 +++++++--------
src/main/java/lotto/Message.java | 10 +++-
src/main/java/lotto/Print.java | 70 +++++++++++++++------------
src/main/java/lotto/RandomNumber.java | 4 +-
8 files changed, 119 insertions(+), 97 deletions(-)
diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java
index d091c8abba..5e60a1c30d 100644
--- a/src/main/java/lotto/Application.java
+++ b/src/main/java/lotto/Application.java
@@ -7,14 +7,13 @@
import java.util.TreeSet;
public class Application {
- public static void main(String[] args) throws IllegalArgumentException{
+ public static void main(String[] args) throws IllegalArgumentException {
// TODO: 프로그램 구현
- Input input=new Input();
- Game game=new Game(new RandomNumber(),new Input(),new Print());
+ Input input = new Input();
+ Game game = new Game(new RandomNumber(), new Input(), new Print());
try {
game.run();
- }catch (Exception e){
- System.out.println(11);
+ } catch (Exception e) {
System.out.println(e.getMessage());
}
}
diff --git a/src/main/java/lotto/Compare.java b/src/main/java/lotto/Compare.java
index fd20555c4e..be5ea5a7a2 100644
--- a/src/main/java/lotto/Compare.java
+++ b/src/main/java/lotto/Compare.java
@@ -16,23 +16,25 @@ public class Compare {
this.input = input;
this.randomNumber = randomNumber;
}
+
public List compare() {
- List result=new ArrayList<>();
- for(int i = 0; i< DIGITS; i++){
- Integer a=input.get(i);
- if(randomNumber.contains(a)){
+ List result = new ArrayList<>();
+ for (int i = 0; i < DIGITS; i++) {
+ Integer a = input.get(i);
+ if (randomNumber.contains(a)) {
result.add(1);
}
}
- if(randomNumber.contains(input.get(DIGITS))){
+ if (randomNumber.contains(input.get(DIGITS))) {
result.add(2);
}
return result;
}
- public int [] winCount(List list){
- int [] result=new int[2];
- result[0]=Collections.frequency(list,1);
- result[1]=Collections.frequency(list,2);
+
+ public int[] winCount(List list) {
+ int[] result = new int[2];
+ result[0] = Collections.frequency(list, 1);
+ result[1] = Collections.frequency(list, 2);
return result;
}
}
diff --git a/src/main/java/lotto/Constant.java b/src/main/java/lotto/Constant.java
index 980642d437..b5bcfde585 100644
--- a/src/main/java/lotto/Constant.java
+++ b/src/main/java/lotto/Constant.java
@@ -1,9 +1,9 @@
package lotto;
public class Constant {
- public final static int DIGITS=6;
- public final static int MIN_BOUND=1;
- public final static int MAX_BOUND=45;
- public final static char MIN_BOUND_CHAR='0';
- public final static char MAX_BOUND_CHAR='9';
+ public final static int DIGITS = 6;
+ public final static int MIN_BOUND = 1;
+ public final static int MAX_BOUND = 45;
+ public final static char MIN_BOUND_CHAR = '0';
+ public final static char MAX_BOUND_CHAR = '9';
}
diff --git a/src/main/java/lotto/Game.java b/src/main/java/lotto/Game.java
index 403f8c949b..94591a25bd 100644
--- a/src/main/java/lotto/Game.java
+++ b/src/main/java/lotto/Game.java
@@ -11,10 +11,10 @@ public class Game {
private final Print print;
- Game(RandomNumber randomNumber,Input input,Print print){
- this.randomNumber=randomNumber;
- this.input=input;
- this.print=print;
+ Game(RandomNumber randomNumber, Input input, Print print) {
+ this.randomNumber = randomNumber;
+ this.input = input;
+ this.print = print;
}
private List> getRandomNumbers(int amount) {
@@ -25,46 +25,49 @@ private List> getRandomNumbers(int amount) {
}
return list;
}
- private void calculateWinCounts(int[] place, int idx, List winCounts){
- if(winCounts.get(idx)[0]==6){
+
+ private void calculateWinCounts(int[] place, int idx, List winCounts) {
+ if (winCounts.get(idx)[0] == 6) {
place[0]++;
return;
}
- if(winCounts.get(idx)[0]==5){
- if(winCounts.get(idx)[1]==1){
+ if (winCounts.get(idx)[0] == 5) {
+ if (winCounts.get(idx)[1] == 1) {
place[1]++;
return;
}
place[2]++;
return;
}
- if(winCounts.get(idx)[0]==4){
+ if (winCounts.get(idx)[0] == 4) {
place[3]++;
return;
}
- if(winCounts.get(idx)[0]==3){
+ if (winCounts.get(idx)[0] == 3) {
place[4]++;
}
}
- private int[] getWinCounts(List winCounts){
- int [] place=new int[5];
- for(int i=0;i winCounts) {
+ int[] place = new int[5];
+ for (int i = 0; i < winCounts.size(); i++) {
+ calculateWinCounts(place, i, winCounts);
}
return place;
}
- public void run(){
- List winCounts=new ArrayList<>();
- int price=input.getPurchacePrice();
- int amount =price/1000;
- List> list=getRandomNumbers(amount);
- print.printAmount(amount);
- List winningNumber=input.getWiningNumber();
- for(int i = 0; i< amount; i++){
- Compare compare=new Compare(winningNumber,list.get(i));
+
+ public void run() {
+ List winCounts = new ArrayList<>();
+ int price = input.getPurchacePrice();
+ int amount = price / 1000;
+ List> list = getRandomNumbers(amount);
+ print.printAmountMessage(amount);
+ List winningNumber = input.getWiningNumber();
+ for (int i = 0; i < amount; i++) {
+ Compare compare = new Compare(winningNumber, list.get(i));
winCounts.add(compare.winCount(compare.compare()));
}
- int[] place=getWinCounts(winCounts);
- print.printResult(place,price);
+ int[] place = getWinCounts(winCounts);
+ print.printResult(place, price);
}
}
diff --git a/src/main/java/lotto/Input.java b/src/main/java/lotto/Input.java
index c91c78b771..fe36034b2c 100644
--- a/src/main/java/lotto/Input.java
+++ b/src/main/java/lotto/Input.java
@@ -10,44 +10,46 @@
public class Input {
private final Print print;
- Input(){
- print=new Print();
+ Input() {
+ print = new Print();
}
- public int getPurchacePrice(){
- print.printGetPrice();
- String input=Console.readLine();
+ public int getPurchacePrice() {
+ print.printGetPriceMessage();
+ String input = Console.readLine();
validatePrice(input);
- int result=Integer.parseInt(input);
+ int result = Integer.parseInt(input);
return result;
}
- public List getWiningNumber(){
- print.printWinningNumber();
- String input=Console.readLine();
- String[] splitResult=input.split(",");
- List result=new ArrayList<>();
- for(String oneSplitResult:splitResult){
- int oneInput=Integer.parseInt(oneSplitResult);
+ public List getWiningNumber() {
+ print.printWinningNumberMessage();
+ String input = Console.readLine();
+ String[] splitResult = input.split(",");
+ List result = new ArrayList<>();
+ for (String oneSplitResult : splitResult) {
+ int oneInput = Integer.parseInt(oneSplitResult);
result.add(oneInput);
}
validateWinningNumber(result);
- print.printBonusNumber();
- input=Console.readLine();
+ print.printBonusNumberMessage();
+ input = Console.readLine();
result.add(Integer.parseInt(input));
validateWinningNumber(result);
return result;
}
+
private void validatePrice(String input) {
- for(int i=0;i MAX_BOUND_CHAR){
+ for (int i = 0; i < input.length(); i++) {
+ if (input.charAt(i) < MIN_BOUND_CHAR || input.charAt(i) > MAX_BOUND_CHAR) {
throw new IllegalArgumentException("[ERROR]");
}
}
}
+
private void validateWinningNumber(List input) {
- for(int i=0;i MAX_BOUND){
+ for (int i = 0; i < input.size(); i++) {
+ if (input.get(i) < MIN_BOUND || input.get(i) > MAX_BOUND) {
System.out.println("[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다.");
throw new IllegalArgumentException("[ERROR]");
}
diff --git a/src/main/java/lotto/Message.java b/src/main/java/lotto/Message.java
index 48752754f7..c149c8f469 100644
--- a/src/main/java/lotto/Message.java
+++ b/src/main/java/lotto/Message.java
@@ -15,6 +15,12 @@ public enum Message {
EQUAL_SIX("6개 일치 (2,000,000,000원) - ");
private final String value;
- Message(String value) { this.value = value; }
- public String getValue() { return value; }
+
+ Message(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
}
diff --git a/src/main/java/lotto/Print.java b/src/main/java/lotto/Print.java
index a11047d285..f1faf99c43 100644
--- a/src/main/java/lotto/Print.java
+++ b/src/main/java/lotto/Print.java
@@ -3,49 +3,59 @@
import static lotto.Message.*;
public class Print {
- public int printSix(int value){
- System.out.println(EQUAL_SIX.getValue()+value+"개");
- return 2000000000*value;
+ public int printSix(int value) {
+ System.out.println(EQUAL_SIX.getValue() + value + "개");
+ return 2000000000 * value;
}
- public int printFive(int value){
- System.out.println(EQUAL_FIVE.getValue()+value+"개");
- return 1500000*value;
+
+ public int printFive(int value) {
+ System.out.println(EQUAL_FIVE.getValue() + value + "개");
+ return 1500000 * value;
}
- public int printFiveBonus(int value){
- System.out.println(EQUAL_FIVE_BONUS.getValue()+value+"개");
- return 30000000*value;
+
+ public int printFiveBonus(int value) {
+ System.out.println(EQUAL_FIVE_BONUS.getValue() + value + "개");
+ return 30000000 * value;
}
- public int printFour(int value){
- System.out.println(EQUAL_FOUR.getValue()+value+"개");
- return 50000*value;
+
+ public int printFour(int value) {
+ System.out.println(EQUAL_FOUR.getValue() + value + "개");
+ return 50000 * value;
}
- public int printThree(int value){
- System.out.println(EQUAL_THREE.getValue()+value+"개");
- return 5000*value;
+
+ public int printThree(int value) {
+ System.out.println(EQUAL_THREE.getValue() + value + "개");
+ return 5000 * value;
}
- public void printProfitResult(int result, int price){
- System.out.println("총 수익률은 "+100*((double)result/price)+"%입니다.");
+
+ public void printProfitResultMessage(int result, int price) {
+ System.out.println("총 수익률은 " + 100 * ((double) result / price) + "%입니다.");
}
- public void printAmount(int amount){
- System.out.println(+amount+ OUTPUT_AMOUNT.getValue());
+
+ public void printAmountMessage(int amount) {
+ System.out.println(+amount + OUTPUT_AMOUNT.getValue());
}
- public void printGetPrice(){
+
+ public void printGetPriceMessage() {
System.out.println(INPUT_PRICE.getValue());
}
- public void printWinningNumber(){
+
+ public void printWinningNumberMessage() {
System.out.println(INPUT_NUMBER.getValue());
}
- public void printBonusNumber(){
+
+ public void printBonusNumberMessage() {
System.out.println(INPUT_BONUS.getValue());
}
- public void printResult(int[] place,int price){
- int result=0;
- result+=printThree(place[4]);
- result+=printFour(place[3]);
- result+=printFive(place[2]);
- result+=printFiveBonus(place[1]);
- result+=printSix(place[0]);
- printProfitResult(result,price);
+
+ public void printResult(int[] place, int price) {
+ int result = 0;
+ result += printThree(place[4]);
+ result += printFour(place[3]);
+ result += printFive(place[2]);
+ result += printFiveBonus(place[1]);
+ result += printSix(place[0]);
+ printProfitResultMessage(result, price);
}
}
diff --git a/src/main/java/lotto/RandomNumber.java b/src/main/java/lotto/RandomNumber.java
index eb17f885a8..019db6b495 100644
--- a/src/main/java/lotto/RandomNumber.java
+++ b/src/main/java/lotto/RandomNumber.java
@@ -8,8 +8,8 @@
public class RandomNumber {
- public List getRandomNumber(){
- List randomNumber= new ArrayList<>(Randoms.pickUniqueNumbersInRange(MIN_BOUND, MAX_BOUND, DIGITS));
+ public List getRandomNumber() {
+ List randomNumber = new ArrayList<>(Randoms.pickUniqueNumbersInRange(MIN_BOUND, MAX_BOUND, DIGITS));
Collections.sort(randomNumber);
System.out.println(randomNumber);
return randomNumber;
From c776e0b1d0f75d38afe31e525d82fba7bf5d951b Mon Sep 17 00:00:00 2001
From: kwonyonghyun
Date: Fri, 7 Jul 2023 00:27:52 +0900
Subject: [PATCH 09/19] =?UTF-8?q?=EA=B0=80=EB=8F=85=EC=84=B1=20=EB=86=92?=
=?UTF-8?q?=EC=9D=B4=EA=B8=B0=20=EC=A0=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/Application.java | 8 +-------
src/main/java/lotto/Compare.java | 1 -
src/main/java/lotto/Input.java | 10 ++++++++--
src/main/java/lotto/Print.java | 8 ++++++++
src/main/java/lotto/RandomNumber.java | 7 +++++++
5 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java
index 5e60a1c30d..749fbf6847 100644
--- a/src/main/java/lotto/Application.java
+++ b/src/main/java/lotto/Application.java
@@ -1,16 +1,10 @@
package lotto;
-import camp.nextstep.edu.missionutils.Console;
-
-import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeSet;
public class Application {
public static void main(String[] args) throws IllegalArgumentException {
// TODO: 프로그램 구현
- Input input = new Input();
- Game game = new Game(new RandomNumber(), new Input(), new Print());
+ Game game = new Game(RandomNumber.getInstance(), Input.getInstance(), Print.getInstance());
try {
game.run();
} catch (Exception e) {
diff --git a/src/main/java/lotto/Compare.java b/src/main/java/lotto/Compare.java
index be5ea5a7a2..55c979687e 100644
--- a/src/main/java/lotto/Compare.java
+++ b/src/main/java/lotto/Compare.java
@@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import java.util.Set;
import static lotto.Constant.*;
diff --git a/src/main/java/lotto/Input.java b/src/main/java/lotto/Input.java
index fe36034b2c..220fb8e942 100644
--- a/src/main/java/lotto/Input.java
+++ b/src/main/java/lotto/Input.java
@@ -9,9 +9,15 @@
public class Input {
private final Print print;
+ public static Input input;
- Input() {
- print = new Print();
+ private Input() {
+ print=Print.getInstance();
+ input=new Input();
+ }
+
+ public static Input getInstance(){
+ return input;
}
public int getPurchacePrice() {
diff --git a/src/main/java/lotto/Print.java b/src/main/java/lotto/Print.java
index f1faf99c43..26b27d70ea 100644
--- a/src/main/java/lotto/Print.java
+++ b/src/main/java/lotto/Print.java
@@ -3,6 +3,14 @@
import static lotto.Message.*;
public class Print {
+ private static Print print;
+ private Print(){
+ print=new Print();
+ }
+ public static Print getInstance() {
+ return print;
+ }
+
public int printSix(int value) {
System.out.println(EQUAL_SIX.getValue() + value + "개");
return 2000000000 * value;
diff --git a/src/main/java/lotto/RandomNumber.java b/src/main/java/lotto/RandomNumber.java
index 019db6b495..53e4316698 100644
--- a/src/main/java/lotto/RandomNumber.java
+++ b/src/main/java/lotto/RandomNumber.java
@@ -8,6 +8,13 @@
public class RandomNumber {
+ private static RandomNumber randomNumber;
+ private RandomNumber(){
+ randomNumber=new RandomNumber();
+ }
+ public static RandomNumber getInstance() {
+ return randomNumber;
+ }
public List getRandomNumber() {
List randomNumber = new ArrayList<>(Randoms.pickUniqueNumbersInRange(MIN_BOUND, MAX_BOUND, DIGITS));
Collections.sort(randomNumber);
From 65bcd185fd42008af2b770008885322cd91d1892 Mon Sep 17 00:00:00 2001
From: kwonyonghyun
Date: Fri, 7 Jul 2023 00:31:48 +0900
Subject: [PATCH 10/19] =?UTF-8?q?=EC=8B=B1=EA=B8=80=ED=86=A4=20=EC=A0=81?=
=?UTF-8?q?=EC=9A=A9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/Input.java | 4 +++-
src/main/java/lotto/Print.java | 7 ++++---
src/main/java/lotto/RandomNumber.java | 7 ++++---
3 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/src/main/java/lotto/Input.java b/src/main/java/lotto/Input.java
index 220fb8e942..ae38b5dd41 100644
--- a/src/main/java/lotto/Input.java
+++ b/src/main/java/lotto/Input.java
@@ -13,10 +13,12 @@ public class Input {
private Input() {
print=Print.getInstance();
- input=new Input();
}
public static Input getInstance(){
+ if(input==null){
+ input=new Input();
+ }
return input;
}
diff --git a/src/main/java/lotto/Print.java b/src/main/java/lotto/Print.java
index 26b27d70ea..b4912ece61 100644
--- a/src/main/java/lotto/Print.java
+++ b/src/main/java/lotto/Print.java
@@ -4,10 +4,11 @@
public class Print {
private static Print print;
- private Print(){
- print=new Print();
- }
+ private Print(){}
public static Print getInstance() {
+ if(print==null){
+ print=new Print();
+ }
return print;
}
diff --git a/src/main/java/lotto/RandomNumber.java b/src/main/java/lotto/RandomNumber.java
index 53e4316698..8dcf388cb6 100644
--- a/src/main/java/lotto/RandomNumber.java
+++ b/src/main/java/lotto/RandomNumber.java
@@ -9,10 +9,11 @@
public class RandomNumber {
private static RandomNumber randomNumber;
- private RandomNumber(){
- randomNumber=new RandomNumber();
- }
+ private RandomNumber(){}
public static RandomNumber getInstance() {
+ if(randomNumber==null){
+ randomNumber=new RandomNumber();
+ }
return randomNumber;
}
public List getRandomNumber() {
From b84d9f392c9fe53108f6e0733a0e15b2a6ada623 Mon Sep 17 00:00:00 2001
From: kwonyonghyun
Date: Fri, 7 Jul 2023 00:35:41 +0900
Subject: [PATCH 11/19] =?UTF-8?q?=EC=B5=9C=EC=A2=85?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/Application.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java
index 749fbf6847..b436eebefc 100644
--- a/src/main/java/lotto/Application.java
+++ b/src/main/java/lotto/Application.java
@@ -2,7 +2,7 @@
public class Application {
- public static void main(String[] args) throws IllegalArgumentException {
+ public static void main(String[] args){
// TODO: 프로그램 구현
Game game = new Game(RandomNumber.getInstance(), Input.getInstance(), Print.getInstance());
try {
From 070b96a0a9ca8473ae8c32547058cdd93b9099c5 Mon Sep 17 00:00:00 2001
From: kwonyonghyun
Date: Fri, 7 Jul 2023 09:52:42 +0900
Subject: [PATCH 12/19] =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=EC=99=80=20?=
=?UTF-8?q?=ED=94=84=EB=A6=B0=ED=8A=B8=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?=
=?UTF-8?q?=EC=88=98=EC=A0=95=EB=B3=B8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/Application.java | 2 +-
src/main/java/lotto/Game.java | 2 +-
src/main/java/lotto/Input.java | 10 +++++-----
src/main/java/lotto/Message.java | 11 ++++++++++-
src/main/java/lotto/Print.java | 21 ++++++++++++---------
src/main/java/lotto/RandomNumber.java | 10 +++++++---
6 files changed, 36 insertions(+), 20 deletions(-)
diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java
index b436eebefc..2926028c56 100644
--- a/src/main/java/lotto/Application.java
+++ b/src/main/java/lotto/Application.java
@@ -2,7 +2,7 @@
public class Application {
- public static void main(String[] args){
+ public static void main(String[] args) {
// TODO: 프로그램 구현
Game game = new Game(RandomNumber.getInstance(), Input.getInstance(), Print.getInstance());
try {
diff --git a/src/main/java/lotto/Game.java b/src/main/java/lotto/Game.java
index 94591a25bd..e04c48228f 100644
--- a/src/main/java/lotto/Game.java
+++ b/src/main/java/lotto/Game.java
@@ -58,7 +58,7 @@ private int[] getWinCounts(List winCounts) {
public void run() {
List winCounts = new ArrayList<>();
- int price = input.getPurchacePrice();
+ int price = input.getPurchasePrice();
int amount = price / 1000;
List> list = getRandomNumbers(amount);
print.printAmountMessage(amount);
diff --git a/src/main/java/lotto/Input.java b/src/main/java/lotto/Input.java
index ae38b5dd41..fe376830c7 100644
--- a/src/main/java/lotto/Input.java
+++ b/src/main/java/lotto/Input.java
@@ -12,17 +12,17 @@ public class Input {
public static Input input;
private Input() {
- print=Print.getInstance();
+ print = Print.getInstance();
}
- public static Input getInstance(){
- if(input==null){
- input=new Input();
+ public static Input getInstance() {
+ if (input == null) {
+ input = new Input();
}
return input;
}
- public int getPurchacePrice() {
+ public int getPurchasePrice() {
print.printGetPriceMessage();
String input = Console.readLine();
validatePrice(input);
diff --git a/src/main/java/lotto/Message.java b/src/main/java/lotto/Message.java
index c149c8f469..7fe320ab6b 100644
--- a/src/main/java/lotto/Message.java
+++ b/src/main/java/lotto/Message.java
@@ -12,7 +12,8 @@ public enum Message {
EQUAL_FOUR("4개 일치 (50,000원) - "),
EQUAL_FIVE("5개 일치 (1,500,000원) - "),
EQUAL_FIVE_BONUS("5개 일치, 보너스 볼 일치 (30,000,000원) - "),
- EQUAL_SIX("6개 일치 (2,000,000,000원) - ");
+ EQUAL_SIX("6개 일치 (2,000,000,000원) - "),
+ PROFIT_RESULT("총 수익률은 ");
private final String value;
@@ -23,4 +24,12 @@ public enum Message {
public String getValue() {
return value;
}
+
+ public String getEqualValue(int x) {
+ return value + x + "개";
+ }
+
+ public String getProfitValue(int result, int price) {
+ return value + 100 * ((double) result / price) + "%입니다.";
+ }
}
diff --git a/src/main/java/lotto/Print.java b/src/main/java/lotto/Print.java
index b4912ece61..5a0b507864 100644
--- a/src/main/java/lotto/Print.java
+++ b/src/main/java/lotto/Print.java
@@ -4,41 +4,44 @@
public class Print {
private static Print print;
- private Print(){}
+
+ private Print() {
+ }
+
public static Print getInstance() {
- if(print==null){
- print=new Print();
+ if (print == null) {
+ print = new Print();
}
return print;
}
public int printSix(int value) {
- System.out.println(EQUAL_SIX.getValue() + value + "개");
+ System.out.println(EQUAL_SIX.getEqualValue(value));
return 2000000000 * value;
}
public int printFive(int value) {
- System.out.println(EQUAL_FIVE.getValue() + value + "개");
+ System.out.println(EQUAL_FIVE.getEqualValue(value));
return 1500000 * value;
}
public int printFiveBonus(int value) {
- System.out.println(EQUAL_FIVE_BONUS.getValue() + value + "개");
+ System.out.println(EQUAL_FIVE_BONUS.getEqualValue(value));
return 30000000 * value;
}
public int printFour(int value) {
- System.out.println(EQUAL_FOUR.getValue() + value + "개");
+ System.out.println(EQUAL_FOUR.getEqualValue(value));
return 50000 * value;
}
public int printThree(int value) {
- System.out.println(EQUAL_THREE.getValue() + value + "개");
+ System.out.println(EQUAL_THREE.getEqualValue(value));
return 5000 * value;
}
public void printProfitResultMessage(int result, int price) {
- System.out.println("총 수익률은 " + 100 * ((double) result / price) + "%입니다.");
+ System.out.println(PROFIT_RESULT.getProfitValue(result, price));
}
public void printAmountMessage(int amount) {
diff --git a/src/main/java/lotto/RandomNumber.java b/src/main/java/lotto/RandomNumber.java
index 8dcf388cb6..66f83503b2 100644
--- a/src/main/java/lotto/RandomNumber.java
+++ b/src/main/java/lotto/RandomNumber.java
@@ -9,13 +9,17 @@
public class RandomNumber {
private static RandomNumber randomNumber;
- private RandomNumber(){}
+
+ private RandomNumber() {
+ }
+
public static RandomNumber getInstance() {
- if(randomNumber==null){
- randomNumber=new RandomNumber();
+ if (randomNumber == null) {
+ randomNumber = new RandomNumber();
}
return randomNumber;
}
+
public List getRandomNumber() {
List randomNumber = new ArrayList<>(Randoms.pickUniqueNumbersInRange(MIN_BOUND, MAX_BOUND, DIGITS));
Collections.sort(randomNumber);
From 0528898061fd1eddf10bb121d07e08f27903a2db Mon Sep 17 00:00:00 2001
From: kwonyonghyun
Date: Fri, 7 Jul 2023 16:47:41 +0900
Subject: [PATCH 13/19] =?UTF-8?q?=EC=9D=B8=ED=84=B0=ED=8E=98=EC=9D=B4?=
=?UTF-8?q?=EC=8A=A4=20=EC=B6=94=EA=B0=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/Application.java | 2 +-
src/main/java/lotto/Compare.java | 34 ++-------
src/main/java/lotto/CompareImpl.java | 41 +++++++++++
src/main/java/lotto/Game.java | 68 ++----------------
src/main/java/lotto/GameImpl.java | 78 +++++++++++++++++++++
src/main/java/lotto/Input.java | 59 ++--------------
src/main/java/lotto/InputImpl.java | 71 +++++++++++++++++++
src/main/java/lotto/Print.java | 71 ++++---------------
src/main/java/lotto/PrintImpl.java | 85 +++++++++++++++++++++++
src/main/java/lotto/RandomNumber.java | 28 +-------
src/main/java/lotto/RandomNumberImpl.java | 30 ++++++++
11 files changed, 337 insertions(+), 230 deletions(-)
create mode 100644 src/main/java/lotto/CompareImpl.java
create mode 100644 src/main/java/lotto/GameImpl.java
create mode 100644 src/main/java/lotto/InputImpl.java
create mode 100644 src/main/java/lotto/PrintImpl.java
create mode 100644 src/main/java/lotto/RandomNumberImpl.java
diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java
index 2926028c56..3c2538bc8c 100644
--- a/src/main/java/lotto/Application.java
+++ b/src/main/java/lotto/Application.java
@@ -4,7 +4,7 @@
public class Application {
public static void main(String[] args) {
// TODO: 프로그램 구현
- Game game = new Game(RandomNumber.getInstance(), Input.getInstance(), Print.getInstance());
+ Game game = new GameImpl(RandomNumberImpl.getInstance(), InputImpl.getInstance(), PrintImpl.getInstance());
try {
game.run();
} catch (Exception e) {
diff --git a/src/main/java/lotto/Compare.java b/src/main/java/lotto/Compare.java
index 55c979687e..8fb00ef7b5 100644
--- a/src/main/java/lotto/Compare.java
+++ b/src/main/java/lotto/Compare.java
@@ -4,36 +4,10 @@
import java.util.Collections;
import java.util.List;
-import static lotto.Constant.*;
+import static lotto.Constant.DIGITS;
-public class Compare {
+public interface Compare {
+ public List compare();
- private final List input;
- private final List randomNumber;
-
- Compare(List input, List randomNumber) {
- this.input = input;
- this.randomNumber = randomNumber;
- }
-
- public List compare() {
- List result = new ArrayList<>();
- for (int i = 0; i < DIGITS; i++) {
- Integer a = input.get(i);
- if (randomNumber.contains(a)) {
- result.add(1);
- }
- }
- if (randomNumber.contains(input.get(DIGITS))) {
- result.add(2);
- }
- return result;
- }
-
- public int[] winCount(List list) {
- int[] result = new int[2];
- result[0] = Collections.frequency(list, 1);
- result[1] = Collections.frequency(list, 2);
- return result;
- }
+ public int[] winCount(List list);
}
diff --git a/src/main/java/lotto/CompareImpl.java b/src/main/java/lotto/CompareImpl.java
new file mode 100644
index 0000000000..447dc84576
--- /dev/null
+++ b/src/main/java/lotto/CompareImpl.java
@@ -0,0 +1,41 @@
+package lotto;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import static lotto.Constant.*;
+
+public class CompareImpl implements Compare {
+
+ private final List input;
+ private final List randomNumber;
+
+ CompareImpl(List input, List randomNumber) {
+ this.input = input;
+ this.randomNumber = randomNumber;
+ }
+
+ @Override
+ public List compare() {
+ List result = new ArrayList<>();
+ for (int i = 0; i < DIGITS; i++) {
+ Integer a = input.get(i);
+ if (randomNumber.contains(a)) {
+ result.add(1);
+ }
+ }
+ if (randomNumber.contains(input.get(DIGITS))) {
+ result.add(2);
+ }
+ return result;
+ }
+
+ @Override
+ public int[] winCount(List list) {
+ int[] result = new int[2];
+ result[0] = Collections.frequency(list, 1);
+ result[1] = Collections.frequency(list, 2);
+ return result;
+ }
+}
diff --git a/src/main/java/lotto/Game.java b/src/main/java/lotto/Game.java
index e04c48228f..c455db7451 100644
--- a/src/main/java/lotto/Game.java
+++ b/src/main/java/lotto/Game.java
@@ -3,71 +3,13 @@
import java.util.ArrayList;
import java.util.List;
-public class Game {
+public interface Game {
+ List> getRandomNumbers(int amount);
- private final RandomNumber randomNumber;
- private final Input input;
- private final Print print;
+ void calculateWinCounts(int[] place, int idx, List winCounts);
+ int[] getWinCounts(List winCounts);
- Game(RandomNumber randomNumber, Input input, Print print) {
- this.randomNumber = randomNumber;
- this.input = input;
- this.print = print;
- }
-
- private List> getRandomNumbers(int amount) {
- List> list = new ArrayList<>();
- for (int i = 0; i < amount; i++) {
- List randomNumbers = randomNumber.getRandomNumber();
- list.add(randomNumbers);
- }
- return list;
- }
-
- private void calculateWinCounts(int[] place, int idx, List winCounts) {
- if (winCounts.get(idx)[0] == 6) {
- place[0]++;
- return;
- }
- if (winCounts.get(idx)[0] == 5) {
- if (winCounts.get(idx)[1] == 1) {
- place[1]++;
- return;
- }
- place[2]++;
- return;
- }
- if (winCounts.get(idx)[0] == 4) {
- place[3]++;
- return;
- }
- if (winCounts.get(idx)[0] == 3) {
- place[4]++;
- }
- }
-
- private int[] getWinCounts(List winCounts) {
- int[] place = new int[5];
- for (int i = 0; i < winCounts.size(); i++) {
- calculateWinCounts(place, i, winCounts);
- }
- return place;
- }
-
- public void run() {
- List winCounts = new ArrayList<>();
- int price = input.getPurchasePrice();
- int amount = price / 1000;
- List> list = getRandomNumbers(amount);
- print.printAmountMessage(amount);
- List winningNumber = input.getWiningNumber();
- for (int i = 0; i < amount; i++) {
- Compare compare = new Compare(winningNumber, list.get(i));
- winCounts.add(compare.winCount(compare.compare()));
- }
- int[] place = getWinCounts(winCounts);
- print.printResult(place, price);
- }
+ public void run();
}
diff --git a/src/main/java/lotto/GameImpl.java b/src/main/java/lotto/GameImpl.java
new file mode 100644
index 0000000000..434db3d2df
--- /dev/null
+++ b/src/main/java/lotto/GameImpl.java
@@ -0,0 +1,78 @@
+package lotto;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class GameImpl implements Game {
+
+
+ private final RandomNumber randomNumber;
+ private final Input input;
+ private final Print print;
+ private Compare compare;
+
+
+ GameImpl(RandomNumber randomNumber, Input input, Print print) {
+ this.randomNumber = randomNumber;
+ this.input = input;
+ this.print = print;
+ }
+
+ @Override
+ public List> getRandomNumbers(int amount) {
+ List> list = new ArrayList<>();
+ for (int i = 0; i < amount; i++) {
+ List randomNumbers = randomNumber.getRandomNumber();
+ list.add(randomNumbers);
+ }
+ return list;
+ }
+
+ @Override
+ public void calculateWinCounts(int[] place, int idx, List winCounts) {
+ if (winCounts.get(idx)[0] == 6) {
+ place[0]++;
+ return;
+ }
+ if (winCounts.get(idx)[0] == 5) {
+ if (winCounts.get(idx)[1] == 1) {
+ place[1]++;
+ return;
+ }
+ place[2]++;
+ return;
+ }
+ if (winCounts.get(idx)[0] == 4) {
+ place[3]++;
+ return;
+ }
+ if (winCounts.get(idx)[0] == 3) {
+ place[4]++;
+ }
+ }
+
+ @Override
+ public int[] getWinCounts(List winCounts) {
+ int[] place = new int[5];
+ for (int i = 0; i < winCounts.size(); i++) {
+ calculateWinCounts(place, i, winCounts);
+ }
+ return place;
+ }
+
+ @Override
+ public void run() {
+ List winCounts = new ArrayList<>();
+ int price = input.getPurchasePrice();
+ int amount = price / 1000;
+ List> list = getRandomNumbers(amount);
+ print.printAmountMessage(amount);
+ List winningNumber = input.getWiningNumber();
+ for (int i = 0; i < amount; i++) {
+ compare = new CompareImpl(winningNumber, list.get(i));
+ winCounts.add(compare.winCount(compare.compare()));
+ }
+ int[] place = getWinCounts(winCounts);
+ print.printResult(place, price);
+ }
+}
diff --git a/src/main/java/lotto/Input.java b/src/main/java/lotto/Input.java
index fe376830c7..0448512e75 100644
--- a/src/main/java/lotto/Input.java
+++ b/src/main/java/lotto/Input.java
@@ -6,62 +6,15 @@
import java.util.List;
import static lotto.Constant.*;
+import static lotto.Constant.MAX_BOUND;
-public class Input {
- private final Print print;
- public static Input input;
+public interface Input {
- private Input() {
- print = Print.getInstance();
- }
+ public int getPurchasePrice();
- public static Input getInstance() {
- if (input == null) {
- input = new Input();
- }
- return input;
- }
+ public List getWiningNumber();
- public int getPurchasePrice() {
- print.printGetPriceMessage();
- String input = Console.readLine();
- validatePrice(input);
- int result = Integer.parseInt(input);
- return result;
- }
-
- public List getWiningNumber() {
- print.printWinningNumberMessage();
- String input = Console.readLine();
- String[] splitResult = input.split(",");
- List result = new ArrayList<>();
- for (String oneSplitResult : splitResult) {
- int oneInput = Integer.parseInt(oneSplitResult);
- result.add(oneInput);
- }
- validateWinningNumber(result);
- print.printBonusNumberMessage();
- input = Console.readLine();
- result.add(Integer.parseInt(input));
- validateWinningNumber(result);
- return result;
- }
-
- private void validatePrice(String input) {
- for (int i = 0; i < input.length(); i++) {
- if (input.charAt(i) < MIN_BOUND_CHAR || input.charAt(i) > MAX_BOUND_CHAR) {
- throw new IllegalArgumentException("[ERROR]");
- }
- }
- }
-
- private void validateWinningNumber(List input) {
- for (int i = 0; i < input.size(); i++) {
- if (input.get(i) < MIN_BOUND || input.get(i) > MAX_BOUND) {
- System.out.println("[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다.");
- throw new IllegalArgumentException("[ERROR]");
- }
- }
- }
+ public void validatePrice(String input);
+ public void validateWinningNumber(List input);
}
diff --git a/src/main/java/lotto/InputImpl.java b/src/main/java/lotto/InputImpl.java
new file mode 100644
index 0000000000..32d6a34860
--- /dev/null
+++ b/src/main/java/lotto/InputImpl.java
@@ -0,0 +1,71 @@
+package lotto;
+
+import camp.nextstep.edu.missionutils.Console;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static lotto.Constant.*;
+
+public class InputImpl implements Input {
+ private final Print print;
+ public static InputImpl input;
+
+ private InputImpl() {
+ print = PrintImpl.getInstance();
+ }
+
+ public static InputImpl getInstance() {
+ if (input == null) {
+ input = new InputImpl();
+ }
+ return input;
+ }
+
+ @Override
+ public int getPurchasePrice() {
+ print.printGetPriceMessage();
+ String input = Console.readLine();
+ validatePrice(input);
+ int result = Integer.parseInt(input);
+ return result;
+ }
+
+ @Override
+ public List getWiningNumber() {
+ print.printWinningNumberMessage();
+ String input = Console.readLine();
+ String[] splitResult = input.split(",");
+ List result = new ArrayList<>();
+ for (String oneSplitResult : splitResult) {
+ int oneInput = Integer.parseInt(oneSplitResult);
+ result.add(oneInput);
+ }
+ validateWinningNumber(result);
+ print.printBonusNumberMessage();
+ input = Console.readLine();
+ result.add(Integer.parseInt(input));
+ validateWinningNumber(result);
+ return result;
+ }
+
+ @Override
+ public void validatePrice(String input) {
+ for (int i = 0; i < input.length(); i++) {
+ if (input.charAt(i) < MIN_BOUND_CHAR || input.charAt(i) > MAX_BOUND_CHAR) {
+ throw new IllegalArgumentException("[ERROR]");
+ }
+ }
+ }
+
+ @Override
+ public void validateWinningNumber(List input) {
+ for (int i = 0; i < input.size(); i++) {
+ if (input.get(i) < MIN_BOUND || input.get(i) > MAX_BOUND) {
+ System.out.println("[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다.");
+ throw new IllegalArgumentException("[ERROR]");
+ }
+ }
+ }
+
+}
diff --git a/src/main/java/lotto/Print.java b/src/main/java/lotto/Print.java
index 5a0b507864..128ef5eebd 100644
--- a/src/main/java/lotto/Print.java
+++ b/src/main/java/lotto/Print.java
@@ -1,73 +1,28 @@
package lotto;
import static lotto.Message.*;
+import static lotto.Message.INPUT_BONUS;
-public class Print {
- private static Print print;
+public interface Print {
+ public int printSix(int value);
- private Print() {
- }
+ public int printFive(int value);
- public static Print getInstance() {
- if (print == null) {
- print = new Print();
- }
- return print;
- }
+ public int printFiveBonus(int value);
- public int printSix(int value) {
- System.out.println(EQUAL_SIX.getEqualValue(value));
- return 2000000000 * value;
- }
+ public int printFour(int value);
- public int printFive(int value) {
- System.out.println(EQUAL_FIVE.getEqualValue(value));
- return 1500000 * value;
- }
+ public int printThree(int value);
- public int printFiveBonus(int value) {
- System.out.println(EQUAL_FIVE_BONUS.getEqualValue(value));
- return 30000000 * value;
- }
+ public void printProfitResultMessage(int result, int price);
- public int printFour(int value) {
- System.out.println(EQUAL_FOUR.getEqualValue(value));
- return 50000 * value;
- }
+ public void printAmountMessage(int amount);
- public int printThree(int value) {
- System.out.println(EQUAL_THREE.getEqualValue(value));
- return 5000 * value;
- }
+ public void printGetPriceMessage();
- public void printProfitResultMessage(int result, int price) {
- System.out.println(PROFIT_RESULT.getProfitValue(result, price));
- }
+ public void printWinningNumberMessage();
- public void printAmountMessage(int amount) {
- System.out.println(+amount + OUTPUT_AMOUNT.getValue());
- }
-
- public void printGetPriceMessage() {
- System.out.println(INPUT_PRICE.getValue());
- }
-
- public void printWinningNumberMessage() {
- System.out.println(INPUT_NUMBER.getValue());
- }
-
- public void printBonusNumberMessage() {
- System.out.println(INPUT_BONUS.getValue());
- }
-
- public void printResult(int[] place, int price) {
- int result = 0;
- result += printThree(place[4]);
- result += printFour(place[3]);
- result += printFive(place[2]);
- result += printFiveBonus(place[1]);
- result += printSix(place[0]);
- printProfitResultMessage(result, price);
- }
+ public void printBonusNumberMessage();
+ public void printResult(int[] place, int price);
}
diff --git a/src/main/java/lotto/PrintImpl.java b/src/main/java/lotto/PrintImpl.java
new file mode 100644
index 0000000000..4a9f1e6f23
--- /dev/null
+++ b/src/main/java/lotto/PrintImpl.java
@@ -0,0 +1,85 @@
+package lotto;
+
+import static lotto.Message.*;
+
+public class PrintImpl implements Print{
+ private static PrintImpl print;
+
+ private PrintImpl() {
+ }
+
+
+ public static PrintImpl getInstance() {
+ if (print == null) {
+ print = new PrintImpl();
+ }
+ return print;
+ }
+
+ @Override
+ public int printSix(int value) {
+ System.out.println(EQUAL_SIX.getEqualValue(value));
+ return 2000000000 * value;
+ }
+
+ @Override
+ public int printFive(int value) {
+ System.out.println(EQUAL_FIVE.getEqualValue(value));
+ return 1500000 * value;
+ }
+
+ @Override
+ public int printFiveBonus(int value) {
+ System.out.println(EQUAL_FIVE_BONUS.getEqualValue(value));
+ return 30000000 * value;
+ }
+
+ @Override
+ public int printFour(int value) {
+ System.out.println(EQUAL_FOUR.getEqualValue(value));
+ return 50000 * value;
+ }
+
+ @Override
+ public int printThree(int value) {
+ System.out.println(EQUAL_THREE.getEqualValue(value));
+ return 5000 * value;
+ }
+
+ @Override
+ public void printProfitResultMessage(int result, int price) {
+ System.out.println(PROFIT_RESULT.getProfitValue(result, price));
+ }
+
+ @Override
+ public void printAmountMessage(int amount) {
+ System.out.println(+amount + OUTPUT_AMOUNT.getValue());
+ }
+
+ @Override
+ public void printGetPriceMessage() {
+ System.out.println(INPUT_PRICE.getValue());
+ }
+
+ @Override
+ public void printWinningNumberMessage() {
+ System.out.println(INPUT_NUMBER.getValue());
+ }
+
+ @Override
+ public void printBonusNumberMessage() {
+ System.out.println(INPUT_BONUS.getValue());
+ }
+
+ @Override
+ public void printResult(int[] place, int price) {
+ int result = 0;
+ result += printThree(place[4]);
+ result += printFour(place[3]);
+ result += printFive(place[2]);
+ result += printFiveBonus(place[1]);
+ result += printSix(place[0]);
+ printProfitResultMessage(result, price);
+ }
+
+}
diff --git a/src/main/java/lotto/RandomNumber.java b/src/main/java/lotto/RandomNumber.java
index 66f83503b2..db1f4b360b 100644
--- a/src/main/java/lotto/RandomNumber.java
+++ b/src/main/java/lotto/RandomNumber.java
@@ -1,29 +1,7 @@
package lotto;
-import camp.nextstep.edu.missionutils.Randoms;
+import java.util.List;
-import java.util.*;
-
-import static lotto.Constant.*;
-
-
-public class RandomNumber {
- private static RandomNumber randomNumber;
-
- private RandomNumber() {
- }
-
- public static RandomNumber getInstance() {
- if (randomNumber == null) {
- randomNumber = new RandomNumber();
- }
- return randomNumber;
- }
-
- public List getRandomNumber() {
- List randomNumber = new ArrayList<>(Randoms.pickUniqueNumbersInRange(MIN_BOUND, MAX_BOUND, DIGITS));
- Collections.sort(randomNumber);
- System.out.println(randomNumber);
- return randomNumber;
- }
+public interface RandomNumber {
+ public List getRandomNumber();
}
diff --git a/src/main/java/lotto/RandomNumberImpl.java b/src/main/java/lotto/RandomNumberImpl.java
new file mode 100644
index 0000000000..7c2b93cc99
--- /dev/null
+++ b/src/main/java/lotto/RandomNumberImpl.java
@@ -0,0 +1,30 @@
+package lotto;
+
+import camp.nextstep.edu.missionutils.Randoms;
+
+import java.util.*;
+
+import static lotto.Constant.*;
+
+
+public class RandomNumberImpl implements RandomNumber {
+ private static RandomNumberImpl randomNumber;
+
+ private RandomNumberImpl() {
+ }
+
+ public static RandomNumberImpl getInstance() {
+ if (randomNumber == null) {
+ randomNumber = new RandomNumberImpl();
+ }
+ return randomNumber;
+ }
+
+ @Override
+ public List getRandomNumber() {
+ List randomNumber = new ArrayList<>(Randoms.pickUniqueNumbersInRange(MIN_BOUND, MAX_BOUND, DIGITS));
+ Collections.sort(randomNumber);
+ System.out.println(randomNumber);
+ return randomNumber;
+ }
+}
From f02d720756f82be8e5899b0651633d30cffde09d Mon Sep 17 00:00:00 2001
From: kwonyonghyun
Date: Fri, 7 Jul 2023 21:44:06 +0900
Subject: [PATCH 14/19] =?UTF-8?q?input=20=ED=85=8C=EC=8A=A4=ED=8A=B8?=
=?UTF-8?q?=EC=BC=80=EC=9D=B4=EC=8A=A4=20=EC=B6=94=EA=B0=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/Application.java | 6 ++
src/main/java/lotto/GameImpl.java | 78 ------------------
.../java/lotto/{ => compare}/Compare.java | 6 +-
.../java/lotto/{ => compare}/CompareImpl.java | 16 ++--
.../java/lotto/{ => constant}/Constant.java | 2 +-
.../java/lotto/{ => constant}/Message.java | 2 +-
src/main/java/lotto/{ => game}/Game.java | 5 +-
src/main/java/lotto/game/GameImpl.java | 82 +++++++++++++++++++
src/main/java/lotto/{ => input}/Input.java | 8 +-
.../java/lotto/{ => input}/InputImpl.java | 8 +-
src/main/java/lotto/{ => print}/Print.java | 5 +-
.../java/lotto/{ => print}/PrintImpl.java | 6 +-
.../{ => randomNumber}/RandomNumber.java | 2 +-
.../{ => randomNumber}/RandomNumberImpl.java | 4 +-
src/test/java/lotto/ApplicationTest.java | 2 +
src/test/java/lotto/InputTest.java | 69 ++++++++++++++++
16 files changed, 187 insertions(+), 114 deletions(-)
delete mode 100644 src/main/java/lotto/GameImpl.java
rename src/main/java/lotto/{ => compare}/Compare.java (55%)
rename src/main/java/lotto/{ => compare}/CompareImpl.java (69%)
rename src/main/java/lotto/{ => constant}/Constant.java (91%)
rename src/main/java/lotto/{ => constant}/Message.java (97%)
rename src/main/java/lotto/{ => game}/Game.java (54%)
create mode 100644 src/main/java/lotto/game/GameImpl.java
rename src/main/java/lotto/{ => input}/Input.java (59%)
rename src/main/java/lotto/{ => input}/InputImpl.java (92%)
rename src/main/java/lotto/{ => print}/Print.java (85%)
rename src/main/java/lotto/{ => print}/PrintImpl.java (95%)
rename src/main/java/lotto/{ => randomNumber}/RandomNumber.java (78%)
rename src/main/java/lotto/{ => randomNumber}/RandomNumberImpl.java (91%)
create mode 100644 src/test/java/lotto/InputTest.java
diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java
index 3c2538bc8c..07a80d221b 100644
--- a/src/main/java/lotto/Application.java
+++ b/src/main/java/lotto/Application.java
@@ -1,6 +1,12 @@
package lotto;
+import lotto.game.Game;
+import lotto.game.GameImpl;
+import lotto.input.InputImpl;
+import lotto.print.PrintImpl;
+import lotto.randomNumber.RandomNumberImpl;
+
public class Application {
public static void main(String[] args) {
// TODO: 프로그램 구현
diff --git a/src/main/java/lotto/GameImpl.java b/src/main/java/lotto/GameImpl.java
deleted file mode 100644
index 434db3d2df..0000000000
--- a/src/main/java/lotto/GameImpl.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package lotto;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class GameImpl implements Game {
-
-
- private final RandomNumber randomNumber;
- private final Input input;
- private final Print print;
- private Compare compare;
-
-
- GameImpl(RandomNumber randomNumber, Input input, Print print) {
- this.randomNumber = randomNumber;
- this.input = input;
- this.print = print;
- }
-
- @Override
- public List> getRandomNumbers(int amount) {
- List> list = new ArrayList<>();
- for (int i = 0; i < amount; i++) {
- List randomNumbers = randomNumber.getRandomNumber();
- list.add(randomNumbers);
- }
- return list;
- }
-
- @Override
- public void calculateWinCounts(int[] place, int idx, List winCounts) {
- if (winCounts.get(idx)[0] == 6) {
- place[0]++;
- return;
- }
- if (winCounts.get(idx)[0] == 5) {
- if (winCounts.get(idx)[1] == 1) {
- place[1]++;
- return;
- }
- place[2]++;
- return;
- }
- if (winCounts.get(idx)[0] == 4) {
- place[3]++;
- return;
- }
- if (winCounts.get(idx)[0] == 3) {
- place[4]++;
- }
- }
-
- @Override
- public int[] getWinCounts(List winCounts) {
- int[] place = new int[5];
- for (int i = 0; i < winCounts.size(); i++) {
- calculateWinCounts(place, i, winCounts);
- }
- return place;
- }
-
- @Override
- public void run() {
- List winCounts = new ArrayList<>();
- int price = input.getPurchasePrice();
- int amount = price / 1000;
- List> list = getRandomNumbers(amount);
- print.printAmountMessage(amount);
- List winningNumber = input.getWiningNumber();
- for (int i = 0; i < amount; i++) {
- compare = new CompareImpl(winningNumber, list.get(i));
- winCounts.add(compare.winCount(compare.compare()));
- }
- int[] place = getWinCounts(winCounts);
- print.printResult(place, price);
- }
-}
diff --git a/src/main/java/lotto/Compare.java b/src/main/java/lotto/compare/Compare.java
similarity index 55%
rename from src/main/java/lotto/Compare.java
rename to src/main/java/lotto/compare/Compare.java
index 8fb00ef7b5..b233130f00 100644
--- a/src/main/java/lotto/Compare.java
+++ b/src/main/java/lotto/compare/Compare.java
@@ -1,11 +1,7 @@
-package lotto;
+package lotto.compare;
-import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
-import static lotto.Constant.DIGITS;
-
public interface Compare {
public List compare();
diff --git a/src/main/java/lotto/CompareImpl.java b/src/main/java/lotto/compare/CompareImpl.java
similarity index 69%
rename from src/main/java/lotto/CompareImpl.java
rename to src/main/java/lotto/compare/CompareImpl.java
index 447dc84576..1565c53f11 100644
--- a/src/main/java/lotto/CompareImpl.java
+++ b/src/main/java/lotto/compare/CompareImpl.java
@@ -1,33 +1,37 @@
-package lotto;
+package lotto.compare;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
-import static lotto.Constant.*;
+import static lotto.constant.Constant.*;
public class CompareImpl implements Compare {
private final List input;
private final List randomNumber;
- CompareImpl(List input, List randomNumber) {
+ public CompareImpl(List input, List randomNumber) {
this.input = input;
this.randomNumber = randomNumber;
}
@Override
public List compare() {
- List result = new ArrayList<>();
+ List result;
+ int correct = 0;
+ int bonus = 0;
for (int i = 0; i < DIGITS; i++) {
Integer a = input.get(i);
if (randomNumber.contains(a)) {
- result.add(1);
+ correct++;
}
}
if (randomNumber.contains(input.get(DIGITS))) {
- result.add(2);
+ bonus++;
}
+ result = new ArrayList<>(Arrays.asList(correct, bonus));
return result;
}
diff --git a/src/main/java/lotto/Constant.java b/src/main/java/lotto/constant/Constant.java
similarity index 91%
rename from src/main/java/lotto/Constant.java
rename to src/main/java/lotto/constant/Constant.java
index b5bcfde585..2acfc2102d 100644
--- a/src/main/java/lotto/Constant.java
+++ b/src/main/java/lotto/constant/Constant.java
@@ -1,4 +1,4 @@
-package lotto;
+package lotto.constant;
public class Constant {
public final static int DIGITS = 6;
diff --git a/src/main/java/lotto/Message.java b/src/main/java/lotto/constant/Message.java
similarity index 97%
rename from src/main/java/lotto/Message.java
rename to src/main/java/lotto/constant/Message.java
index 7fe320ab6b..16569fd505 100644
--- a/src/main/java/lotto/Message.java
+++ b/src/main/java/lotto/constant/Message.java
@@ -1,4 +1,4 @@
-package lotto;
+package lotto.constant;
public enum Message {
diff --git a/src/main/java/lotto/Game.java b/src/main/java/lotto/game/Game.java
similarity index 54%
rename from src/main/java/lotto/Game.java
rename to src/main/java/lotto/game/Game.java
index c455db7451..31053d547b 100644
--- a/src/main/java/lotto/Game.java
+++ b/src/main/java/lotto/game/Game.java
@@ -1,4 +1,4 @@
-package lotto;
+package lotto.game;
import java.util.ArrayList;
import java.util.List;
@@ -7,9 +7,8 @@ public interface Game {
List> getRandomNumbers(int amount);
- void calculateWinCounts(int[] place, int idx, List winCounts);
+ int[] getWinCounts(List> winCounts);
- int[] getWinCounts(List winCounts);
public void run();
}
diff --git a/src/main/java/lotto/game/GameImpl.java b/src/main/java/lotto/game/GameImpl.java
new file mode 100644
index 0000000000..eea2a47385
--- /dev/null
+++ b/src/main/java/lotto/game/GameImpl.java
@@ -0,0 +1,82 @@
+package lotto.game;
+
+import lotto.compare.Compare;
+import lotto.compare.CompareImpl;
+import lotto.input.Input;
+import lotto.print.Print;
+import lotto.randomNumber.RandomNumber;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class GameImpl implements Game {
+
+
+ private final RandomNumber randomNumber;
+ private final Input input;
+ private final Print print;
+ private Compare compare;
+
+
+ public GameImpl(RandomNumber randomNumber, Input input, Print print) {
+ this.randomNumber = randomNumber;
+ this.input = input;
+ this.print = print;
+ }
+
+ @Override
+ public List> getRandomNumbers(int amount) {
+ List> list = new ArrayList<>();
+ for (int i = 0; i < amount; i++) {
+ List randomNumbers = randomNumber.getRandomNumber();
+ list.add(randomNumbers);
+ }
+ return list;
+ }
+
+ @Override
+ public int[] getWinCounts(List> winCounts) {
+ int[] place = new int[5];
+ for (List winCount : winCounts) {
+ int count = winCount.get(0);
+ if (count == 6) {
+ place[0]++;
+ continue;
+ }
+ if (count == 5) {
+ if (winCount.get(1) == 1) {
+ place[1]++;
+ continue;
+ }
+ place[2]++;
+ continue;
+ }
+ if (count == 4) {
+ place[3]++;
+ continue;
+ }
+ if (count == 3) {
+ place[4]++;
+ }
+ }
+ return place;
+ }
+
+ @Override
+ public void run() {
+ List> winCounts = new ArrayList<>();
+ int price = input.getPurchasePrice();
+ int amount = price / 1000;
+ List> randomNumberList = getRandomNumbers(amount);
+ print.printAmountMessage(amount);
+ List winningNumber = input.getWiningNumber();
+ for (List randomNumber : randomNumberList) {
+ compare = new CompareImpl(winningNumber, randomNumber);
+ List winCountResult = compare.compare();
+ ;
+ winCounts.add(winCountResult);
+ }
+ int[] place = getWinCounts(winCounts);
+ print.printResult(place, price);
+ }
+}
diff --git a/src/main/java/lotto/Input.java b/src/main/java/lotto/input/Input.java
similarity index 59%
rename from src/main/java/lotto/Input.java
rename to src/main/java/lotto/input/Input.java
index 0448512e75..2b8b7efd75 100644
--- a/src/main/java/lotto/Input.java
+++ b/src/main/java/lotto/input/Input.java
@@ -1,13 +1,7 @@
-package lotto;
+package lotto.input;
-import camp.nextstep.edu.missionutils.Console;
-
-import java.util.ArrayList;
import java.util.List;
-import static lotto.Constant.*;
-import static lotto.Constant.MAX_BOUND;
-
public interface Input {
public int getPurchasePrice();
diff --git a/src/main/java/lotto/InputImpl.java b/src/main/java/lotto/input/InputImpl.java
similarity index 92%
rename from src/main/java/lotto/InputImpl.java
rename to src/main/java/lotto/input/InputImpl.java
index 32d6a34860..a6af99b457 100644
--- a/src/main/java/lotto/InputImpl.java
+++ b/src/main/java/lotto/input/InputImpl.java
@@ -1,11 +1,13 @@
-package lotto;
+package lotto.input;
import camp.nextstep.edu.missionutils.Console;
+import lotto.print.Print;
+import lotto.print.PrintImpl;
import java.util.ArrayList;
import java.util.List;
-import static lotto.Constant.*;
+import static lotto.constant.Constant.*;
public class InputImpl implements Input {
private final Print print;
@@ -62,7 +64,7 @@ public void validatePrice(String input) {
public void validateWinningNumber(List input) {
for (int i = 0; i < input.size(); i++) {
if (input.get(i) < MIN_BOUND || input.get(i) > MAX_BOUND) {
- System.out.println("[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다.");
+
throw new IllegalArgumentException("[ERROR]");
}
}
diff --git a/src/main/java/lotto/Print.java b/src/main/java/lotto/print/Print.java
similarity index 85%
rename from src/main/java/lotto/Print.java
rename to src/main/java/lotto/print/Print.java
index 128ef5eebd..64d70b57c8 100644
--- a/src/main/java/lotto/Print.java
+++ b/src/main/java/lotto/print/Print.java
@@ -1,7 +1,4 @@
-package lotto;
-
-import static lotto.Message.*;
-import static lotto.Message.INPUT_BONUS;
+package lotto.print;
public interface Print {
public int printSix(int value);
diff --git a/src/main/java/lotto/PrintImpl.java b/src/main/java/lotto/print/PrintImpl.java
similarity index 95%
rename from src/main/java/lotto/PrintImpl.java
rename to src/main/java/lotto/print/PrintImpl.java
index 4a9f1e6f23..9aa192626c 100644
--- a/src/main/java/lotto/PrintImpl.java
+++ b/src/main/java/lotto/print/PrintImpl.java
@@ -1,8 +1,8 @@
-package lotto;
+package lotto.print;
-import static lotto.Message.*;
+import static lotto.constant.Message.*;
-public class PrintImpl implements Print{
+public class PrintImpl implements Print {
private static PrintImpl print;
private PrintImpl() {
diff --git a/src/main/java/lotto/RandomNumber.java b/src/main/java/lotto/randomNumber/RandomNumber.java
similarity index 78%
rename from src/main/java/lotto/RandomNumber.java
rename to src/main/java/lotto/randomNumber/RandomNumber.java
index db1f4b360b..13f3ef16d3 100644
--- a/src/main/java/lotto/RandomNumber.java
+++ b/src/main/java/lotto/randomNumber/RandomNumber.java
@@ -1,4 +1,4 @@
-package lotto;
+package lotto.randomNumber;
import java.util.List;
diff --git a/src/main/java/lotto/RandomNumberImpl.java b/src/main/java/lotto/randomNumber/RandomNumberImpl.java
similarity index 91%
rename from src/main/java/lotto/RandomNumberImpl.java
rename to src/main/java/lotto/randomNumber/RandomNumberImpl.java
index 7c2b93cc99..42a35af9e8 100644
--- a/src/main/java/lotto/RandomNumberImpl.java
+++ b/src/main/java/lotto/randomNumber/RandomNumberImpl.java
@@ -1,10 +1,10 @@
-package lotto;
+package lotto.randomNumber;
import camp.nextstep.edu.missionutils.Randoms;
import java.util.*;
-import static lotto.Constant.*;
+import static lotto.constant.Constant.*;
public class RandomNumberImpl implements RandomNumber {
diff --git a/src/test/java/lotto/ApplicationTest.java b/src/test/java/lotto/ApplicationTest.java
index 4dcf5b19b8..cbdb40b69a 100644
--- a/src/test/java/lotto/ApplicationTest.java
+++ b/src/test/java/lotto/ApplicationTest.java
@@ -1,6 +1,7 @@
package lotto;
import camp.nextstep.edu.missionutils.test.NsTest;
+import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.List;
@@ -54,6 +55,7 @@ class ApplicationTest extends NsTest {
});
}
+
@Override
public void runMain() {
Application.main(new String[]{});
diff --git a/src/test/java/lotto/InputTest.java b/src/test/java/lotto/InputTest.java
new file mode 100644
index 0000000000..1e3ca3f488
--- /dev/null
+++ b/src/test/java/lotto/InputTest.java
@@ -0,0 +1,69 @@
+package lotto;
+
+import lotto.input.Input;
+import lotto.input.InputImpl;
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+import java.io.ByteArrayInputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+class InputTest {
+
+ @DisplayName("Input 클래스의 객체가 맞는지 확인")
+ @Test
+ void 객체_리턴_테스트() {
+ Assertions.assertThat(InputImpl.getInstance()).isInstanceOf(Input.class);
+ }
+
+ @Test
+ void 구입_가격_입력_테스트() {
+ //given
+ Input input = InputImpl.getInstance();
+ String inputNumber = "8000";
+
+ //when
+ System.setIn(new ByteArrayInputStream(inputNumber.getBytes()));
+ int result = input.getPurchasePrice();
+
+ //then
+ Assertions.assertThat(result).isEqualTo(Integer.parseInt(inputNumber));
+ }
+
+ @Test
+ @DisplayName("입력값에 숫자가 아닌 문자가 들어가면 예외 테스트")
+ void 구입_가격_입력_숫자_아닐때_테스트() {
+ //given
+ Input input = InputImpl.getInstance();
+ String inputNumber = "1000j";
+
+ //when
+ System.setIn(new ByteArrayInputStream(inputNumber.getBytes()));
+
+ //then
+ org.junit.jupiter.api.Assertions.assertThrows(IllegalArgumentException.class, () -> {
+ input.getPurchasePrice();
+ });
+
+ }
+
+ @Test
+ @DisplayName("입력값을 입력했을때, 출력값이 정상인지 테스트")
+ void 당첨_번호_입력_테스트() {
+ //given
+ Input input = InputImpl.getInstance();
+ String inputNumber = "1,2,3,4,5,6\n7";
+
+
+ //when
+ System.setIn(new ByteArrayInputStream(inputNumber.getBytes()));
+ List result = input.getWiningNumber();
+
+ //then
+ List expectedList = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6, 7));
+ Assertions.assertThat(result).isEqualTo(expectedList);
+ }
+}
\ No newline at end of file
From b2d7e6c5132ee87d608b3a685789b35c1b663646 Mon Sep 17 00:00:00 2001
From: kwonyonghyun
Date: Sat, 8 Jul 2023 00:18:01 +0900
Subject: [PATCH 15/19] =?UTF-8?q?=ED=99=95=EC=9D=B8=EC=9A=A9=20=EC=BB=A4?=
=?UTF-8?q?=EB=B0=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/constant/Constant.java | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/main/java/lotto/constant/Constant.java b/src/main/java/lotto/constant/Constant.java
index 2acfc2102d..dc8d7da197 100644
--- a/src/main/java/lotto/constant/Constant.java
+++ b/src/main/java/lotto/constant/Constant.java
@@ -6,4 +6,5 @@ public class Constant {
public final static int MAX_BOUND = 45;
public final static char MIN_BOUND_CHAR = '0';
public final static char MAX_BOUND_CHAR = '9';
+
}
From 59b166be0ed3311de7328046ab490f814e057b2d Mon Sep 17 00:00:00 2001
From: kwonyonghyun
Date: Sat, 8 Jul 2023 00:58:52 +0900
Subject: [PATCH 16/19] =?UTF-8?q?GameImpl=20=ED=81=B4=EB=9E=98=EC=8A=A4?=
=?UTF-8?q?=EC=9D=98=20getWinCounts=20=ED=95=A8=EC=88=98=20=EC=A0=9C?=
=?UTF-8?q?=EC=99=B8=ED=95=98=EA=B3=A0=EB=8A=94=20=EB=A6=AC=ED=8C=A9?=
=?UTF-8?q?=ED=86=A0=EB=A7=81=20=EC=99=84=EB=A3=8C=ED=96=88=EC=8A=B5?=
=?UTF-8?q?=EB=8B=88=EB=8B=A4.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/compare/CompareImpl.java | 4 +--
src/main/java/lotto/constant/Constant.java | 16 ++++++++++
src/main/java/lotto/constant/Message.java | 12 +++----
src/main/java/lotto/game/GameImpl.java | 28 +++++++++--------
src/main/java/lotto/print/Print.java | 10 +++---
src/main/java/lotto/print/PrintImpl.java | 33 +++++++++++---------
6 files changed, 62 insertions(+), 41 deletions(-)
diff --git a/src/main/java/lotto/compare/CompareImpl.java b/src/main/java/lotto/compare/CompareImpl.java
index 1565c53f11..592d1465a1 100644
--- a/src/main/java/lotto/compare/CompareImpl.java
+++ b/src/main/java/lotto/compare/CompareImpl.java
@@ -38,8 +38,8 @@ public List compare() {
@Override
public int[] winCount(List list) {
int[] result = new int[2];
- result[0] = Collections.frequency(list, 1);
- result[1] = Collections.frequency(list, 2);
+ result[MATCH_COUNT_IDX] = Collections.frequency(list, MATCH_NUMBER);
+ result[BONUS_MATCH_COUNT_IDX] = Collections.frequency(list, BONUS_MATCH_NUMBER);
return result;
}
}
diff --git a/src/main/java/lotto/constant/Constant.java b/src/main/java/lotto/constant/Constant.java
index dc8d7da197..faaf65cf6f 100644
--- a/src/main/java/lotto/constant/Constant.java
+++ b/src/main/java/lotto/constant/Constant.java
@@ -6,5 +6,21 @@ public class Constant {
public final static int MAX_BOUND = 45;
public final static char MIN_BOUND_CHAR = '0';
public final static char MAX_BOUND_CHAR = '9';
+ public final static int FIRST_PLACE_COUNT = 6;
+ public final static int SECOND_PLACE_COUNT = 5;
+ public final static int FOURTH_PLACE_COUNT = 4;
+ public final static int FIFTH_PLACE_COUNT = 3;
+ public final static int BONUS_COUNT = 1;
+ public final static int FIRST_PLACE_IDX = 0;
+ public final static int SECOND_PLACE_IDX = 1;
+ public final static int THIRD_PLACE_IDX = 2;
+ public final static int FOURTH_PLACE_IDX = 3;
+ public final static int FIFTH_PLACE_IDX = 4;
+ public final static int TOTAL_PLACES = 5;
+ public final static int MATCH_COUNT_IDX = 0;
+ public final static int BONUS_MATCH_COUNT_IDX = 1;
+
+ public final static int MATCH_NUMBER = 1;
+ public final static int BONUS_MATCH_NUMBER = 2;
}
diff --git a/src/main/java/lotto/constant/Message.java b/src/main/java/lotto/constant/Message.java
index 16569fd505..654cbb8d6d 100644
--- a/src/main/java/lotto/constant/Message.java
+++ b/src/main/java/lotto/constant/Message.java
@@ -8,11 +8,11 @@ public enum Message {
INPUT_NUMBER("당첨 번호를 입력해 주세요"),
INPUT_BONUS("보너스 번호를 입력해 주세요"),
WINNING_RESULT("당첨 통계\n___"),
- EQUAL_THREE("3개 일치 (5,000원) - "),
- EQUAL_FOUR("4개 일치 (50,000원) - "),
- EQUAL_FIVE("5개 일치 (1,500,000원) - "),
- EQUAL_FIVE_BONUS("5개 일치, 보너스 볼 일치 (30,000,000원) - "),
- EQUAL_SIX("6개 일치 (2,000,000,000원) - "),
+ MATCH_THREE("3개 일치 (5,000원) - "),
+ MATCH_FOUR("4개 일치 (50,000원) - "),
+ MATCH_FIVE("5개 일치 (1,500,000원) - "),
+ MATCH_FIVE_BONUS("5개 일치, 보너스 볼 일치 (30,000,000원) - "),
+ MATCH_SIX("6개 일치 (2,000,000,000원) - "),
PROFIT_RESULT("총 수익률은 ");
private final String value;
@@ -25,7 +25,7 @@ public String getValue() {
return value;
}
- public String getEqualValue(int x) {
+ public String getMATCHValue(int x) {
return value + x + "개";
}
diff --git a/src/main/java/lotto/game/GameImpl.java b/src/main/java/lotto/game/GameImpl.java
index eea2a47385..d0fbbceb2e 100644
--- a/src/main/java/lotto/game/GameImpl.java
+++ b/src/main/java/lotto/game/GameImpl.java
@@ -2,6 +2,7 @@
import lotto.compare.Compare;
import lotto.compare.CompareImpl;
+import lotto.constant.Constant;
import lotto.input.Input;
import lotto.print.Print;
import lotto.randomNumber.RandomNumber;
@@ -9,6 +10,8 @@
import java.util.ArrayList;
import java.util.List;
+import static lotto.constant.Constant.*;
+
public class GameImpl implements Game {
@@ -36,27 +39,27 @@ public List> getRandomNumbers(int amount) {
@Override
public int[] getWinCounts(List> winCounts) {
- int[] place = new int[5];
+ int[] place = new int[TOTAL_PLACES];
for (List winCount : winCounts) {
- int count = winCount.get(0);
- if (count == 6) {
- place[0]++;
+ int count = winCount.get(MATCH_COUNT_IDX);//보너스 숫자 제외 맞춘 숫자 갯수
+ if (count == FIRST_PLACE_COUNT) {
+ place[FIRST_PLACE_IDX]++;
continue;
}
- if (count == 5) {
- if (winCount.get(1) == 1) {
- place[1]++;
+ if (count == SECOND_PLACE_COUNT) {
+ if (winCount.get(BONUS_MATCH_COUNT_IDX) == BONUS_COUNT) {//보너스 숫자 맞춘 갯수
+ place[SECOND_PLACE_IDX]++;
continue;
}
- place[2]++;
+ place[THIRD_PLACE_IDX]++;
continue;
}
- if (count == 4) {
- place[3]++;
+ if (count == FOURTH_PLACE_COUNT) {
+ place[FOURTH_PLACE_IDX]++;
continue;
}
- if (count == 3) {
- place[4]++;
+ if (count == FIFTH_PLACE_COUNT) {
+ place[FIFTH_PLACE_IDX]++;
}
}
return place;
@@ -73,7 +76,6 @@ public void run() {
for (List randomNumber : randomNumberList) {
compare = new CompareImpl(winningNumber, randomNumber);
List winCountResult = compare.compare();
- ;
winCounts.add(winCountResult);
}
int[] place = getWinCounts(winCounts);
diff --git a/src/main/java/lotto/print/Print.java b/src/main/java/lotto/print/Print.java
index 64d70b57c8..b7b4b2c9e0 100644
--- a/src/main/java/lotto/print/Print.java
+++ b/src/main/java/lotto/print/Print.java
@@ -1,15 +1,15 @@
package lotto.print;
public interface Print {
- public int printSix(int value);
+ public int printSixMatch(int value);
- public int printFive(int value);
+ public int printFiveMatch(int value);
- public int printFiveBonus(int value);
+ public int printFiveBonusMatch(int value);
- public int printFour(int value);
+ public int printFourMatch(int value);
- public int printThree(int value);
+ public int printThreeMatch(int value);
public void printProfitResultMessage(int result, int price);
diff --git a/src/main/java/lotto/print/PrintImpl.java b/src/main/java/lotto/print/PrintImpl.java
index 9aa192626c..f0b005337f 100644
--- a/src/main/java/lotto/print/PrintImpl.java
+++ b/src/main/java/lotto/print/PrintImpl.java
@@ -1,5 +1,8 @@
package lotto.print;
+import lotto.constant.Constant;
+
+import static lotto.constant.Constant.*;
import static lotto.constant.Message.*;
public class PrintImpl implements Print {
@@ -17,32 +20,32 @@ public static PrintImpl getInstance() {
}
@Override
- public int printSix(int value) {
- System.out.println(EQUAL_SIX.getEqualValue(value));
+ public int printSixMatch(int value) {
+ System.out.println(MATCH_SIX.getMATCHValue(value));
return 2000000000 * value;
}
@Override
- public int printFive(int value) {
- System.out.println(EQUAL_FIVE.getEqualValue(value));
+ public int printFiveMatch(int value) {
+ System.out.println(MATCH_FIVE.getMATCHValue(value));
return 1500000 * value;
}
@Override
- public int printFiveBonus(int value) {
- System.out.println(EQUAL_FIVE_BONUS.getEqualValue(value));
+ public int printFiveBonusMatch(int value) {
+ System.out.println(MATCH_FIVE_BONUS.getMATCHValue(value));
return 30000000 * value;
}
@Override
- public int printFour(int value) {
- System.out.println(EQUAL_FOUR.getEqualValue(value));
+ public int printFourMatch(int value) {
+ System.out.println(MATCH_FOUR.getMATCHValue(value));
return 50000 * value;
}
@Override
- public int printThree(int value) {
- System.out.println(EQUAL_THREE.getEqualValue(value));
+ public int printThreeMatch(int value) {
+ System.out.println(MATCH_THREE.getMATCHValue(value));
return 5000 * value;
}
@@ -74,11 +77,11 @@ public void printBonusNumberMessage() {
@Override
public void printResult(int[] place, int price) {
int result = 0;
- result += printThree(place[4]);
- result += printFour(place[3]);
- result += printFive(place[2]);
- result += printFiveBonus(place[1]);
- result += printSix(place[0]);
+ result += printThreeMatch(place[FIFTH_PLACE_IDX]);
+ result += printFourMatch(place[FOURTH_PLACE_IDX]);
+ result += printFiveMatch(place[THIRD_PLACE_IDX]);
+ result += printFiveBonusMatch(place[SECOND_PLACE_IDX]);
+ result += printSixMatch(place[FIRST_PLACE_IDX]);
printProfitResultMessage(result, price);
}
From 1e9694ca0676d13f21bc8d88121b5abc2e907e03 Mon Sep 17 00:00:00 2001
From: kwonyonghyun
Date: Wed, 12 Jul 2023 16:42:01 +0900
Subject: [PATCH 17/19] =?UTF-8?q?LottoConfig=20=EC=B6=94=EA=B0=80,=20?=
=?UTF-8?q?=EC=8B=B1=EA=B8=80=ED=86=A4=20lazy=20holder=20=EB=B0=A9?=
=?UTF-8?q?=EC=8B=9D=EC=9C=BC=EB=A1=9C=20=EB=A6=AC=ED=8C=A9=ED=86=A0?=
=?UTF-8?q?=EB=A7=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/Application.java | 9 +++---
src/main/java/lotto/config/LottoConfig.java | 31 +++++++++++++++++++
src/main/java/lotto/game/Game.java | 4 ---
src/main/java/lotto/game/GameImpl.java | 8 ++---
src/main/java/lotto/input/Input.java | 2 --
src/main/java/lotto/input/InputImpl.java | 20 ++++++------
src/main/java/lotto/print/PrintImpl.java | 12 ++++---
.../lotto/randomNumber/RandomNumberImpl.java | 12 ++++---
8 files changed, 64 insertions(+), 34 deletions(-)
create mode 100644 src/main/java/lotto/config/LottoConfig.java
diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java
index 07a80d221b..9dcb8569ec 100644
--- a/src/main/java/lotto/Application.java
+++ b/src/main/java/lotto/Application.java
@@ -1,16 +1,15 @@
package lotto;
+import lotto.config.LottoConfig;
import lotto.game.Game;
-import lotto.game.GameImpl;
-import lotto.input.InputImpl;
-import lotto.print.PrintImpl;
-import lotto.randomNumber.RandomNumberImpl;
public class Application {
+
public static void main(String[] args) {
// TODO: 프로그램 구현
- Game game = new GameImpl(RandomNumberImpl.getInstance(), InputImpl.getInstance(), PrintImpl.getInstance());
+ LottoConfig lottoConfig=new LottoConfig();
+ Game game = lottoConfig.getGame();
try {
game.run();
} catch (Exception e) {
diff --git a/src/main/java/lotto/config/LottoConfig.java b/src/main/java/lotto/config/LottoConfig.java
new file mode 100644
index 0000000000..d09e71317d
--- /dev/null
+++ b/src/main/java/lotto/config/LottoConfig.java
@@ -0,0 +1,31 @@
+package lotto.config;
+
+
+import lotto.game.Game;
+import lotto.game.GameImpl;
+import lotto.input.Input;
+import lotto.input.InputImpl;
+import lotto.print.Print;
+import lotto.print.PrintImpl;
+import lotto.randomNumber.RandomNumber;
+import lotto.randomNumber.RandomNumberImpl;
+
+public class LottoConfig {
+
+ public RandomNumber getRandomNumber() {
+ return RandomNumberImpl.getInstance();
+ }
+
+ public Input getInput() {
+ return InputImpl.getInstance();
+ }
+
+ public Print getPrint() {
+ return PrintImpl.getInstance();
+ }
+
+
+ public Game getGame() {
+ return new GameImpl(getRandomNumber(), getInput(), getPrint());
+ }
+}
diff --git a/src/main/java/lotto/game/Game.java b/src/main/java/lotto/game/Game.java
index 31053d547b..572143d5a1 100644
--- a/src/main/java/lotto/game/Game.java
+++ b/src/main/java/lotto/game/Game.java
@@ -5,10 +5,6 @@
public interface Game {
- List> getRandomNumbers(int amount);
-
- int[] getWinCounts(List> winCounts);
-
public void run();
}
diff --git a/src/main/java/lotto/game/GameImpl.java b/src/main/java/lotto/game/GameImpl.java
index d0fbbceb2e..afcb6874a1 100644
--- a/src/main/java/lotto/game/GameImpl.java
+++ b/src/main/java/lotto/game/GameImpl.java
@@ -27,8 +27,8 @@ public GameImpl(RandomNumber randomNumber, Input input, Print print) {
this.print = print;
}
- @Override
- public List> getRandomNumbers(int amount) {
+
+ private List> getRandomNumbers(int amount) {
List> list = new ArrayList<>();
for (int i = 0; i < amount; i++) {
List randomNumbers = randomNumber.getRandomNumber();
@@ -37,8 +37,8 @@ public List> getRandomNumbers(int amount) {
return list;
}
- @Override
- public int[] getWinCounts(List> winCounts) {
+
+ private int[] getWinCounts(List> winCounts) {
int[] place = new int[TOTAL_PLACES];
for (List winCount : winCounts) {
int count = winCount.get(MATCH_COUNT_IDX);//보너스 숫자 제외 맞춘 숫자 갯수
diff --git a/src/main/java/lotto/input/Input.java b/src/main/java/lotto/input/Input.java
index 2b8b7efd75..737d4cf3b6 100644
--- a/src/main/java/lotto/input/Input.java
+++ b/src/main/java/lotto/input/Input.java
@@ -8,7 +8,5 @@ public interface Input {
public List getWiningNumber();
- public void validatePrice(String input);
- public void validateWinningNumber(List input);
}
diff --git a/src/main/java/lotto/input/InputImpl.java b/src/main/java/lotto/input/InputImpl.java
index a6af99b457..8b3d2c963f 100644
--- a/src/main/java/lotto/input/InputImpl.java
+++ b/src/main/java/lotto/input/InputImpl.java
@@ -17,11 +17,13 @@ private InputImpl() {
print = PrintImpl.getInstance();
}
- public static InputImpl getInstance() {
- if (input == null) {
- input = new InputImpl();
- }
- return input;
+ private static class InstanceHolder {
+ private static Input INSTANCE = new InputImpl();
+ }
+
+
+ public static Input getInstance() {
+ return InstanceHolder.INSTANCE;
}
@Override
@@ -51,8 +53,8 @@ public List getWiningNumber() {
return result;
}
- @Override
- public void validatePrice(String input) {
+
+ private void validatePrice(String input) {
for (int i = 0; i < input.length(); i++) {
if (input.charAt(i) < MIN_BOUND_CHAR || input.charAt(i) > MAX_BOUND_CHAR) {
throw new IllegalArgumentException("[ERROR]");
@@ -60,8 +62,8 @@ public void validatePrice(String input) {
}
}
- @Override
- public void validateWinningNumber(List input) {
+
+ private void validateWinningNumber(List input) {
for (int i = 0; i < input.size(); i++) {
if (input.get(i) < MIN_BOUND || input.get(i) > MAX_BOUND) {
diff --git a/src/main/java/lotto/print/PrintImpl.java b/src/main/java/lotto/print/PrintImpl.java
index f0b005337f..909e1b2d29 100644
--- a/src/main/java/lotto/print/PrintImpl.java
+++ b/src/main/java/lotto/print/PrintImpl.java
@@ -11,12 +11,14 @@ public class PrintImpl implements Print {
private PrintImpl() {
}
+ private static class InstanceHolder {
+ private static Print INSTANCE = new PrintImpl();
+ }
+
+
+ public static Print getInstance() {
- public static PrintImpl getInstance() {
- if (print == null) {
- print = new PrintImpl();
- }
- return print;
+ return InstanceHolder.INSTANCE;
}
@Override
diff --git a/src/main/java/lotto/randomNumber/RandomNumberImpl.java b/src/main/java/lotto/randomNumber/RandomNumberImpl.java
index 42a35af9e8..9a8dece27c 100644
--- a/src/main/java/lotto/randomNumber/RandomNumberImpl.java
+++ b/src/main/java/lotto/randomNumber/RandomNumberImpl.java
@@ -13,11 +13,13 @@ public class RandomNumberImpl implements RandomNumber {
private RandomNumberImpl() {
}
- public static RandomNumberImpl getInstance() {
- if (randomNumber == null) {
- randomNumber = new RandomNumberImpl();
- }
- return randomNumber;
+ private static class InstanceHolder {
+ private static RandomNumber INSTANCE = new RandomNumberImpl();
+ }
+
+
+ public static RandomNumber getInstance() {
+ return InstanceHolder.INSTANCE;
}
@Override
From 462402a86942a2975cb08fc452fc1e3a2c34147f Mon Sep 17 00:00:00 2001
From: kwonyonghyun
Date: Wed, 12 Jul 2023 18:02:17 +0900
Subject: [PATCH 18/19] =?UTF-8?q?=EC=82=AC=EC=86=8C=ED=95=9C=20=EC=8A=A4?=
=?UTF-8?q?=ED=8E=A0=EB=A7=81=20=EB=B3=80=ED=99=94?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main/java/lotto/config/LottoConfig.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/main/java/lotto/config/LottoConfig.java b/src/main/java/lotto/config/LottoConfig.java
index d09e71317d..4c973b2794 100644
--- a/src/main/java/lotto/config/LottoConfig.java
+++ b/src/main/java/lotto/config/LottoConfig.java
@@ -12,20 +12,20 @@
public class LottoConfig {
- public RandomNumber getRandomNumber() {
+ public RandomNumber randomNumber() {
return RandomNumberImpl.getInstance();
}
- public Input getInput() {
+ public Input input() {
return InputImpl.getInstance();
}
- public Print getPrint() {
+ public Print print() {
return PrintImpl.getInstance();
}
public Game getGame() {
- return new GameImpl(getRandomNumber(), getInput(), getPrint());
+ return new GameImpl(randomNumber(), input(), print());
}
}
From 87d8289f5bbc275e23276973f7062f98f64c0897 Mon Sep 17 00:00:00 2001
From: kwonyonghyun
Date: Fri, 14 Jul 2023 14:05:17 +0900
Subject: [PATCH 19/19] .
---
src/main/java/lotto/Application.java | 2 +-
src/main/java/lotto/config/LottoConfig.java | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java
index 9dcb8569ec..ffc62b20aa 100644
--- a/src/main/java/lotto/Application.java
+++ b/src/main/java/lotto/Application.java
@@ -9,7 +9,7 @@ public class Application {
public static void main(String[] args) {
// TODO: 프로그램 구현
LottoConfig lottoConfig=new LottoConfig();
- Game game = lottoConfig.getGame();
+ Game game = lottoConfig.game();
try {
game.run();
} catch (Exception e) {
diff --git a/src/main/java/lotto/config/LottoConfig.java b/src/main/java/lotto/config/LottoConfig.java
index 4c973b2794..3688232f7b 100644
--- a/src/main/java/lotto/config/LottoConfig.java
+++ b/src/main/java/lotto/config/LottoConfig.java
@@ -25,7 +25,7 @@ public Print print() {
}
- public Game getGame() {
+ public Game game() {
return new GameImpl(randomNumber(), input(), print());
}
}