From 398d8d60b8b9beacd2ef3028583a55da48841ba5 Mon Sep 17 00:00:00 2001 From: enohs Date: Mon, 30 Sep 2024 01:16:02 +0900 Subject: [PATCH 01/11] =?UTF-8?q?=EB=AF=B8=EC=99=84=EC=84=B1......?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 25 +++++++++++++ src/main/java/lotto/Application.java | 54 ++++++++++++++++++++++++++-- 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index e69de29b..96baa518 100644 --- a/docs/README.md +++ b/docs/README.md @@ -0,0 +1,25 @@ +## 구현 기능 목록 ## + +- [x] 한 장당 1000원을 로또 구입 가격을 입력 받음 + - > 로또 번호 범위는 1 ~ 45 + - > 한 장당 겹치지 않는 6개의 숫자 할당 + - > 1000원으로 나눠지지 않는 값을 입력하면 IllegalArgumentException을 발생시키고 "[Error]"로 시작하는 메시지 출력 후 종료 + - > 로또 번호는 오름차순으로 정렬하여 출력 + + +- [x] 당첨 번호를 입력받음 + - > 1부터 6까지 콤마로 나눠 입력 받음 + - > 보너스 번호를 입력받음 + +- [x] 일치하는 로또 번호와 당첨 금액을 정의하는 enum 클래스 생성 +- [x] 사용자가 구매한 로또 번호와 당첨번호를 비교해 당첨 내역을 확인할 수 있다. + - > 일치하는 번호의 개수를 확인할 수 있다. + - > 일치하는 번호의 수만큼 수익이 측정된다. + - > 3개 번호가 일치하면 5,000원이며, 5등이다. + - > 4개 번호가 일치하면 50,000원이며, 4등이다. + - > 5개 번호가 일치하면 1,500,500원이며, 3등이다. + - > 5개 번호가 일치하고 보너스 번호가 일치하면 30,000,000원 2등이다. + - > 6개 번호가 일치하면 2,000,000,000원이다. + +- [x] 사용자가 구입한 로또 금액과 당첨 금액으로 수익률을 확인할 수 있다. + - > 수익률은 소수점 둘재 자리에서 반올림한다. diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java index d190922b..fc95f4cd 100644 --- a/src/main/java/lotto/Application.java +++ b/src/main/java/lotto/Application.java @@ -1,7 +1,57 @@ package lotto; +import camp.nextstep.edu.missionutils.Randoms; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Scanner; +import java.util.Set; +import org.mockito.internal.stubbing.defaultanswers.ReturnsSmartNulls; + public class Application { + static Scanner scanner = new Scanner(System.in); + + public static void main(String[] args) { - // TODO: 프로그램 구현 - } + System.out.println("구입 금액을 입력해 주세요."); + int buyCost = scanner.nextInt(); + + try { + if (buyCost % 1000 != 0) { + throw new IllegalArgumentException("[Error] 잔돈이 남았습니다. 잔돈은 드리지 않으니 다시 시작 후 정확히 입력하십시오."); + } + System.out.println("\n"+(buyCost / 1000) + "개를 구매했습니다."); + } catch (IllegalAccessError e) { + System.out.println(e.getMessage()); + return; + } + + for (int i=0; i < (buyCost / 1000); i++){ + List selectedLottoList = Randoms.pickUniqueNumbersInRange(1,45,6); + Collections.sort(selectedLottoList); + System.out.println(selectedLottoList); + } + + System.out.println("\n당첨 번호를 입력해 주세요."); + scanner.nextLine(); + String inputWinningNum = scanner.nextLine(); + List inputWinningNumList= List.of(inputWinningNum.split(",")); + System.out.println(inputWinningNumList); + +// for (int i = 0; i < inputWinningNumList.size(); i++){ +// List winningLottoList = Randoms.pickUniqueNumbersInRange(1,45,6); +// if (inputWinningNumList.get(i).equals("1")){ +// +// } else if (inputWinningNumList.get(i).equals("2")) { +// +// }else if (inputWinningNumList.get(i).equals("3")) { +// +// }else if (inputWinningNumList.get(i).equals("4")) { +// +// }else if (inputWinningNumList.get(i).equals("5")) { +// +// }else if (inputWinningNumList.get(i).equals("6")) { +// +// }} + } } From c9c60ebc3b2df0ce81d0f9e93055212053fc0f64 Mon Sep 17 00:00:00 2001 From: enohs Date: Sat, 5 Oct 2024 16:04:46 +0900 Subject: [PATCH 02/11] =?UTF-8?q?=EC=97=90=EB=9F=AC=EC=B2=B4=ED=81=AC=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EC=9E=85=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EB=B6=84=ED=95=A0=20=EB=A1=9C=EB=98=90=20=EB=A6=AC=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=A0=9C=EC=9E=91=20=EA=B8=B0=EB=8A=A5=20=EB=B6=84?= =?UTF-8?q?=ED=95=A0=20=EC=B6=9C=EB=A0=A5=20=EA=B8=B0=EB=8A=A5=20=EB=B6=84?= =?UTF-8?q?=ED=95=A0=20=EC=A4=91=EC=95=99=20=EC=A7=91=ED=95=A9=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=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 --- docs/README.md | 30 +++++--------- src/main/java/lotto/Application.java | 53 +------------------------ src/main/java/lotto/CheckError.java | 28 +++++++++++++ src/main/java/lotto/InputNums.java | 27 +++++++++++++ src/main/java/lotto/MakeLottoLists.java | 39 ++++++++++++++++++ src/main/java/lotto/PrintStrings.java | 13 ++++++ src/main/java/lotto/StartLotto.java | 15 +++++++ 7 files changed, 134 insertions(+), 71 deletions(-) create mode 100644 src/main/java/lotto/CheckError.java create mode 100644 src/main/java/lotto/InputNums.java create mode 100644 src/main/java/lotto/MakeLottoLists.java create mode 100644 src/main/java/lotto/PrintStrings.java create mode 100644 src/main/java/lotto/StartLotto.java diff --git a/docs/README.md b/docs/README.md index 96baa518..27186aaf 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,25 +1,15 @@ ## 구현 기능 목록 ## -- [x] 한 장당 1000원을 로또 구입 가격을 입력 받음 - - > 로또 번호 범위는 1 ~ 45 - - > 한 장당 겹치지 않는 6개의 숫자 할당 - - > 1000원으로 나눠지지 않는 값을 입력하면 IllegalArgumentException을 발생시키고 "[Error]"로 시작하는 메시지 출력 후 종료 - - > 로또 번호는 오름차순으로 정렬하여 출력 +# View + - 로또 가격 입력 + - 로또 개수 출력 + - 로또 개수만큼 리스트 출력 + - 당첨 번호 입력 + - 보너스 번호 입력 + - 당첨 통계 출력 +# Controller + - -- [x] 당첨 번호를 입력받음 - - > 1부터 6까지 콤마로 나눠 입력 받음 - - > 보너스 번호를 입력받음 +# Model -- [x] 일치하는 로또 번호와 당첨 금액을 정의하는 enum 클래스 생성 -- [x] 사용자가 구매한 로또 번호와 당첨번호를 비교해 당첨 내역을 확인할 수 있다. - - > 일치하는 번호의 개수를 확인할 수 있다. - - > 일치하는 번호의 수만큼 수익이 측정된다. - - > 3개 번호가 일치하면 5,000원이며, 5등이다. - - > 4개 번호가 일치하면 50,000원이며, 4등이다. - - > 5개 번호가 일치하면 1,500,500원이며, 3등이다. - - > 5개 번호가 일치하고 보너스 번호가 일치하면 30,000,000원 2등이다. - - > 6개 번호가 일치하면 2,000,000,000원이다. - -- [x] 사용자가 구입한 로또 금액과 당첨 금액으로 수익률을 확인할 수 있다. - - > 수익률은 소수점 둘재 자리에서 반올림한다. diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java index fc95f4cd..55c28662 100644 --- a/src/main/java/lotto/Application.java +++ b/src/main/java/lotto/Application.java @@ -1,57 +1,8 @@ package lotto; -import camp.nextstep.edu.missionutils.Randoms; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Scanner; -import java.util.Set; -import org.mockito.internal.stubbing.defaultanswers.ReturnsSmartNulls; - public class Application { - static Scanner scanner = new Scanner(System.in); - public static void main(String[] args) { - System.out.println("구입 금액을 입력해 주세요."); - int buyCost = scanner.nextInt(); - - try { - if (buyCost % 1000 != 0) { - throw new IllegalArgumentException("[Error] 잔돈이 남았습니다. 잔돈은 드리지 않으니 다시 시작 후 정확히 입력하십시오."); - } - System.out.println("\n"+(buyCost / 1000) + "개를 구매했습니다."); - } catch (IllegalAccessError e) { - System.out.println(e.getMessage()); - return; - } - - for (int i=0; i < (buyCost / 1000); i++){ - List selectedLottoList = Randoms.pickUniqueNumbersInRange(1,45,6); - Collections.sort(selectedLottoList); - System.out.println(selectedLottoList); - } - - System.out.println("\n당첨 번호를 입력해 주세요."); - scanner.nextLine(); - String inputWinningNum = scanner.nextLine(); - List inputWinningNumList= List.of(inputWinningNum.split(",")); - System.out.println(inputWinningNumList); - -// for (int i = 0; i < inputWinningNumList.size(); i++){ -// List winningLottoList = Randoms.pickUniqueNumbersInRange(1,45,6); -// if (inputWinningNumList.get(i).equals("1")){ -// -// } else if (inputWinningNumList.get(i).equals("2")) { -// -// }else if (inputWinningNumList.get(i).equals("3")) { -// -// }else if (inputWinningNumList.get(i).equals("4")) { -// -// }else if (inputWinningNumList.get(i).equals("5")) { -// -// }else if (inputWinningNumList.get(i).equals("6")) { -// -// }} - } + new StartLotto(); + } } diff --git a/src/main/java/lotto/CheckError.java b/src/main/java/lotto/CheckError.java new file mode 100644 index 00000000..739df4a3 --- /dev/null +++ b/src/main/java/lotto/CheckError.java @@ -0,0 +1,28 @@ +package lotto; + +public class CheckError { + public static void dividedThousand(int price){ + if (price % 1000 != 0){ + System.out.println("[Error] 남은 동전이 없어 잔돈을 드리지 못 합니다. 다시 입력해 주세요."); + throw new IllegalArgumentException(); + }} + + public static int isNum(String num){ + try { + int intNum = Integer.parseInt(num); + return intNum; + }catch (IllegalArgumentException e){ + System.out.println("숫자를 입력해 주세요~"); + throw new IllegalArgumentException(); + } + } + + public static void isNumRange(int num){ + if (num < 1 || num > 45){ + System.out.println("[Error] 1부터 45까지의 숫자만 입력해 주세요."); + throw new IllegalArgumentException(); + } + } + + +} diff --git a/src/main/java/lotto/InputNums.java b/src/main/java/lotto/InputNums.java new file mode 100644 index 00000000..a4cece34 --- /dev/null +++ b/src/main/java/lotto/InputNums.java @@ -0,0 +1,27 @@ +package lotto; + +import java.util.Scanner; + +public class InputNums { + static Scanner scanner = new Scanner(System.in); + + public static int price(){ + System.out.println("구입금액을 입력해 주세요."); + String lottoPrice = scanner.nextLine(); + int intPrice = CheckError.isNum(lottoPrice); + return intPrice; + } + + public static String winningNums() { + System.out.println("\n당첨 번호를 입력해 주세요."); + String winningNums = scanner.nextLine(); + return winningNums; + } + + public static int bonusNum(){ + System.out.println("\n보너스 번호를 입력해 주세요."); + int bonusNum = scanner.nextInt(); + CheckError.isNumRange(bonusNum); + return bonusNum; + } +} diff --git a/src/main/java/lotto/MakeLottoLists.java b/src/main/java/lotto/MakeLottoLists.java new file mode 100644 index 00000000..07de1ffc --- /dev/null +++ b/src/main/java/lotto/MakeLottoLists.java @@ -0,0 +1,39 @@ +package lotto; + +import camp.nextstep.edu.missionutils.Randoms; +import java.util.ArrayList; +import java.util.List; + +public class MakeLottoLists { + private List> saveLottos; + private List> winLottos; + private static final int DEFAULT_LOTTO_COUNT = 6; + + public MakeLottoLists() { + this.saveLottos = new ArrayList<>(); + this.winLottos = new ArrayList<>(); + } + + public List> makeInputLottoList(int price) { + int LOTTO_COUNT = price / 1000; + + CheckError.dividedThousand(price); // 가격 유효성 검사 + + for (int i = 0; i < LOTTO_COUNT; i++) { + List numbers = Randoms.pickUniqueNumbersInRange(1, 45, 6); + saveLottos.add(numbers); + } + + PrintStrings.printLottos(saveLottos, LOTTO_COUNT); + return saveLottos; // 반환 타입에 제네릭 추가 + } + + public List> makeWinLottoList() { + for (int i = 0; i < DEFAULT_LOTTO_COUNT; i++) { + List numbers = Randoms.pickUniqueNumbersInRange(1, 45, 6); + winLottos.add(numbers); + } + + return winLottos; // 반환 타입에 제네릭 추가 + } +} diff --git a/src/main/java/lotto/PrintStrings.java b/src/main/java/lotto/PrintStrings.java new file mode 100644 index 00000000..8d8e4537 --- /dev/null +++ b/src/main/java/lotto/PrintStrings.java @@ -0,0 +1,13 @@ +package lotto; + +import java.util.List; + +public class PrintStrings { + + public static void printLottos (List> saveLottos, int count){ + System.out.println("\n" + count + "개를 입력했습니다."); + for (int i =0; i < saveLottos.size(); i++){ + System.out.println(saveLottos.get(i)); + } + } +} diff --git a/src/main/java/lotto/StartLotto.java b/src/main/java/lotto/StartLotto.java new file mode 100644 index 00000000..a59dd47f --- /dev/null +++ b/src/main/java/lotto/StartLotto.java @@ -0,0 +1,15 @@ +package lotto; + +import java.util.List; + +public class StartLotto { + public StartLotto() { + int inputPrice = InputNums.price(); + MakeLottoLists makeLottoLists = new MakeLottoLists(); + makeLottoLists.makeInputLottoList(inputPrice); + List> list = makeLottoLists.makeWinLottoList(); + + InputNums.winningNums(); + InputNums.bonusNum(); + } +} From 2fe9f9be295986764cf7c567d4934ba4e38e09fa Mon Sep 17 00:00:00 2001 From: enohs Date: Sat, 5 Oct 2024 16:27:52 +0900 Subject: [PATCH 03/11] =?UTF-8?q?=EC=9D=BC=EB=B6=80=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/MakeLottoLists.java | 6 +++--- src/main/java/lotto/PrintStrings.java | 13 +++++++++++++ src/main/java/lotto/StartLotto.java | 3 +++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/lotto/MakeLottoLists.java b/src/main/java/lotto/MakeLottoLists.java index 07de1ffc..acecf974 100644 --- a/src/main/java/lotto/MakeLottoLists.java +++ b/src/main/java/lotto/MakeLottoLists.java @@ -17,7 +17,7 @@ public MakeLottoLists() { public List> makeInputLottoList(int price) { int LOTTO_COUNT = price / 1000; - CheckError.dividedThousand(price); // 가격 유효성 검사 + CheckError.dividedThousand(price); for (int i = 0; i < LOTTO_COUNT; i++) { List numbers = Randoms.pickUniqueNumbersInRange(1, 45, 6); @@ -25,7 +25,7 @@ public List> makeInputLottoList(int price) { } PrintStrings.printLottos(saveLottos, LOTTO_COUNT); - return saveLottos; // 반환 타입에 제네릭 추가 + return saveLottos; } public List> makeWinLottoList() { @@ -34,6 +34,6 @@ public List> makeWinLottoList() { winLottos.add(numbers); } - return winLottos; // 반환 타입에 제네릭 추가 + return winLottos; } } diff --git a/src/main/java/lotto/PrintStrings.java b/src/main/java/lotto/PrintStrings.java index 8d8e4537..ba726462 100644 --- a/src/main/java/lotto/PrintStrings.java +++ b/src/main/java/lotto/PrintStrings.java @@ -10,4 +10,17 @@ public static void printLottos (List> saveLottos, int count){ System.out.println(saveLottos.get(i)); } } + + public static void lottoResult(){ + System.out.println("\n당첨 통계"); + System.out.println("---------"); + + System.out.println("3개 일치 (5,000원)- 0개"); + System.out.println("4개 일치 (50,000원)- 0개"); + System.out.println("5개 일치 (1,500,000원)- 0개"); + System.out.println("5개 일치, 보너스 볼 일치 (30,000,000원)- 0개"); + System.out.println("6개 일치 (2,000,000,000원)- 0개"); + + System.out.println("총 수익률은 0%입니다."); + } } diff --git a/src/main/java/lotto/StartLotto.java b/src/main/java/lotto/StartLotto.java index a59dd47f..7468d5d9 100644 --- a/src/main/java/lotto/StartLotto.java +++ b/src/main/java/lotto/StartLotto.java @@ -5,8 +5,11 @@ public class StartLotto { public StartLotto() { int inputPrice = InputNums.price(); + MakeLottoLists makeLottoLists = new MakeLottoLists(); + makeLottoLists.makeInputLottoList(inputPrice); + List> list = makeLottoLists.makeWinLottoList(); InputNums.winningNums(); From 8391724abaac721d0b8c000444eacd48fce6cd12 Mon Sep 17 00:00:00 2001 From: enohs Date: Sat, 5 Oct 2024 18:52:07 +0900 Subject: [PATCH 04/11] =?UTF-8?q?=EC=88=98=EC=9D=B5=EB=A5=A0=20=EA=B3=84?= =?UTF-8?q?=EC=82=B0=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80,=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EC=B2=B4=ED=81=AC=20=EC=B6=94=EA=B0=80,?= =?UTF-8?q?=20=EB=A1=9C=EB=98=90=20=EB=B9=84=EA=B5=90=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=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 | 8 --- src/main/java/lotto/CheckError.java | 28 ---------- .../lotto/{ => InOutputSystem}/InputNums.java | 5 +- .../lotto/InOutputSystem/PrintStrings.java | 27 ++++++++++ src/main/java/lotto/PrintStrings.java | 26 --------- src/main/java/lotto/StartLotto.java | 18 ------- .../java/lotto/mainSystem/Application.java | 9 ++++ .../java/lotto/mainSystem/StartLotto.java | 30 +++++++++++ .../java/lotto/manageError/CheckError.java | 49 +++++++++++++++++ .../java/lotto/manageLotto/CalcProfit.java | 12 +++++ .../java/lotto/manageLotto/CompareLottos.java | 54 +++++++++++++++++++ .../{ => manageLotto}/MakeLottoLists.java | 16 ++---- .../java/lotto/manageLotto/MakeWinLotto.java | 20 +++++++ src/test/java/lotto/ApplicationTest.java | 1 + 14 files changed, 208 insertions(+), 95 deletions(-) delete mode 100644 src/main/java/lotto/Application.java delete mode 100644 src/main/java/lotto/CheckError.java rename src/main/java/lotto/{ => InOutputSystem}/InputNums.java (86%) create mode 100644 src/main/java/lotto/InOutputSystem/PrintStrings.java delete mode 100644 src/main/java/lotto/PrintStrings.java delete mode 100644 src/main/java/lotto/StartLotto.java create mode 100644 src/main/java/lotto/mainSystem/Application.java create mode 100644 src/main/java/lotto/mainSystem/StartLotto.java create mode 100644 src/main/java/lotto/manageError/CheckError.java create mode 100644 src/main/java/lotto/manageLotto/CalcProfit.java create mode 100644 src/main/java/lotto/manageLotto/CompareLottos.java rename src/main/java/lotto/{ => manageLotto}/MakeLottoLists.java (61%) create mode 100644 src/main/java/lotto/manageLotto/MakeWinLotto.java diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java deleted file mode 100644 index 55c28662..00000000 --- a/src/main/java/lotto/Application.java +++ /dev/null @@ -1,8 +0,0 @@ -package lotto; - -public class Application { - - public static void main(String[] args) { - new StartLotto(); - } -} diff --git a/src/main/java/lotto/CheckError.java b/src/main/java/lotto/CheckError.java deleted file mode 100644 index 739df4a3..00000000 --- a/src/main/java/lotto/CheckError.java +++ /dev/null @@ -1,28 +0,0 @@ -package lotto; - -public class CheckError { - public static void dividedThousand(int price){ - if (price % 1000 != 0){ - System.out.println("[Error] 남은 동전이 없어 잔돈을 드리지 못 합니다. 다시 입력해 주세요."); - throw new IllegalArgumentException(); - }} - - public static int isNum(String num){ - try { - int intNum = Integer.parseInt(num); - return intNum; - }catch (IllegalArgumentException e){ - System.out.println("숫자를 입력해 주세요~"); - throw new IllegalArgumentException(); - } - } - - public static void isNumRange(int num){ - if (num < 1 || num > 45){ - System.out.println("[Error] 1부터 45까지의 숫자만 입력해 주세요."); - throw new IllegalArgumentException(); - } - } - - -} diff --git a/src/main/java/lotto/InputNums.java b/src/main/java/lotto/InOutputSystem/InputNums.java similarity index 86% rename from src/main/java/lotto/InputNums.java rename to src/main/java/lotto/InOutputSystem/InputNums.java index a4cece34..6e792f7c 100644 --- a/src/main/java/lotto/InputNums.java +++ b/src/main/java/lotto/InOutputSystem/InputNums.java @@ -1,6 +1,7 @@ -package lotto; +package lotto.InOutputSystem; import java.util.Scanner; +import lotto.manageError.CheckError; public class InputNums { static Scanner scanner = new Scanner(System.in); @@ -21,7 +22,7 @@ public static String winningNums() { public static int bonusNum(){ System.out.println("\n보너스 번호를 입력해 주세요."); int bonusNum = scanner.nextInt(); - CheckError.isNumRange(bonusNum); + CheckError.numRange(bonusNum); return bonusNum; } } diff --git a/src/main/java/lotto/InOutputSystem/PrintStrings.java b/src/main/java/lotto/InOutputSystem/PrintStrings.java new file mode 100644 index 00000000..d0c43354 --- /dev/null +++ b/src/main/java/lotto/InOutputSystem/PrintStrings.java @@ -0,0 +1,27 @@ +package lotto.InOutputSystem; + +import java.util.List; +import java.util.Map; + +public class PrintStrings { + + public static void printLottos (List> saveLottos, int count){ + System.out.println("\n" + count + "개를 입력했습니다."); + for (int i =0; i < saveLottos.size(); i++){ + System.out.println(saveLottos.get(i)); + } + } + + public static void lottoResult(Map prizeMap, double profit){ + System.out.println("\n당첨 통계"); + System.out.println("---------"); + + System.out.println("3개 일치 (5,000원)- " + prizeMap.get("5등") + "개"); + System.out.println("4개 일치 (50,000원)- " + prizeMap.get("4등") + "개"); + System.out.println("5개 일치 (1,500,000원)- "+ prizeMap.get("3등") + "개"); + System.out.println("5개 일치, 보너스 볼 일치 (30,000,000원)-"+ prizeMap.get("2등") + "개"); + System.out.println("6개 일치 (2,000,000,000원)- "+ prizeMap.get("1등") + "개"); + + System.out.println("총 수익률은 " + String.format("%.1f", profit) + "%입니다."); + } +} diff --git a/src/main/java/lotto/PrintStrings.java b/src/main/java/lotto/PrintStrings.java deleted file mode 100644 index ba726462..00000000 --- a/src/main/java/lotto/PrintStrings.java +++ /dev/null @@ -1,26 +0,0 @@ -package lotto; - -import java.util.List; - -public class PrintStrings { - - public static void printLottos (List> saveLottos, int count){ - System.out.println("\n" + count + "개를 입력했습니다."); - for (int i =0; i < saveLottos.size(); i++){ - System.out.println(saveLottos.get(i)); - } - } - - public static void lottoResult(){ - System.out.println("\n당첨 통계"); - System.out.println("---------"); - - System.out.println("3개 일치 (5,000원)- 0개"); - System.out.println("4개 일치 (50,000원)- 0개"); - System.out.println("5개 일치 (1,500,000원)- 0개"); - System.out.println("5개 일치, 보너스 볼 일치 (30,000,000원)- 0개"); - System.out.println("6개 일치 (2,000,000,000원)- 0개"); - - System.out.println("총 수익률은 0%입니다."); - } -} diff --git a/src/main/java/lotto/StartLotto.java b/src/main/java/lotto/StartLotto.java deleted file mode 100644 index 7468d5d9..00000000 --- a/src/main/java/lotto/StartLotto.java +++ /dev/null @@ -1,18 +0,0 @@ -package lotto; - -import java.util.List; - -public class StartLotto { - public StartLotto() { - int inputPrice = InputNums.price(); - - MakeLottoLists makeLottoLists = new MakeLottoLists(); - - makeLottoLists.makeInputLottoList(inputPrice); - - List> list = makeLottoLists.makeWinLottoList(); - - InputNums.winningNums(); - InputNums.bonusNum(); - } -} diff --git a/src/main/java/lotto/mainSystem/Application.java b/src/main/java/lotto/mainSystem/Application.java new file mode 100644 index 00000000..e157264c --- /dev/null +++ b/src/main/java/lotto/mainSystem/Application.java @@ -0,0 +1,9 @@ +package lotto.mainSystem; + +public class Application { + + public static void main(String[] args) { + StartLotto startLotto = new StartLotto(); + startLotto.run(); + } +} diff --git a/src/main/java/lotto/mainSystem/StartLotto.java b/src/main/java/lotto/mainSystem/StartLotto.java new file mode 100644 index 00000000..937c445a --- /dev/null +++ b/src/main/java/lotto/mainSystem/StartLotto.java @@ -0,0 +1,30 @@ +package lotto.mainSystem; + +import java.util.List; +import java.util.Map; +import lotto.InOutputSystem.InputNums; +import lotto.InOutputSystem.PrintStrings; +import lotto.manageLotto.CalcProfit; +import lotto.manageLotto.CompareLottos; +import lotto.manageLotto.MakeLottoLists; +import lotto.manageLotto.MakeWinLotto; + +public class StartLotto { + public void run(){ + int inputPrice = InputNums.price(); + + MakeLottoLists lottoLists = new MakeLottoLists(); + List> myLottos = lottoLists.makeInputLottoList(inputPrice); + + String winningNums = InputNums.winningNums(); + List winLotto = MakeWinLotto.makeWinLotto(winningNums); + + int bonusNum = InputNums.bonusNum(); + + Map prize = CompareLottos.compareNums(myLottos, winLotto, bonusNum); + + double profit = CalcProfit.calcProfit(prize, inputPrice); + + PrintStrings.lottoResult(prize, profit); + } +} diff --git a/src/main/java/lotto/manageError/CheckError.java b/src/main/java/lotto/manageError/CheckError.java new file mode 100644 index 00000000..72480bc4 --- /dev/null +++ b/src/main/java/lotto/manageError/CheckError.java @@ -0,0 +1,49 @@ +package lotto.manageError; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class CheckError { + public static void dividedThousand(int price){ + if (price % 1000 != 0){ + System.out.println("[Error] 남은 동전이 없어 잔돈을 드리지 못 합니다. 다시 입력해 주세요."); + throw new IllegalArgumentException(); + }} + + public static int isNum(String num){ + try { + int intNum = Integer.parseInt(num); + return intNum; + }catch (IllegalArgumentException e){ + System.out.println("숫자를 입력해 주세요."); + throw new IllegalArgumentException(); + } + } + + public static void numRange(int num){ + if (num < 1 || num > 45){ + System.out.println("[Error] 1부터 45까지의 숫자만 입력해 주세요."); + throw new IllegalArgumentException(); + } + } + + public static void onlySixNums(List nums){ + if (nums.size() != 6){ + System.out.println("[Error] 숫자 6개를 입력해 주세요."); + throw new IllegalArgumentException(); + } + } + + public static List inputOnlyNums(String[] winningNumsArr){ + try { + List integerList = Arrays.stream(winningNumsArr) + .map(Integer::parseInt) + .collect(Collectors.toList()); + return integerList; + } catch (IllegalArgumentException e) { + System.out.println("[Error] 숫자를 입력해 주세요."); + throw new IllegalArgumentException(); + } + } +} diff --git a/src/main/java/lotto/manageLotto/CalcProfit.java b/src/main/java/lotto/manageLotto/CalcProfit.java new file mode 100644 index 00000000..db92aa77 --- /dev/null +++ b/src/main/java/lotto/manageLotto/CalcProfit.java @@ -0,0 +1,12 @@ +package lotto.manageLotto; + +import java.util.Map; + +public class CalcProfit { + public static double calcProfit(Map prize, int inputPrice) { + int totalPrize = (int) prize.get("1등") * 2000000000 + (int) prize.get("2등") * 30000000 + (int) prize.get("3등") * 1500000 + (int) prize.get("4등") * 50000 + (int) prize.get("5등") * 5000; + double profitRate = (double) totalPrize/ inputPrice * 100; + + return profitRate; + } +} diff --git a/src/main/java/lotto/manageLotto/CompareLottos.java b/src/main/java/lotto/manageLotto/CompareLottos.java new file mode 100644 index 00000000..c2559398 --- /dev/null +++ b/src/main/java/lotto/manageLotto/CompareLottos.java @@ -0,0 +1,54 @@ +package lotto.manageLotto; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CompareLottos { + + public static Map compareNums(List> myLottos, List winLotto, int bonusNum) { + int sixMatch = 0; + int fiveAndBonusMatch = 0; + int fiveMatch = 0; + int fourMatch = 0; + int threeMatch = 0; + + Map prizeMap = new HashMap<>(); + + for (List myLotto : myLottos) { + int matchCount = 0; + boolean bonusMatch = false; + + for (int num : myLotto) { + if (winLotto.contains(num)) { + matchCount++; + } + } + + if (myLotto.contains(bonusNum)) { + bonusMatch = true; + } + + + if (matchCount == 6) { + sixMatch++; + } else if (matchCount == 5 && bonusMatch) { + fiveAndBonusMatch++; + } else if (matchCount == 5) { + fiveMatch++; + } else if (matchCount == 4) { + fourMatch++; + } else if (matchCount == 3) { + threeMatch++; + } + } + + prizeMap.put("1등", sixMatch); + prizeMap.put("2등", fiveAndBonusMatch); + prizeMap.put("3등", fiveMatch); + prizeMap.put("4등", fourMatch); + prizeMap.put("5등", threeMatch); + + return prizeMap; + } +} \ No newline at end of file diff --git a/src/main/java/lotto/MakeLottoLists.java b/src/main/java/lotto/manageLotto/MakeLottoLists.java similarity index 61% rename from src/main/java/lotto/MakeLottoLists.java rename to src/main/java/lotto/manageLotto/MakeLottoLists.java index acecf974..716f76fe 100644 --- a/src/main/java/lotto/MakeLottoLists.java +++ b/src/main/java/lotto/manageLotto/MakeLottoLists.java @@ -1,17 +1,16 @@ -package lotto; +package lotto.manageLotto; import camp.nextstep.edu.missionutils.Randoms; import java.util.ArrayList; import java.util.List; +import lotto.manageError.CheckError; +import lotto.InOutputSystem.PrintStrings; public class MakeLottoLists { private List> saveLottos; - private List> winLottos; - private static final int DEFAULT_LOTTO_COUNT = 6; public MakeLottoLists() { this.saveLottos = new ArrayList<>(); - this.winLottos = new ArrayList<>(); } public List> makeInputLottoList(int price) { @@ -27,13 +26,4 @@ public List> makeInputLottoList(int price) { PrintStrings.printLottos(saveLottos, LOTTO_COUNT); return saveLottos; } - - public List> makeWinLottoList() { - for (int i = 0; i < DEFAULT_LOTTO_COUNT; i++) { - List numbers = Randoms.pickUniqueNumbersInRange(1, 45, 6); - winLottos.add(numbers); - } - - return winLottos; - } } diff --git a/src/main/java/lotto/manageLotto/MakeWinLotto.java b/src/main/java/lotto/manageLotto/MakeWinLotto.java new file mode 100644 index 00000000..3d8366d0 --- /dev/null +++ b/src/main/java/lotto/manageLotto/MakeWinLotto.java @@ -0,0 +1,20 @@ +package lotto.manageLotto; + +import java.util.List; +import lotto.manageError.CheckError; + +public class MakeWinLotto { + + public static List makeWinLotto(String winningNums) { + String[] winningNumsArr = winningNums.split(","); + List integerList = CheckError.inputOnlyNums(winningNumsArr); + + CheckError.onlySixNums(integerList); + + for (int i = 0; i < integerList.size(); i++) { + CheckError.numRange(integerList.get(i)); + } + + return integerList; + } +} diff --git a/src/test/java/lotto/ApplicationTest.java b/src/test/java/lotto/ApplicationTest.java index a15c7d1f..d209d693 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 lotto.mainSystem.Application; import org.junit.jupiter.api.Test; import java.util.List; From 223e3c77cf39a7fffaaab024fa15ff3091b43095 Mon Sep 17 00:00:00 2001 From: enohs Date: Mon, 7 Oct 2024 00:25:34 +0900 Subject: [PATCH 05/11] =?UTF-8?q?=ED=94=BC=EB=93=9C=EB=B0=B1=20=EB=B0=98?= =?UTF-8?q?=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lotto/InOutputSystem/InputNums.java | 28 -------- .../lotto/InOutputSystem/PrintStrings.java | 27 -------- .../lotto/error/ErrorCheckingAndParsing.java | 63 +++++++++++++++++ src/main/java/lotto/io/InputHandler.java | 36 ++++++++++ src/main/java/lotto/io/OutputHandler.java | 30 ++++++++ .../java/lotto/lotto/LottoComparison.java | 68 +++++++++++++++++++ src/main/java/lotto/lotto/MyLottoMaker.java | 29 ++++++++ .../java/lotto/lotto/ProfitCalculator.java | 15 ++++ src/main/java/lotto/lotto/WinLottoMaker.java | 21 ++++++ src/main/java/lotto/main/Application.java | 10 +++ src/main/java/lotto/main/LottoStarter.java | 32 +++++++++ .../java/lotto/mainSystem/Application.java | 9 --- .../java/lotto/mainSystem/StartLotto.java | 30 -------- .../java/lotto/manageError/CheckError.java | 49 ------------- .../java/lotto/manageLotto/CalcProfit.java | 12 ---- .../java/lotto/manageLotto/CompareLottos.java | 54 --------------- .../lotto/manageLotto/MakeLottoLists.java | 29 -------- .../java/lotto/manageLotto/MakeWinLotto.java | 20 ------ src/test/java/lotto/ApplicationTest.java | 2 +- 19 files changed, 305 insertions(+), 259 deletions(-) delete mode 100644 src/main/java/lotto/InOutputSystem/InputNums.java delete mode 100644 src/main/java/lotto/InOutputSystem/PrintStrings.java create mode 100644 src/main/java/lotto/error/ErrorCheckingAndParsing.java create mode 100644 src/main/java/lotto/io/InputHandler.java create mode 100644 src/main/java/lotto/io/OutputHandler.java create mode 100644 src/main/java/lotto/lotto/LottoComparison.java create mode 100644 src/main/java/lotto/lotto/MyLottoMaker.java create mode 100644 src/main/java/lotto/lotto/ProfitCalculator.java create mode 100644 src/main/java/lotto/lotto/WinLottoMaker.java create mode 100644 src/main/java/lotto/main/Application.java create mode 100644 src/main/java/lotto/main/LottoStarter.java delete mode 100644 src/main/java/lotto/mainSystem/Application.java delete mode 100644 src/main/java/lotto/mainSystem/StartLotto.java delete mode 100644 src/main/java/lotto/manageError/CheckError.java delete mode 100644 src/main/java/lotto/manageLotto/CalcProfit.java delete mode 100644 src/main/java/lotto/manageLotto/CompareLottos.java delete mode 100644 src/main/java/lotto/manageLotto/MakeLottoLists.java delete mode 100644 src/main/java/lotto/manageLotto/MakeWinLotto.java diff --git a/src/main/java/lotto/InOutputSystem/InputNums.java b/src/main/java/lotto/InOutputSystem/InputNums.java deleted file mode 100644 index 6e792f7c..00000000 --- a/src/main/java/lotto/InOutputSystem/InputNums.java +++ /dev/null @@ -1,28 +0,0 @@ -package lotto.InOutputSystem; - -import java.util.Scanner; -import lotto.manageError.CheckError; - -public class InputNums { - static Scanner scanner = new Scanner(System.in); - - public static int price(){ - System.out.println("구입금액을 입력해 주세요."); - String lottoPrice = scanner.nextLine(); - int intPrice = CheckError.isNum(lottoPrice); - return intPrice; - } - - public static String winningNums() { - System.out.println("\n당첨 번호를 입력해 주세요."); - String winningNums = scanner.nextLine(); - return winningNums; - } - - public static int bonusNum(){ - System.out.println("\n보너스 번호를 입력해 주세요."); - int bonusNum = scanner.nextInt(); - CheckError.numRange(bonusNum); - return bonusNum; - } -} diff --git a/src/main/java/lotto/InOutputSystem/PrintStrings.java b/src/main/java/lotto/InOutputSystem/PrintStrings.java deleted file mode 100644 index d0c43354..00000000 --- a/src/main/java/lotto/InOutputSystem/PrintStrings.java +++ /dev/null @@ -1,27 +0,0 @@ -package lotto.InOutputSystem; - -import java.util.List; -import java.util.Map; - -public class PrintStrings { - - public static void printLottos (List> saveLottos, int count){ - System.out.println("\n" + count + "개를 입력했습니다."); - for (int i =0; i < saveLottos.size(); i++){ - System.out.println(saveLottos.get(i)); - } - } - - public static void lottoResult(Map prizeMap, double profit){ - System.out.println("\n당첨 통계"); - System.out.println("---------"); - - System.out.println("3개 일치 (5,000원)- " + prizeMap.get("5등") + "개"); - System.out.println("4개 일치 (50,000원)- " + prizeMap.get("4등") + "개"); - System.out.println("5개 일치 (1,500,000원)- "+ prizeMap.get("3등") + "개"); - System.out.println("5개 일치, 보너스 볼 일치 (30,000,000원)-"+ prizeMap.get("2등") + "개"); - System.out.println("6개 일치 (2,000,000,000원)- "+ prizeMap.get("1등") + "개"); - - System.out.println("총 수익률은 " + String.format("%.1f", profit) + "%입니다."); - } -} diff --git a/src/main/java/lotto/error/ErrorCheckingAndParsing.java b/src/main/java/lotto/error/ErrorCheckingAndParsing.java new file mode 100644 index 00000000..9a50bfe8 --- /dev/null +++ b/src/main/java/lotto/error/ErrorCheckingAndParsing.java @@ -0,0 +1,63 @@ +package lotto.error; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +public class ErrorCheckingAndParsing { + + public static int isDividedThousand(int price){ + final int Dividing_THOUSAND_PLACE = 1000; + + if (price % Dividing_THOUSAND_PLACE != 0){ + throw new IllegalArgumentException("[Error] 남은 동전이 없어 잔돈을 드리지 못 합니다. 다시 입력해 주세요."); + } + + return price / Dividing_THOUSAND_PLACE; + } + + public static int isNum(String lottoPrice){ + try { + int price = Integer.parseInt(lottoPrice); + + return price; + }catch (IllegalArgumentException e){ + throw new IllegalArgumentException("숫자를 입력해 주세요."); + } + + } + + public static void numRange(int lottoNum){ + + final int MINIMUM_NUMBER_RANGE = 1; + final int MAXIMUM_NUMBER_RANGE = 45; + + if (lottoNum < MINIMUM_NUMBER_RANGE || lottoNum > MAXIMUM_NUMBER_RANGE){ + throw new IllegalArgumentException("[Error] 1부터 45까지의 숫자만 입력해 주세요."); + } + + } + + public static void isOnlySixNums(List winNums){ + + final int LOTTO_NUM_COUNT = 6; + + if (winNums.size() != LOTTO_NUM_COUNT){ + throw new IllegalArgumentException("[Error] 숫자 6개를 입력해 주세요."); + } + + } + + public static List isNumsAsString(String[] winNumbersAsStrings){ + try { + List winNums = Arrays.stream(winNumbersAsStrings) + .map(Integer::parseInt) + .collect(Collectors.toList()); + + return winNums; + } catch (IllegalArgumentException e) { + throw new IllegalArgumentException("[Error] 숫자를 입력해 주세요."); + } + } + +} diff --git a/src/main/java/lotto/io/InputHandler.java b/src/main/java/lotto/io/InputHandler.java new file mode 100644 index 00000000..75e00d90 --- /dev/null +++ b/src/main/java/lotto/io/InputHandler.java @@ -0,0 +1,36 @@ +package lotto.io; + +import java.util.Scanner; +import lotto.error.ErrorCheckingAndParsing; + +public class InputHandler { + + static Scanner scanner = new Scanner(System.in); + + public static int getPrice(){ + System.out.println("구입 금액을 입력해 주세요."); + + String lottoPrice = scanner.nextLine(); + int price = ErrorCheckingAndParsing.isNum(lottoPrice); + + return price; + } + + public static String getWinNums() { + System.out.println("\n당첨 번호를 입력해 주세요."); + + String winNumbers = scanner.nextLine(); + + return winNumbers; + } + + public static int getBonusNum(){ + System.out.println("\n보너스 번호를 입력해 주세요."); + int bonusNumber = scanner.nextInt(); + + ErrorCheckingAndParsing.numRange(bonusNumber); + + return bonusNumber; + } + +} diff --git a/src/main/java/lotto/io/OutputHandler.java b/src/main/java/lotto/io/OutputHandler.java new file mode 100644 index 00000000..4e58a649 --- /dev/null +++ b/src/main/java/lotto/io/OutputHandler.java @@ -0,0 +1,30 @@ +package lotto.io; + +import java.util.List; +import java.util.Map; + +public class OutputHandler { + + public static void printLottos (List> lottoStorage, int count){ + + System.out.println("\n" + count + "개를 입력했습니다."); + for (int i =0; i < lottoStorage.size(); i++){ + System.out.println(lottoStorage.get(i)); + } + } + + public static void printLottoResult(Map prizeRanking, double profit){ + + System.out.println("\n당첨 통계"); + System.out.println("---------"); + + System.out.println("3개 일치 (5,000원)- " + prizeRanking.get("5등") + "개"); + System.out.println("4개 일치 (50,000원)- " + prizeRanking.get("4등") + "개"); + System.out.println("5개 일치 (1,500,000원)- "+ prizeRanking.get("3등") + "개"); + System.out.println("5개 일치, 보너스 볼 일치 (30,000,000원)-"+ prizeRanking.get("2등") + "개"); + System.out.println("6개 일치 (2,000,000,000원)- "+ prizeRanking.get("1등") + "개"); + + System.out.println("총 수익률은 " + String.format("%.1f", profit) + "%입니다."); + } + +} diff --git a/src/main/java/lotto/lotto/LottoComparison.java b/src/main/java/lotto/lotto/LottoComparison.java new file mode 100644 index 00000000..73069ffc --- /dev/null +++ b/src/main/java/lotto/lotto/LottoComparison.java @@ -0,0 +1,68 @@ +package lotto.lotto; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class LottoComparison { + + public static Map compareNums(List> myLottos, List winLotto, int bonusNumber) { + + int sixMatch = 0; + int fiveAndBonusMatch = 0; + int fiveMatch = 0; + int fourMatch = 0; + int threeMatch = 0; + final int FIRST_PLACE = 6; + final int SECOND_PLACE = 5; + final int THIRD_PLACE = 4; + final int FOURTH_PLACE = 3; + final int FIFTH_PLACE = 2; + + Map prizeRanking = new HashMap<>(); + + for (List myLotto : myLottos) { + int matchCount = 0; + boolean bonusMatch = false; + + for (int num : myLotto) { + if (winLotto.contains(num)) { + matchCount++; + } + } + + if (myLotto.contains(bonusNumber)) { + bonusMatch = true; + } + + + switch (matchCount) { + case 6: + sixMatch++; + break; + case 5: + if (bonusMatch) { + fiveAndBonusMatch++; + } else { + fiveMatch++; + } + break; + case 4: + fourMatch++; + break; + case 3: + threeMatch++; + break; + } + } + + prizeRanking.put(FIRST_PLACE, sixMatch); + prizeRanking.put(SECOND_PLACE, fiveAndBonusMatch); + prizeRanking.put(THIRD_PLACE, fiveMatch); + prizeRanking.put(FOURTH_PLACE, fourMatch); + prizeRanking.put(FIFTH_PLACE, threeMatch); + + return prizeRanking; + } + +} diff --git a/src/main/java/lotto/lotto/MyLottoMaker.java b/src/main/java/lotto/lotto/MyLottoMaker.java new file mode 100644 index 00000000..0a88f7e8 --- /dev/null +++ b/src/main/java/lotto/lotto/MyLottoMaker.java @@ -0,0 +1,29 @@ +package lotto.lotto; + +import camp.nextstep.edu.missionutils.Randoms; +import java.util.ArrayList; +import java.util.List; +import lotto.error.ErrorCheckingAndParsing; +import lotto.io.OutputHandler; + +public class MyLottoMaker { + + public List> makeMyLottos(int price) { + final int MINIMUM_NUMBER = 1; + final int MAXIMUM_NUMBER = 45; + final int LOTTO_NUM_COUNT = 6; + final int LOTTO_COUNT = ErrorCheckingAndParsing.isDividedThousand(price); + + List> lottoStorage = new ArrayList<>(); + + for (int i = 0; i < LOTTO_COUNT; i++) { + List myLotto = Randoms.pickUniqueNumbersInRange(MINIMUM_NUMBER, MAXIMUM_NUMBER, LOTTO_NUM_COUNT); + lottoStorage.add(myLotto); + } + + OutputHandler.printLottos(lottoStorage, LOTTO_COUNT); + + return lottoStorage; + } + +} diff --git a/src/main/java/lotto/lotto/ProfitCalculator.java b/src/main/java/lotto/lotto/ProfitCalculator.java new file mode 100644 index 00000000..9ea6f0c0 --- /dev/null +++ b/src/main/java/lotto/lotto/ProfitCalculator.java @@ -0,0 +1,15 @@ +package lotto.lotto; + +import java.util.Map; + +public class ProfitCalculator { + + public static double calcProfit(Map prizeRanking, int inputPrice) { + int totalPrize = (int) prizeRanking.get("1등") * 2000000000 + (int) prizeRanking.get("2등") * 30000000 + (int) prizeRanking.get("3등") * 1500000 + (int) prizeRanking.get("4등") * 50000 + (int) prizeRanking.get("5등") * 5000; + + double profitRate = (double) totalPrize/ inputPrice * 100; + + return profitRate; + } + +} diff --git a/src/main/java/lotto/lotto/WinLottoMaker.java b/src/main/java/lotto/lotto/WinLottoMaker.java new file mode 100644 index 00000000..a9f680d3 --- /dev/null +++ b/src/main/java/lotto/lotto/WinLottoMaker.java @@ -0,0 +1,21 @@ +package lotto.lotto; + +import java.util.List; +import lotto.error.ErrorCheckingAndParsing; + +public class WinLottoMaker { + + public static List makeWinLotto(String winNumbersAsString) { + String[] winNumbersAsStrings = winNumbersAsString.split(","); + + List winNums = ErrorCheckingAndParsing.isNumsAsString(winNumbersAsStrings); + ErrorCheckingAndParsing.isOnlySixNums(winNums); + + for (int i = 0; i < winNums.size(); i++) { + ErrorCheckingAndParsing.numRange(winNums.get(i)); + } + + return winNums; + } + +} diff --git a/src/main/java/lotto/main/Application.java b/src/main/java/lotto/main/Application.java new file mode 100644 index 00000000..6f8939f7 --- /dev/null +++ b/src/main/java/lotto/main/Application.java @@ -0,0 +1,10 @@ +package lotto.main; + +public class Application { + + public static void main(String[] args) { + LottoStarter lottoStarter = new LottoStarter(); + lottoStarter.run(); + } + +} diff --git a/src/main/java/lotto/main/LottoStarter.java b/src/main/java/lotto/main/LottoStarter.java new file mode 100644 index 00000000..849b29ba --- /dev/null +++ b/src/main/java/lotto/main/LottoStarter.java @@ -0,0 +1,32 @@ +package lotto.main; + +import java.util.List; +import java.util.Map; +import lotto.io.InputHandler; +import lotto.io.OutputHandler; +import lotto.lotto.ProfitCalculator; +import lotto.lotto.LottoComparison; +import lotto.lotto.MyLottoMaker; +import lotto.lotto.WinLottoMaker; + +public class LottoStarter { + + public void run(){ + int price = InputHandler.getPrice(); + + MyLottoMaker myLottoMaker = new MyLottoMaker(); + List> myLottos = myLottoMaker.makeMyLottos(price); + + String winNumbersAsString = InputHandler.getWinNums(); + List winLotto = WinLottoMaker.makeWinLotto(winNumbersAsString); + + int bonusNumber = InputHandler.getBonusNum(); + + Map prizeRanking = LottoComparison.compareNums(myLottos, winLotto, bonusNumber); + + double profit = ProfitCalculator.calcProfit(prizeRanking, price); + + OutputHandler.printLottoResult(prizeRanking, profit); + } + +} diff --git a/src/main/java/lotto/mainSystem/Application.java b/src/main/java/lotto/mainSystem/Application.java deleted file mode 100644 index e157264c..00000000 --- a/src/main/java/lotto/mainSystem/Application.java +++ /dev/null @@ -1,9 +0,0 @@ -package lotto.mainSystem; - -public class Application { - - public static void main(String[] args) { - StartLotto startLotto = new StartLotto(); - startLotto.run(); - } -} diff --git a/src/main/java/lotto/mainSystem/StartLotto.java b/src/main/java/lotto/mainSystem/StartLotto.java deleted file mode 100644 index 937c445a..00000000 --- a/src/main/java/lotto/mainSystem/StartLotto.java +++ /dev/null @@ -1,30 +0,0 @@ -package lotto.mainSystem; - -import java.util.List; -import java.util.Map; -import lotto.InOutputSystem.InputNums; -import lotto.InOutputSystem.PrintStrings; -import lotto.manageLotto.CalcProfit; -import lotto.manageLotto.CompareLottos; -import lotto.manageLotto.MakeLottoLists; -import lotto.manageLotto.MakeWinLotto; - -public class StartLotto { - public void run(){ - int inputPrice = InputNums.price(); - - MakeLottoLists lottoLists = new MakeLottoLists(); - List> myLottos = lottoLists.makeInputLottoList(inputPrice); - - String winningNums = InputNums.winningNums(); - List winLotto = MakeWinLotto.makeWinLotto(winningNums); - - int bonusNum = InputNums.bonusNum(); - - Map prize = CompareLottos.compareNums(myLottos, winLotto, bonusNum); - - double profit = CalcProfit.calcProfit(prize, inputPrice); - - PrintStrings.lottoResult(prize, profit); - } -} diff --git a/src/main/java/lotto/manageError/CheckError.java b/src/main/java/lotto/manageError/CheckError.java deleted file mode 100644 index 72480bc4..00000000 --- a/src/main/java/lotto/manageError/CheckError.java +++ /dev/null @@ -1,49 +0,0 @@ -package lotto.manageError; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -public class CheckError { - public static void dividedThousand(int price){ - if (price % 1000 != 0){ - System.out.println("[Error] 남은 동전이 없어 잔돈을 드리지 못 합니다. 다시 입력해 주세요."); - throw new IllegalArgumentException(); - }} - - public static int isNum(String num){ - try { - int intNum = Integer.parseInt(num); - return intNum; - }catch (IllegalArgumentException e){ - System.out.println("숫자를 입력해 주세요."); - throw new IllegalArgumentException(); - } - } - - public static void numRange(int num){ - if (num < 1 || num > 45){ - System.out.println("[Error] 1부터 45까지의 숫자만 입력해 주세요."); - throw new IllegalArgumentException(); - } - } - - public static void onlySixNums(List nums){ - if (nums.size() != 6){ - System.out.println("[Error] 숫자 6개를 입력해 주세요."); - throw new IllegalArgumentException(); - } - } - - public static List inputOnlyNums(String[] winningNumsArr){ - try { - List integerList = Arrays.stream(winningNumsArr) - .map(Integer::parseInt) - .collect(Collectors.toList()); - return integerList; - } catch (IllegalArgumentException e) { - System.out.println("[Error] 숫자를 입력해 주세요."); - throw new IllegalArgumentException(); - } - } -} diff --git a/src/main/java/lotto/manageLotto/CalcProfit.java b/src/main/java/lotto/manageLotto/CalcProfit.java deleted file mode 100644 index db92aa77..00000000 --- a/src/main/java/lotto/manageLotto/CalcProfit.java +++ /dev/null @@ -1,12 +0,0 @@ -package lotto.manageLotto; - -import java.util.Map; - -public class CalcProfit { - public static double calcProfit(Map prize, int inputPrice) { - int totalPrize = (int) prize.get("1등") * 2000000000 + (int) prize.get("2등") * 30000000 + (int) prize.get("3등") * 1500000 + (int) prize.get("4등") * 50000 + (int) prize.get("5등") * 5000; - double profitRate = (double) totalPrize/ inputPrice * 100; - - return profitRate; - } -} diff --git a/src/main/java/lotto/manageLotto/CompareLottos.java b/src/main/java/lotto/manageLotto/CompareLottos.java deleted file mode 100644 index c2559398..00000000 --- a/src/main/java/lotto/manageLotto/CompareLottos.java +++ /dev/null @@ -1,54 +0,0 @@ -package lotto.manageLotto; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class CompareLottos { - - public static Map compareNums(List> myLottos, List winLotto, int bonusNum) { - int sixMatch = 0; - int fiveAndBonusMatch = 0; - int fiveMatch = 0; - int fourMatch = 0; - int threeMatch = 0; - - Map prizeMap = new HashMap<>(); - - for (List myLotto : myLottos) { - int matchCount = 0; - boolean bonusMatch = false; - - for (int num : myLotto) { - if (winLotto.contains(num)) { - matchCount++; - } - } - - if (myLotto.contains(bonusNum)) { - bonusMatch = true; - } - - - if (matchCount == 6) { - sixMatch++; - } else if (matchCount == 5 && bonusMatch) { - fiveAndBonusMatch++; - } else if (matchCount == 5) { - fiveMatch++; - } else if (matchCount == 4) { - fourMatch++; - } else if (matchCount == 3) { - threeMatch++; - } - } - - prizeMap.put("1등", sixMatch); - prizeMap.put("2등", fiveAndBonusMatch); - prizeMap.put("3등", fiveMatch); - prizeMap.put("4등", fourMatch); - prizeMap.put("5등", threeMatch); - - return prizeMap; - } -} \ No newline at end of file diff --git a/src/main/java/lotto/manageLotto/MakeLottoLists.java b/src/main/java/lotto/manageLotto/MakeLottoLists.java deleted file mode 100644 index 716f76fe..00000000 --- a/src/main/java/lotto/manageLotto/MakeLottoLists.java +++ /dev/null @@ -1,29 +0,0 @@ -package lotto.manageLotto; - -import camp.nextstep.edu.missionutils.Randoms; -import java.util.ArrayList; -import java.util.List; -import lotto.manageError.CheckError; -import lotto.InOutputSystem.PrintStrings; - -public class MakeLottoLists { - private List> saveLottos; - - public MakeLottoLists() { - this.saveLottos = new ArrayList<>(); - } - - public List> makeInputLottoList(int price) { - int LOTTO_COUNT = price / 1000; - - CheckError.dividedThousand(price); - - for (int i = 0; i < LOTTO_COUNT; i++) { - List numbers = Randoms.pickUniqueNumbersInRange(1, 45, 6); - saveLottos.add(numbers); - } - - PrintStrings.printLottos(saveLottos, LOTTO_COUNT); - return saveLottos; - } -} diff --git a/src/main/java/lotto/manageLotto/MakeWinLotto.java b/src/main/java/lotto/manageLotto/MakeWinLotto.java deleted file mode 100644 index 3d8366d0..00000000 --- a/src/main/java/lotto/manageLotto/MakeWinLotto.java +++ /dev/null @@ -1,20 +0,0 @@ -package lotto.manageLotto; - -import java.util.List; -import lotto.manageError.CheckError; - -public class MakeWinLotto { - - public static List makeWinLotto(String winningNums) { - String[] winningNumsArr = winningNums.split(","); - List integerList = CheckError.inputOnlyNums(winningNumsArr); - - CheckError.onlySixNums(integerList); - - for (int i = 0; i < integerList.size(); i++) { - CheckError.numRange(integerList.get(i)); - } - - return integerList; - } -} diff --git a/src/test/java/lotto/ApplicationTest.java b/src/test/java/lotto/ApplicationTest.java index d209d693..b3e0ab44 100644 --- a/src/test/java/lotto/ApplicationTest.java +++ b/src/test/java/lotto/ApplicationTest.java @@ -1,7 +1,7 @@ package lotto; import camp.nextstep.edu.missionutils.test.NsTest; -import lotto.mainSystem.Application; +import lotto.main.Application; import org.junit.jupiter.api.Test; import java.util.List; From e7e931ab2d5ff18cdcfc80271534a00687d46bb9 Mon Sep 17 00:00:00 2001 From: enohs Date: Mon, 7 Oct 2024 01:47:52 +0900 Subject: [PATCH 06/11] =?UTF-8?q?=EB=A1=9C=ED=86=A0=20=EB=A7=A4=EC=B9=98?= =?UTF-8?q?=20=EC=B9=B4=EC=9A=B4=ED=84=B0=20=ED=81=B4=EB=9E=98=EC=8A=A4=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80,=20=EB=B3=80=EC=88=98=EB=AA=85=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD,=20=EC=83=81=EC=88=98=20=EC=82=AC=EC=9A=A9,=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EB=82=AE=EC=B6=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lotto/error/ErrorCheckingAndParsing.java | 20 +++--- src/main/java/lotto/io/InputHandler.java | 8 +-- src/main/java/lotto/io/OutputHandler.java | 21 +++--- .../java/lotto/lotto/LottoComparison.java | 68 +++++-------------- .../java/lotto/lotto/LottoMatchCounter.java | 51 ++++++++++++++ .../java/lotto/lotto/ProfitCalculator.java | 11 ++- src/main/java/lotto/lotto/WinLottoMaker.java | 10 +-- src/main/java/lotto/main/LottoStarter.java | 20 ++++-- 8 files changed, 119 insertions(+), 90 deletions(-) create mode 100644 src/main/java/lotto/lotto/LottoMatchCounter.java diff --git a/src/main/java/lotto/error/ErrorCheckingAndParsing.java b/src/main/java/lotto/error/ErrorCheckingAndParsing.java index 9a50bfe8..b04c975d 100644 --- a/src/main/java/lotto/error/ErrorCheckingAndParsing.java +++ b/src/main/java/lotto/error/ErrorCheckingAndParsing.java @@ -5,15 +5,19 @@ import java.util.stream.Collectors; public class ErrorCheckingAndParsing { + static final int THOUSAND_PLACE = 1000; + static final int MINIMUM_NUMBER_RANGE = 1; + static final int MAXIMUM_NUMBER_RANGE = 45; + static final int LOTTO_NUM_COUNT = 6; + public static int isDividedThousand(int price){ - final int Dividing_THOUSAND_PLACE = 1000; - if (price % Dividing_THOUSAND_PLACE != 0){ + if (price % THOUSAND_PLACE != 0){ throw new IllegalArgumentException("[Error] 남은 동전이 없어 잔돈을 드리지 못 합니다. 다시 입력해 주세요."); } - return price / Dividing_THOUSAND_PLACE; + return price / THOUSAND_PLACE; } public static int isNum(String lottoPrice){ @@ -27,11 +31,7 @@ public static int isNum(String lottoPrice){ } - public static void numRange(int lottoNum){ - - final int MINIMUM_NUMBER_RANGE = 1; - final int MAXIMUM_NUMBER_RANGE = 45; - + public static void confirmNumRange(int lottoNum){ if (lottoNum < MINIMUM_NUMBER_RANGE || lottoNum > MAXIMUM_NUMBER_RANGE){ throw new IllegalArgumentException("[Error] 1부터 45까지의 숫자만 입력해 주세요."); } @@ -39,13 +39,9 @@ public static void numRange(int lottoNum){ } public static void isOnlySixNums(List winNums){ - - final int LOTTO_NUM_COUNT = 6; - if (winNums.size() != LOTTO_NUM_COUNT){ throw new IllegalArgumentException("[Error] 숫자 6개를 입력해 주세요."); } - } public static List isNumsAsString(String[] winNumbersAsStrings){ diff --git a/src/main/java/lotto/io/InputHandler.java b/src/main/java/lotto/io/InputHandler.java index 75e00d90..bd790d85 100644 --- a/src/main/java/lotto/io/InputHandler.java +++ b/src/main/java/lotto/io/InputHandler.java @@ -7,7 +7,7 @@ public class InputHandler { static Scanner scanner = new Scanner(System.in); - public static int getPrice(){ + public int getPrice(){ System.out.println("구입 금액을 입력해 주세요."); String lottoPrice = scanner.nextLine(); @@ -16,7 +16,7 @@ public static int getPrice(){ return price; } - public static String getWinNums() { + public String getWinNums() { System.out.println("\n당첨 번호를 입력해 주세요."); String winNumbers = scanner.nextLine(); @@ -24,11 +24,11 @@ public static String getWinNums() { return winNumbers; } - public static int getBonusNum(){ + public int getBonusNum(){ System.out.println("\n보너스 번호를 입력해 주세요."); int bonusNumber = scanner.nextInt(); - ErrorCheckingAndParsing.numRange(bonusNumber); + ErrorCheckingAndParsing.confirmNumRange(bonusNumber); return bonusNumber; } diff --git a/src/main/java/lotto/io/OutputHandler.java b/src/main/java/lotto/io/OutputHandler.java index 4e58a649..4c46a7ec 100644 --- a/src/main/java/lotto/io/OutputHandler.java +++ b/src/main/java/lotto/io/OutputHandler.java @@ -13,18 +13,21 @@ public static void printLottos (List> lottoStorage, int count){ } } - public static void printLottoResult(Map prizeRanking, double profit){ + public static void printLottoResult(Map prizeRanking, double profitRate){ + final int FIRST_PLACE = 6; + final int SECOND_PLACE = 5; + final int THIRD_PLACE = 4; + final int FOURTH_PLACE = 3; + final int FIFTH_PLACE = 2; System.out.println("\n당첨 통계"); System.out.println("---------"); - - System.out.println("3개 일치 (5,000원)- " + prizeRanking.get("5등") + "개"); - System.out.println("4개 일치 (50,000원)- " + prizeRanking.get("4등") + "개"); - System.out.println("5개 일치 (1,500,000원)- "+ prizeRanking.get("3등") + "개"); - System.out.println("5개 일치, 보너스 볼 일치 (30,000,000원)-"+ prizeRanking.get("2등") + "개"); - System.out.println("6개 일치 (2,000,000,000원)- "+ prizeRanking.get("1등") + "개"); - - System.out.println("총 수익률은 " + String.format("%.1f", profit) + "%입니다."); + System.out.println("3개 일치 (5,000원)- " + prizeRanking.get(FIFTH_PLACE) + "개"); + System.out.println("4개 일치 (50,000원)- " + prizeRanking.get(FOURTH_PLACE) + "개"); + System.out.println("5개 일치 (1,500,000원)- "+ prizeRanking.get(THIRD_PLACE) + "개"); + System.out.println("5개 일치, 보너스 볼 일치 (30,000,000원)-"+ prizeRanking.get(SECOND_PLACE) + "개"); + System.out.println("6개 일치 (2,000,000,000원)- "+ prizeRanking.get(FIRST_PLACE) + "개"); + System.out.println("총 수익률은 " + String.format("%.1f", profitRate) + "%입니다."); } } diff --git a/src/main/java/lotto/lotto/LottoComparison.java b/src/main/java/lotto/lotto/LottoComparison.java index 73069ffc..6c4299a2 100644 --- a/src/main/java/lotto/lotto/LottoComparison.java +++ b/src/main/java/lotto/lotto/LottoComparison.java @@ -1,68 +1,32 @@ package lotto.lotto; -import java.util.HashMap; import java.util.List; -import java.util.Map; public class LottoComparison { - public static Map compareNums(List> myLottos, List winLotto, int bonusNumber) { + LottoMatchCounter lottoMatchCounter; - int sixMatch = 0; - int fiveAndBonusMatch = 0; - int fiveMatch = 0; - int fourMatch = 0; - int threeMatch = 0; - final int FIRST_PLACE = 6; - final int SECOND_PLACE = 5; - final int THIRD_PLACE = 4; - final int FOURTH_PLACE = 3; - final int FIFTH_PLACE = 2; - - Map prizeRanking = new HashMap<>(); + public LottoComparison(LottoMatchCounter lottoMatchCounter) { + this.lottoMatchCounter = lottoMatchCounter; + } + public void compareNums(List> myLottos, List winLotto, int bonusNumber) { for (List myLotto : myLottos) { - int matchCount = 0; - boolean bonusMatch = false; - - for (int num : myLotto) { - if (winLotto.contains(num)) { - matchCount++; - } - } - - if (myLotto.contains(bonusNumber)) { - bonusMatch = true; - } + int matchCount = countMatchingNumbers(myLotto, winLotto); + boolean bonusMatch = myLotto.contains(bonusNumber); + lottoMatchCounter.countMatch(matchCount, bonusMatch); + } + } - switch (matchCount) { - case 6: - sixMatch++; - break; - case 5: - if (bonusMatch) { - fiveAndBonusMatch++; - } else { - fiveMatch++; - } - break; - case 4: - fourMatch++; - break; - case 3: - threeMatch++; - break; + private int countMatchingNumbers(List myLotto, List winLotto) { + int matchCount = 0; + for (int num : myLotto) { + if (winLotto.contains(num)) { + matchCount++; } } - - prizeRanking.put(FIRST_PLACE, sixMatch); - prizeRanking.put(SECOND_PLACE, fiveAndBonusMatch); - prizeRanking.put(THIRD_PLACE, fiveMatch); - prizeRanking.put(FOURTH_PLACE, fourMatch); - prizeRanking.put(FIFTH_PLACE, threeMatch); - - return prizeRanking; + return matchCount; } } diff --git a/src/main/java/lotto/lotto/LottoMatchCounter.java b/src/main/java/lotto/lotto/LottoMatchCounter.java new file mode 100644 index 00000000..91a04856 --- /dev/null +++ b/src/main/java/lotto/lotto/LottoMatchCounter.java @@ -0,0 +1,51 @@ +package lotto.lotto; + +import java.util.Map; + +public class LottoMatchCounter { + + int sixMatch = 0; + int fiveAndBonusMatch = 0; + int fiveMatch = 0; + int fourMatch = 0; + int threeMatch = 0; + final int FIRST_PLACE = 6; + final int SECOND_PLACE = 5; + final int THIRD_PLACE = 4; + final int FOURTH_PLACE = 3; + final int FIFTH_PLACE = 2; + + public void countMatch(int matchCount, boolean bonusMatch) { + switch (matchCount) { + case 6: + sixMatch++; + break; + case 5: + if (bonusMatch) { + fiveAndBonusMatch++; + } else { + fiveMatch++; + } + break; + case 4: + fourMatch++; + break; + case 3: + threeMatch++; + break; + } + } + + public Map getPrizeRanking() { + Map prizeRanking = Map.of( + FIRST_PLACE, sixMatch, + SECOND_PLACE, fiveAndBonusMatch, + THIRD_PLACE, fiveMatch, + FOURTH_PLACE, fourMatch, + FIFTH_PLACE, threeMatch + ); + + return prizeRanking; + } + +} diff --git a/src/main/java/lotto/lotto/ProfitCalculator.java b/src/main/java/lotto/lotto/ProfitCalculator.java index 9ea6f0c0..e12b59a9 100644 --- a/src/main/java/lotto/lotto/ProfitCalculator.java +++ b/src/main/java/lotto/lotto/ProfitCalculator.java @@ -1,11 +1,18 @@ package lotto.lotto; import java.util.Map; +import java.util.Set; public class ProfitCalculator { - public static double calcProfit(Map prizeRanking, int inputPrice) { - int totalPrize = (int) prizeRanking.get("1등") * 2000000000 + (int) prizeRanking.get("2등") * 30000000 + (int) prizeRanking.get("3등") * 1500000 + (int) prizeRanking.get("4등") * 50000 + (int) prizeRanking.get("5등") * 5000; + public double calcProfit(Map prizeRanking, int inputPrice) { + final int FIRST_PLACE = 6; + final int SECOND_PLACE = 5; + final int THIRD_PLACE = 4; + final int FOURTH_PLACE = 3; + final int FIFTH_PLACE = 2; + + int totalPrize = prizeRanking.get(FIRST_PLACE) * 2000000000 + prizeRanking.get(SECOND_PLACE) * 30000000 + prizeRanking.get(THIRD_PLACE) * 1500000 + prizeRanking.get(FOURTH_PLACE) * 50000 + prizeRanking.get(FIFTH_PLACE) * 5000; double profitRate = (double) totalPrize/ inputPrice * 100; diff --git a/src/main/java/lotto/lotto/WinLottoMaker.java b/src/main/java/lotto/lotto/WinLottoMaker.java index a9f680d3..288199ed 100644 --- a/src/main/java/lotto/lotto/WinLottoMaker.java +++ b/src/main/java/lotto/lotto/WinLottoMaker.java @@ -8,14 +8,14 @@ public class WinLottoMaker { public static List makeWinLotto(String winNumbersAsString) { String[] winNumbersAsStrings = winNumbersAsString.split(","); - List winNums = ErrorCheckingAndParsing.isNumsAsString(winNumbersAsStrings); - ErrorCheckingAndParsing.isOnlySixNums(winNums); + List winNumbers = ErrorCheckingAndParsing.isNumsAsString(winNumbersAsStrings); + ErrorCheckingAndParsing.isOnlySixNums(winNumbers); - for (int i = 0; i < winNums.size(); i++) { - ErrorCheckingAndParsing.numRange(winNums.get(i)); + for (int i = 0; i < winNumbers.size(); i++) { + ErrorCheckingAndParsing.confirmNumRange(winNumbers.get(i)); } - return winNums; + return winNumbers; } } diff --git a/src/main/java/lotto/main/LottoStarter.java b/src/main/java/lotto/main/LottoStarter.java index 849b29ba..c2ecc3ea 100644 --- a/src/main/java/lotto/main/LottoStarter.java +++ b/src/main/java/lotto/main/LottoStarter.java @@ -2,8 +2,10 @@ import java.util.List; import java.util.Map; +import lotto.Lotto; import lotto.io.InputHandler; import lotto.io.OutputHandler; +import lotto.lotto.LottoMatchCounter; import lotto.lotto.ProfitCalculator; import lotto.lotto.LottoComparison; import lotto.lotto.MyLottoMaker; @@ -12,21 +14,27 @@ public class LottoStarter { public void run(){ - int price = InputHandler.getPrice(); + InputHandler inputHandler = new InputHandler(); + int price = inputHandler.getPrice(); MyLottoMaker myLottoMaker = new MyLottoMaker(); List> myLottos = myLottoMaker.makeMyLottos(price); - String winNumbersAsString = InputHandler.getWinNums(); + String winNumbersAsString = inputHandler.getWinNums(); List winLotto = WinLottoMaker.makeWinLotto(winNumbersAsString); - int bonusNumber = InputHandler.getBonusNum(); + int bonusNumber = inputHandler.getBonusNum(); - Map prizeRanking = LottoComparison.compareNums(myLottos, winLotto, bonusNumber); + LottoMatchCounter lottoMatchCounter = new LottoMatchCounter(); + LottoComparison lottoComparison = new LottoComparison(lottoMatchCounter); + lottoComparison.compareNums(myLottos, winLotto, bonusNumber); - double profit = ProfitCalculator.calcProfit(prizeRanking, price); + Map prizeRanking = lottoMatchCounter.getPrizeRanking(); - OutputHandler.printLottoResult(prizeRanking, profit); + ProfitCalculator profitCalculator = new ProfitCalculator(); + double profitRate = profitCalculator.calcProfit(prizeRanking, price); + + OutputHandler.printLottoResult(prizeRanking, profitRate); } } From 174503ca405273ac5724a583f9bb31513a3e221e Mon Sep 17 00:00:00 2001 From: enohs Date: Thu, 10 Oct 2024 13:38:06 +0900 Subject: [PATCH 07/11] =?UTF-8?q?=EC=8A=A4=ED=83=80=ED=84=B0=20=ED=81=B4?= =?UTF-8?q?=EB=9E=98=EC=8A=A4=20=EC=82=AD=EC=A0=9C=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EC=A3=BC=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lotto/error/ErrorCheckingAndParsing.java | 2 +- src/main/java/lotto/io/InputHandler.java | 8 +++- src/main/java/lotto/io/OutputHandler.java | 30 +++++++++++++- .../java/lotto/lotto/LottoComparison.java | 15 ++++++- src/main/java/lotto/lotto/MyLottoMaker.java | 30 +++++++++----- .../java/lotto/lotto/ProfitCalculator.java | 20 ++++++++-- src/main/java/lotto/lotto/WinLottoMaker.java | 20 ++++++++-- src/main/java/lotto/main/Application.java | 18 ++++++++- src/main/java/lotto/main/LottoStarter.java | 40 ------------------- 9 files changed, 120 insertions(+), 63 deletions(-) delete mode 100644 src/main/java/lotto/main/LottoStarter.java diff --git a/src/main/java/lotto/error/ErrorCheckingAndParsing.java b/src/main/java/lotto/error/ErrorCheckingAndParsing.java index b04c975d..0a368b60 100644 --- a/src/main/java/lotto/error/ErrorCheckingAndParsing.java +++ b/src/main/java/lotto/error/ErrorCheckingAndParsing.java @@ -5,12 +5,12 @@ import java.util.stream.Collectors; public class ErrorCheckingAndParsing { + static final int THOUSAND_PLACE = 1000; static final int MINIMUM_NUMBER_RANGE = 1; static final int MAXIMUM_NUMBER_RANGE = 45; static final int LOTTO_NUM_COUNT = 6; - public static int isDividedThousand(int price){ if (price % THOUSAND_PLACE != 0){ diff --git a/src/main/java/lotto/io/InputHandler.java b/src/main/java/lotto/io/InputHandler.java index bd790d85..d6a90c81 100644 --- a/src/main/java/lotto/io/InputHandler.java +++ b/src/main/java/lotto/io/InputHandler.java @@ -5,14 +5,20 @@ public class InputHandler { + int price = 0; + static Scanner scanner = new Scanner(System.in); public int getPrice(){ System.out.println("구입 금액을 입력해 주세요."); String lottoPrice = scanner.nextLine(); - int price = ErrorCheckingAndParsing.isNum(lottoPrice); + price = ErrorCheckingAndParsing.isNum(lottoPrice); + + return price; + } + public int getInputPrice() { return price; } diff --git a/src/main/java/lotto/io/OutputHandler.java b/src/main/java/lotto/io/OutputHandler.java index 4c46a7ec..df787d4e 100644 --- a/src/main/java/lotto/io/OutputHandler.java +++ b/src/main/java/lotto/io/OutputHandler.java @@ -2,18 +2,42 @@ import java.util.List; import java.util.Map; +import lotto.lotto.LottoMatchCounter; +import lotto.lotto.MyLottoMaker; +import lotto.lotto.ProfitCalculator; public class OutputHandler { - public static void printLottos (List> lottoStorage, int count){ + MyLottoMaker myLottoMaker; + InputHandler inputHandler; + LottoMatchCounter lottoMatchCounter; + ProfitCalculator profitCalculator; + public OutputHandler(InputHandler inputHandler, MyLottoMaker myLottoMaker){ + this.myLottoMaker = myLottoMaker; + this.inputHandler = inputHandler; + printLottos(myLottoMaker); + } + public OutputHandler(LottoMatchCounter lottoMatchCounter, ProfitCalculator profitCalculator){ + + this.lottoMatchCounter = lottoMatchCounter; + this.profitCalculator = profitCalculator; + printLottoResult(lottoMatchCounter, profitCalculator); + } + + public void printLottos (MyLottoMaker myLottoMaker){ + int count = myLottoMaker.getLottoCount(); + List> lottoStorage = myLottoMaker.getMyLottos(); System.out.println("\n" + count + "개를 입력했습니다."); for (int i =0; i < lottoStorage.size(); i++){ System.out.println(lottoStorage.get(i)); } } - public static void printLottoResult(Map prizeRanking, double profitRate){ + public static void printLottoResult(LottoMatchCounter lottoMatchCounter, ProfitCalculator profitCalculator){ + Map prizeRanking = lottoMatchCounter.getPrizeRanking(); + double profitRate = profitCalculator.getProfitRate(); + final int FIRST_PLACE = 6; final int SECOND_PLACE = 5; final int THIRD_PLACE = 4; @@ -31,3 +55,5 @@ public static void printLottoResult(Map prizeRanking, double p } } + + diff --git a/src/main/java/lotto/lotto/LottoComparison.java b/src/main/java/lotto/lotto/LottoComparison.java index 6c4299a2..410367c5 100644 --- a/src/main/java/lotto/lotto/LottoComparison.java +++ b/src/main/java/lotto/lotto/LottoComparison.java @@ -1,16 +1,27 @@ package lotto.lotto; import java.util.List; +import lotto.io.InputHandler; public class LottoComparison { LottoMatchCounter lottoMatchCounter; + WinLottoMaker winLottoMaker; + InputHandler inputHandler; + MyLottoMaker myLottoMaker; - public LottoComparison(LottoMatchCounter lottoMatchCounter) { + public LottoComparison(LottoMatchCounter lottoMatchCounter, MyLottoMaker myLottoMaker, WinLottoMaker winLottoMaker, InputHandler inputHandler) { this.lottoMatchCounter = lottoMatchCounter; + this.myLottoMaker = myLottoMaker; + this.winLottoMaker = winLottoMaker; + this.inputHandler = inputHandler; + compareNums(myLottoMaker, winLottoMaker, inputHandler); } - public void compareNums(List> myLottos, List winLotto, int bonusNumber) { + public void compareNums(MyLottoMaker myLottoMaker, WinLottoMaker winLottoMaker, InputHandler inputHandler) { + List> myLottos = myLottoMaker.getMyLottos(); + List winLotto = winLottoMaker.getWinLotto(); + int bonusNumber = inputHandler.getBonusNum(); for (List myLotto : myLottos) { int matchCount = countMatchingNumbers(myLotto, winLotto); boolean bonusMatch = myLotto.contains(bonusNumber); diff --git a/src/main/java/lotto/lotto/MyLottoMaker.java b/src/main/java/lotto/lotto/MyLottoMaker.java index 0a88f7e8..4863ca0b 100644 --- a/src/main/java/lotto/lotto/MyLottoMaker.java +++ b/src/main/java/lotto/lotto/MyLottoMaker.java @@ -4,26 +4,38 @@ import java.util.ArrayList; import java.util.List; import lotto.error.ErrorCheckingAndParsing; -import lotto.io.OutputHandler; +import lotto.io.InputHandler; public class MyLottoMaker { - public List> makeMyLottos(int price) { - final int MINIMUM_NUMBER = 1; - final int MAXIMUM_NUMBER = 45; - final int LOTTO_NUM_COUNT = 6; - final int LOTTO_COUNT = ErrorCheckingAndParsing.isDividedThousand(price); + int LOTTO_COUNT = 0; + final int MINIMUM_NUMBER = 1; + final int MAXIMUM_NUMBER = 45; + final int LOTTO_NUM_COUNT = 6; + List> lottoStorage = new ArrayList<>(); + InputHandler inputHandler; - List> lottoStorage = new ArrayList<>(); + public MyLottoMaker(InputHandler inputHandler) { + this.inputHandler = inputHandler; + makeMyLottos(inputHandler.getPrice()); + } + + public void makeMyLottos(int price) { + + LOTTO_COUNT = ErrorCheckingAndParsing.isDividedThousand(price); for (int i = 0; i < LOTTO_COUNT; i++) { List myLotto = Randoms.pickUniqueNumbersInRange(MINIMUM_NUMBER, MAXIMUM_NUMBER, LOTTO_NUM_COUNT); lottoStorage.add(myLotto); } + } - OutputHandler.printLottos(lottoStorage, LOTTO_COUNT); - + public List> getMyLottos() { return lottoStorage; } + public int getLottoCount(){ + return LOTTO_COUNT; + } + } diff --git a/src/main/java/lotto/lotto/ProfitCalculator.java b/src/main/java/lotto/lotto/ProfitCalculator.java index e12b59a9..bdc8e930 100644 --- a/src/main/java/lotto/lotto/ProfitCalculator.java +++ b/src/main/java/lotto/lotto/ProfitCalculator.java @@ -1,11 +1,23 @@ package lotto.lotto; import java.util.Map; -import java.util.Set; +import lotto.io.InputHandler; public class ProfitCalculator { - public double calcProfit(Map prizeRanking, int inputPrice) { + double profitRate = 0; + LottoMatchCounter lottoMatchCounter; + InputHandler inputHandler; + + public ProfitCalculator(LottoMatchCounter lottoMatchCounter, InputHandler inputHandler) { + this.lottoMatchCounter = lottoMatchCounter; + this.inputHandler = inputHandler; + calcProfit(lottoMatchCounter, inputHandler); + } + + public void calcProfit(LottoMatchCounter lottoMatchCounter, InputHandler inputHandler) { + Map prizeRanking = lottoMatchCounter.getPrizeRanking(); + int inputPrice = inputHandler.getInputPrice(); final int FIRST_PLACE = 6; final int SECOND_PLACE = 5; final int THIRD_PLACE = 4; @@ -14,8 +26,10 @@ public double calcProfit(Map prizeRanking, int inputPrice) { int totalPrize = prizeRanking.get(FIRST_PLACE) * 2000000000 + prizeRanking.get(SECOND_PLACE) * 30000000 + prizeRanking.get(THIRD_PLACE) * 1500000 + prizeRanking.get(FOURTH_PLACE) * 50000 + prizeRanking.get(FIFTH_PLACE) * 5000; - double profitRate = (double) totalPrize/ inputPrice * 100; + profitRate = (double) totalPrize/ inputPrice * 100; + } + public double getProfitRate() { return profitRate; } diff --git a/src/main/java/lotto/lotto/WinLottoMaker.java b/src/main/java/lotto/lotto/WinLottoMaker.java index 288199ed..602d1512 100644 --- a/src/main/java/lotto/lotto/WinLottoMaker.java +++ b/src/main/java/lotto/lotto/WinLottoMaker.java @@ -2,13 +2,23 @@ import java.util.List; import lotto.error.ErrorCheckingAndParsing; +import lotto.io.InputHandler; public class WinLottoMaker { - public static List makeWinLotto(String winNumbersAsString) { - String[] winNumbersAsStrings = winNumbersAsString.split(","); + String[] winNumbersAsStrings; + List winNumbers; + InputHandler inputHandler; - List winNumbers = ErrorCheckingAndParsing.isNumsAsString(winNumbersAsStrings); + public WinLottoMaker(InputHandler inputHandler) { + this.inputHandler = inputHandler; + makeWinLotto(inputHandler.getWinNums()); + } + + public List makeWinLotto(String winNumbersAsString) { + winNumbersAsStrings = winNumbersAsString.split(","); + + winNumbers = ErrorCheckingAndParsing.isNumsAsString(winNumbersAsStrings); ErrorCheckingAndParsing.isOnlySixNums(winNumbers); for (int i = 0; i < winNumbers.size(); i++) { @@ -18,4 +28,8 @@ public static List makeWinLotto(String winNumbersAsString) { return winNumbers; } + public List getWinLotto() { + return winNumbers; + } + } diff --git a/src/main/java/lotto/main/Application.java b/src/main/java/lotto/main/Application.java index 6f8939f7..585608fd 100644 --- a/src/main/java/lotto/main/Application.java +++ b/src/main/java/lotto/main/Application.java @@ -1,10 +1,24 @@ package lotto.main; +import lotto.io.InputHandler; +import lotto.io.OutputHandler; +import lotto.lotto.LottoComparison; +import lotto.lotto.LottoMatchCounter; +import lotto.lotto.MyLottoMaker; +import lotto.lotto.ProfitCalculator; +import lotto.lotto.WinLottoMaker; + public class Application { public static void main(String[] args) { - LottoStarter lottoStarter = new LottoStarter(); - lottoStarter.run(); + InputHandler inputHandler = new InputHandler(); + MyLottoMaker myLottoMaker = new MyLottoMaker(inputHandler); + new OutputHandler(inputHandler, myLottoMaker); + WinLottoMaker winLottoMaker = new WinLottoMaker(inputHandler); + LottoMatchCounter lottoMatchCounter = new LottoMatchCounter(); + new LottoComparison(lottoMatchCounter, myLottoMaker, winLottoMaker, inputHandler); + ProfitCalculator profitCalculator = new ProfitCalculator(lottoMatchCounter, inputHandler); + new OutputHandler(lottoMatchCounter, profitCalculator); } } diff --git a/src/main/java/lotto/main/LottoStarter.java b/src/main/java/lotto/main/LottoStarter.java deleted file mode 100644 index c2ecc3ea..00000000 --- a/src/main/java/lotto/main/LottoStarter.java +++ /dev/null @@ -1,40 +0,0 @@ -package lotto.main; - -import java.util.List; -import java.util.Map; -import lotto.Lotto; -import lotto.io.InputHandler; -import lotto.io.OutputHandler; -import lotto.lotto.LottoMatchCounter; -import lotto.lotto.ProfitCalculator; -import lotto.lotto.LottoComparison; -import lotto.lotto.MyLottoMaker; -import lotto.lotto.WinLottoMaker; - -public class LottoStarter { - - public void run(){ - InputHandler inputHandler = new InputHandler(); - int price = inputHandler.getPrice(); - - MyLottoMaker myLottoMaker = new MyLottoMaker(); - List> myLottos = myLottoMaker.makeMyLottos(price); - - String winNumbersAsString = inputHandler.getWinNums(); - List winLotto = WinLottoMaker.makeWinLotto(winNumbersAsString); - - int bonusNumber = inputHandler.getBonusNum(); - - LottoMatchCounter lottoMatchCounter = new LottoMatchCounter(); - LottoComparison lottoComparison = new LottoComparison(lottoMatchCounter); - lottoComparison.compareNums(myLottos, winLotto, bonusNumber); - - Map prizeRanking = lottoMatchCounter.getPrizeRanking(); - - ProfitCalculator profitCalculator = new ProfitCalculator(); - double profitRate = profitCalculator.calcProfit(prizeRanking, price); - - OutputHandler.printLottoResult(prizeRanking, profitRate); - } - -} From b8ffdaef7d4936ca023ff6a4e20f2ad04f5bd51e Mon Sep 17 00:00:00 2001 From: enohs Date: Thu, 10 Oct 2024 13:57:33 +0900 Subject: [PATCH 08/11] =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=BB=A8=EB=B2=A4?= =?UTF-8?q?=EC=85=98=EC=97=90=20=EB=A7=9E=EA=B2=8C=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=ED=95=98=EC=A7=80=20=EC=95=8A=EB=8A=94=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=EB=9D=BC=EC=9D=B8=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/io/InputHandler.java | 5 +---- src/main/java/lotto/io/OutputHandler.java | 15 ++++++++------- src/main/java/lotto/lotto/LottoComparison.java | 2 +- src/main/java/lotto/lotto/MyLottoMaker.java | 3 ++- src/main/java/lotto/lotto/WinLottoMaker.java | 4 +--- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main/java/lotto/io/InputHandler.java b/src/main/java/lotto/io/InputHandler.java index d6a90c81..edc99dff 100644 --- a/src/main/java/lotto/io/InputHandler.java +++ b/src/main/java/lotto/io/InputHandler.java @@ -6,16 +6,13 @@ public class InputHandler { int price = 0; - static Scanner scanner = new Scanner(System.in); - public int getPrice(){ + public void getPrice(){ System.out.println("구입 금액을 입력해 주세요."); String lottoPrice = scanner.nextLine(); price = ErrorCheckingAndParsing.isNum(lottoPrice); - - return price; } public int getInputPrice() { diff --git a/src/main/java/lotto/io/OutputHandler.java b/src/main/java/lotto/io/OutputHandler.java index df787d4e..3436502b 100644 --- a/src/main/java/lotto/io/OutputHandler.java +++ b/src/main/java/lotto/io/OutputHandler.java @@ -8,6 +8,11 @@ public class OutputHandler { + final int FIRST_PLACE = 6; + final int SECOND_PLACE = 5; + final int THIRD_PLACE = 4; + final int FOURTH_PLACE = 3; + final int FIFTH_PLACE = 2; MyLottoMaker myLottoMaker; InputHandler inputHandler; LottoMatchCounter lottoMatchCounter; @@ -18,6 +23,7 @@ public OutputHandler(InputHandler inputHandler, MyLottoMaker myLottoMaker){ this.inputHandler = inputHandler; printLottos(myLottoMaker); } + public OutputHandler(LottoMatchCounter lottoMatchCounter, ProfitCalculator profitCalculator){ this.lottoMatchCounter = lottoMatchCounter; @@ -34,16 +40,11 @@ public void printLottos (MyLottoMaker myLottoMaker){ } } - public static void printLottoResult(LottoMatchCounter lottoMatchCounter, ProfitCalculator profitCalculator){ + public void printLottoResult(LottoMatchCounter lottoMatchCounter, ProfitCalculator profitCalculator){ + Map prizeRanking = lottoMatchCounter.getPrizeRanking(); double profitRate = profitCalculator.getProfitRate(); - final int FIRST_PLACE = 6; - final int SECOND_PLACE = 5; - final int THIRD_PLACE = 4; - final int FOURTH_PLACE = 3; - final int FIFTH_PLACE = 2; - System.out.println("\n당첨 통계"); System.out.println("---------"); System.out.println("3개 일치 (5,000원)- " + prizeRanking.get(FIFTH_PLACE) + "개"); diff --git a/src/main/java/lotto/lotto/LottoComparison.java b/src/main/java/lotto/lotto/LottoComparison.java index 410367c5..7f02d7b8 100644 --- a/src/main/java/lotto/lotto/LottoComparison.java +++ b/src/main/java/lotto/lotto/LottoComparison.java @@ -5,6 +5,7 @@ public class LottoComparison { + int matchCount = 0; LottoMatchCounter lottoMatchCounter; WinLottoMaker winLottoMaker; InputHandler inputHandler; @@ -31,7 +32,6 @@ public void compareNums(MyLottoMaker myLottoMaker, WinLottoMaker winLottoMaker, } private int countMatchingNumbers(List myLotto, List winLotto) { - int matchCount = 0; for (int num : myLotto) { if (winLotto.contains(num)) { matchCount++; diff --git a/src/main/java/lotto/lotto/MyLottoMaker.java b/src/main/java/lotto/lotto/MyLottoMaker.java index 4863ca0b..e520e2e2 100644 --- a/src/main/java/lotto/lotto/MyLottoMaker.java +++ b/src/main/java/lotto/lotto/MyLottoMaker.java @@ -17,7 +17,8 @@ public class MyLottoMaker { public MyLottoMaker(InputHandler inputHandler) { this.inputHandler = inputHandler; - makeMyLottos(inputHandler.getPrice()); + inputHandler.getPrice(); + makeMyLottos(inputHandler.getInputPrice()); } public void makeMyLottos(int price) { diff --git a/src/main/java/lotto/lotto/WinLottoMaker.java b/src/main/java/lotto/lotto/WinLottoMaker.java index 602d1512..8fa4d5b1 100644 --- a/src/main/java/lotto/lotto/WinLottoMaker.java +++ b/src/main/java/lotto/lotto/WinLottoMaker.java @@ -15,7 +15,7 @@ public WinLottoMaker(InputHandler inputHandler) { makeWinLotto(inputHandler.getWinNums()); } - public List makeWinLotto(String winNumbersAsString) { + public void makeWinLotto(String winNumbersAsString) { winNumbersAsStrings = winNumbersAsString.split(","); winNumbers = ErrorCheckingAndParsing.isNumsAsString(winNumbersAsStrings); @@ -24,8 +24,6 @@ public List makeWinLotto(String winNumbersAsString) { for (int i = 0; i < winNumbers.size(); i++) { ErrorCheckingAndParsing.confirmNumRange(winNumbers.get(i)); } - - return winNumbers; } public List getWinLotto() { From e7bb528a7cec57169c2d39b7a4d96623349ecd30 Mon Sep 17 00:00:00 2001 From: enohs Date: Thu, 10 Oct 2024 14:45:29 +0900 Subject: [PATCH 09/11] =?UTF-8?q?matchCount=20=EC=B4=88=EA=B8=B0=ED=99=94?= =?UTF-8?q?=20=EC=95=88=EB=90=98=EB=8A=94=20=EC=98=A4=EB=A5=98=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/lotto/LottoComparison.java | 3 ++- src/main/java/lotto/main/Application.java | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/lotto/lotto/LottoComparison.java b/src/main/java/lotto/lotto/LottoComparison.java index 7f02d7b8..8fb861e4 100644 --- a/src/main/java/lotto/lotto/LottoComparison.java +++ b/src/main/java/lotto/lotto/LottoComparison.java @@ -5,7 +5,7 @@ public class LottoComparison { - int matchCount = 0; + int matchCount; LottoMatchCounter lottoMatchCounter; WinLottoMaker winLottoMaker; InputHandler inputHandler; @@ -32,6 +32,7 @@ public void compareNums(MyLottoMaker myLottoMaker, WinLottoMaker winLottoMaker, } private int countMatchingNumbers(List myLotto, List winLotto) { + matchCount = 0; for (int num : myLotto) { if (winLotto.contains(num)) { matchCount++; diff --git a/src/main/java/lotto/main/Application.java b/src/main/java/lotto/main/Application.java index 585608fd..097df575 100644 --- a/src/main/java/lotto/main/Application.java +++ b/src/main/java/lotto/main/Application.java @@ -14,9 +14,11 @@ public static void main(String[] args) { InputHandler inputHandler = new InputHandler(); MyLottoMaker myLottoMaker = new MyLottoMaker(inputHandler); new OutputHandler(inputHandler, myLottoMaker); + WinLottoMaker winLottoMaker = new WinLottoMaker(inputHandler); LottoMatchCounter lottoMatchCounter = new LottoMatchCounter(); new LottoComparison(lottoMatchCounter, myLottoMaker, winLottoMaker, inputHandler); + ProfitCalculator profitCalculator = new ProfitCalculator(lottoMatchCounter, inputHandler); new OutputHandler(lottoMatchCounter, profitCalculator); } From 3c62a49570fb1aa4d2fc209ed8ff212aba7d8f24 Mon Sep 17 00:00:00 2001 From: enohs Date: Thu, 10 Oct 2024 14:47:09 +0900 Subject: [PATCH 10/11] =?UTF-8?q?=EB=AC=B4=EC=9D=98=EB=AF=B8=ED=95=9C=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/io/OutputHandler.java | 3 +-- src/main/java/lotto/main/Application.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/lotto/io/OutputHandler.java b/src/main/java/lotto/io/OutputHandler.java index 3436502b..8106982f 100644 --- a/src/main/java/lotto/io/OutputHandler.java +++ b/src/main/java/lotto/io/OutputHandler.java @@ -18,9 +18,8 @@ public class OutputHandler { LottoMatchCounter lottoMatchCounter; ProfitCalculator profitCalculator; - public OutputHandler(InputHandler inputHandler, MyLottoMaker myLottoMaker){ + public OutputHandler(MyLottoMaker myLottoMaker){ this.myLottoMaker = myLottoMaker; - this.inputHandler = inputHandler; printLottos(myLottoMaker); } diff --git a/src/main/java/lotto/main/Application.java b/src/main/java/lotto/main/Application.java index 097df575..a00063fa 100644 --- a/src/main/java/lotto/main/Application.java +++ b/src/main/java/lotto/main/Application.java @@ -13,7 +13,7 @@ public class Application { public static void main(String[] args) { InputHandler inputHandler = new InputHandler(); MyLottoMaker myLottoMaker = new MyLottoMaker(inputHandler); - new OutputHandler(inputHandler, myLottoMaker); + new OutputHandler(myLottoMaker); WinLottoMaker winLottoMaker = new WinLottoMaker(inputHandler); LottoMatchCounter lottoMatchCounter = new LottoMatchCounter(); From 2b1aefc1bebffdf53524ec45c644a63cbe78e2b0 Mon Sep 17 00:00:00 2001 From: enohs Date: Thu, 10 Oct 2024 14:50:19 +0900 Subject: [PATCH 11/11] =?UTF-8?q?=EB=AC=B4=EC=9D=98=EB=AF=B8=ED=95=9C=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/io/OutputHandler.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/lotto/io/OutputHandler.java b/src/main/java/lotto/io/OutputHandler.java index 8106982f..d10b7592 100644 --- a/src/main/java/lotto/io/OutputHandler.java +++ b/src/main/java/lotto/io/OutputHandler.java @@ -14,7 +14,6 @@ public class OutputHandler { final int FOURTH_PLACE = 3; final int FIFTH_PLACE = 2; MyLottoMaker myLottoMaker; - InputHandler inputHandler; LottoMatchCounter lottoMatchCounter; ProfitCalculator profitCalculator;