From a7f2600567ebab0e4bb8b375c47d83ef51f11952 Mon Sep 17 00:00:00 2001 From: jermany17 Date: Wed, 2 Oct 2024 13:49:31 +0900 Subject: [PATCH 1/6] =?UTF-8?q?Lotto=EA=B0=9D=EC=B2=B4=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/domain/Lotto.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/main/java/domain/Lotto.java diff --git a/src/main/java/domain/Lotto.java b/src/main/java/domain/Lotto.java new file mode 100644 index 00000000..dc13ccf3 --- /dev/null +++ b/src/main/java/domain/Lotto.java @@ -0,0 +1,12 @@ +package domain; + +import java.util.List; + +public class Lotto { + + private List lotto; + + public Lotto(List lottoNum){ + this.lotto = lottoNum; + } +} \ No newline at end of file From 70f31d1a86e43ae735a75588ae2e11c5f28f83eb Mon Sep 17 00:00:00 2001 From: jermany17 Date: Wed, 2 Oct 2024 13:50:02 +0900 Subject: [PATCH 2/6] =?UTF-8?q?View=EA=B5=AC=ED=98=84=20-=20Input,=20Outpu?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/view/Input.java | 62 ++++++++++++++++++++++++++++++++ src/main/java/view/Output.java | 65 ++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 src/main/java/view/Input.java create mode 100644 src/main/java/view/Output.java diff --git a/src/main/java/view/Input.java b/src/main/java/view/Input.java new file mode 100644 index 00000000..24064609 --- /dev/null +++ b/src/main/java/view/Input.java @@ -0,0 +1,62 @@ +package view; + +import java.util.*; + +public class Input { + + private static Scanner scanner = new Scanner(System.in); + + public static int moneyInput(){ + System.out.println("구입금액을 입력해 주세요."); + int money = scanner.nextInt(); + System.out.println(); + return money/1000; + } + + public static int manualNumInput(){ + System.out.println("수동으로 구매할 로또 수를 입력해 주세요."); + int manual = scanner.nextInt(); + System.out.println(); + scanner.nextLine(); + return manual; + } + + public static List manualLottoInput(int n) { + if (n == 0) + System.out.println("수동으로 구매할 번호를 입력해 주세요."); + List manualLotto = Arrays.asList(scanner.nextLine().split(",")); + for(int i = 0; i < manualLotto.size(); i++){ + manualLotto.set(i, manualLotto.get(i).trim()); + } + return manualLotto; + } + + public static List AutoLottoInput() { + List lottoRange = new ArrayList<>(); + for (int i = 1; i <= 45; i++) { + lottoRange.add(String.valueOf(i)); + } + Collections.shuffle(lottoRange); + return lottoRange.subList(0, 6); + } + + public static List LastWeekLottoNum(){ + System.out.println("\n지난 주 당첨 번호를 입력해 주세요."); + List LastWeekLotto = Arrays.asList(scanner.nextLine().split(",")); + for(int i = 0; i < LastWeekLotto.size(); i++){ + LastWeekLotto.set(i, LastWeekLotto.get(i).trim()); + } + return LastWeekLotto; + } + + public static String BonusBall(){ + System.out.println("\n보너스 볼을 입력해 주세요."); + return scanner.nextLine(); + } + + public static void closeScanner() { + if (scanner != null) { + scanner.close(); + } + } +} \ No newline at end of file diff --git a/src/main/java/view/Output.java b/src/main/java/view/Output.java new file mode 100644 index 00000000..593f406b --- /dev/null +++ b/src/main/java/view/Output.java @@ -0,0 +1,65 @@ +package view; + +import java.util.*; +import domain.LottoGame; + +public class Output { + + public static void ManualAndAutoNumOutput(int manual, int auto){ + System.out.println(); + System.out.println("수동으로 " + manual + "장, 자동으로 " + auto + "개를 구매했습니다."); + } + + public static void LottoNumOutput(List Lotto){ + System.out.print("["); + for(int i = 0; i < Lotto.size(); i++){ + System.out.print(Lotto.get(i)); + if(i != Lotto.size() - 1){ + System.out.print(", "); + } + } + System.out.println("]"); + } + + public static void ResultOfLotto(List> LottoList, List LastWeekLotto, String BonusBall, int moneyInput){ + int result3 = 0, result4 = 0, result5 = 0, result6 = 0, result5Bonus = 0; + int matchNum = 0, matchBonus = 0; + int resultMoney = 0; + double rate = 0; + + for (List Lotto : LottoList) { + matchNum = LottoGame.matchNum(Lotto, LastWeekLotto); + matchBonus = LottoGame.matchBonus(Lotto, BonusBall); + if (matchNum == 3) { + result3++; + resultMoney += 5000; + } + if (matchNum == 4) { + result4++; + resultMoney += 50000; + } + if (matchNum == 5 && matchBonus == 0) { + result5++; + resultMoney += 1500000; + } + if (matchNum == 5 && matchBonus == 1) { + result5Bonus++; + resultMoney += 30000000; + } + if (matchNum == 6) { + result6++; + resultMoney += 2000000000; + } + } + + System.out.println("\n당첨 통계"); + System.out.println("---------"); + System.out.println("3개 일치 (5000원)- " + result3 + "개"); + System.out.println("4개 일치 (50000원)- " + result4 + "개"); + System.out.println("5개 일치 (1500000원)- " + result5 + "개"); + System.out.println("5개 일치, 보너스 볼 일치(30000000)원 - " + result5Bonus + "개"); + System.out.println("6개 일치 (2000000000원)-" + result6 + "개"); + rate = (double) resultMoney / moneyInput; + System.out.println("총 수익률은 " + String.format("%.2f", rate) + "입니다."); + } +} From c4dc932804c9a3a03c73f3355f6a215fa3e3d98d Mon Sep 17 00:00:00 2001 From: jermany17 Date: Wed, 2 Oct 2024 13:50:39 +0900 Subject: [PATCH 3/6] =?UTF-8?q?Domain=20-=20LottoGame=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/domain/LottoGame.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/main/java/domain/LottoGame.java diff --git a/src/main/java/domain/LottoGame.java b/src/main/java/domain/LottoGame.java new file mode 100644 index 00000000..63b796d0 --- /dev/null +++ b/src/main/java/domain/LottoGame.java @@ -0,0 +1,25 @@ +package domain; + +import java.util.List; + +public class LottoGame { + + public static int matchNum(List Lotto, List LastWeekLotto){ + int matchNum = 0; + for (String n : Lotto) { + if (LastWeekLotto.contains(n)) { + matchNum++; + } + } + return matchNum; + } + + public static int matchBonus(List Lotto, String BonusBall){ + for (String n : Lotto) { + if (n.equals(BonusBall)) { + return 1; + } + } + return 0; + } +} From d9a425e62698a0bc521dc8910290bc762acd1b2c Mon Sep 17 00:00:00 2001 From: jermany17 Date: Wed, 2 Oct 2024 13:50:57 +0900 Subject: [PATCH 4/6] =?UTF-8?q?Controller=20-=20App=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/controller/App.java | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/main/java/controller/App.java diff --git a/src/main/java/controller/App.java b/src/main/java/controller/App.java new file mode 100644 index 00000000..58efe9bd --- /dev/null +++ b/src/main/java/controller/App.java @@ -0,0 +1,49 @@ +package controller; + +import java.util.*; +import view.Input; +import view.Output; + +public class App { + public static void main(String[] args) { + + // 모든 로또들을 넣을 리스트 + List> LottoList = new ArrayList<>(); + + // 구입 금액 입력한다 + int total = Input.moneyInput(); + + // 수동으로 구매할 로또 수를 입력한다 + int manual = Input.manualNumInput(); + + // 자동으로 구매할 로또 수를 계산한다. + int auto = total - manual; + + // 수동 로또 번호를 입력한다 + for(int i = 0; i < manual; i++) { + List manualLotto = Input.manualLottoInput(i); + LottoList.add(manualLotto); + } + + // 수동과 자동 구매 개수를 출력한다 + Output.ManualAndAutoNumOutput(manual, auto); + + // 자동 로또 번호를 생성 및 출력한다 + for (int i = 0; i < auto; i++) { + List autoLotto = Input.AutoLottoInput(); + Collections.sort(autoLotto); + LottoList.add(autoLotto); + Output.LottoNumOutput(autoLotto); + } + + // 지난 주 당첨 번호를 입력한다 + List LastWeekLotto = Input.LastWeekLottoNum(); + + // 보너스 볼을 입력한다 + String BonusBall = Input.BonusBall(); + + // 당첨 통계를 출력한다 + Output.ResultOfLotto(LottoList, LastWeekLotto, BonusBall, total*1000); + Input.closeScanner(); + } +} \ No newline at end of file From 4c785cf86b0aa429b1df2326d086ea69321790cf Mon Sep 17 00:00:00 2001 From: jermany17 Date: Wed, 2 Oct 2024 13:51:03 +0900 Subject: [PATCH 5/6] =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/LottoTest.java | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/test/java/LottoTest.java diff --git a/src/test/java/LottoTest.java b/src/test/java/LottoTest.java new file mode 100644 index 00000000..571ef400 --- /dev/null +++ b/src/test/java/LottoTest.java @@ -0,0 +1,54 @@ +import domain.LottoGame; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.Arrays; +import java.util.List; + +public class LottoTest { + + @Test + @DisplayName("로또번호_6개_일치여부를_확인한다") + public void 로또번호_6개_일치여부를_확인한다() { + List lotto = Arrays.asList("1", "2", "3", "4", "5", "6"); + List lastWeekLotto = Arrays.asList("6", "5", "4", "3", "2", "1"); + int result = LottoGame.matchNum(lotto, lastWeekLotto); + assertEquals(6, result); + } + + @Test + @DisplayName("로또번호_3개_일치여부를_확인한다") + public void 로또번호_3개_일치여부를_확인한다() { + List lotto = Arrays.asList("1", "2", "3", "4", "5", "6"); + List lastWeekLotto = Arrays.asList("10", "9", "8", "3", "2", "1"); + int result = LottoGame.matchNum(lotto, lastWeekLotto); + assertEquals(3, result); + } + + @Test + @DisplayName("로또번호_0개_일치여부를_확인한다") + public void 로또번호_0개_일치여부를_확인한다() { + List lotto = Arrays.asList("1", "2", "3", "4", "5", "6"); + List lastWeekLotto = Arrays.asList("7", "8", "9", "10", "11", "12"); + int result = LottoGame.matchNum(lotto, lastWeekLotto); + assertEquals(0, result); + } + + @Test + @DisplayName("보너스번호_일치여부를_확인한다") + public void 보너스번호_일치여부를_확인한다() { + List lotto = Arrays.asList("1", "2", "3", "4", "5", "7"); + String bonusBall = "7"; + int result = LottoGame.matchBonus(lotto, bonusBall); + assertEquals(1, result); // 보너스볼이 일치함 + } + + @Test + @DisplayName("보너스번호_불일치여부를_확인한다") + public void 보너스번호_불일치여부를_확인한다() { + List lotto = Arrays.asList("1", "2", "3", "4", "5", "7"); + String bonusBall = "8"; + int result = LottoGame.matchBonus(lotto, bonusBall); + assertEquals(0, result); // 보너스볼이 일치하지 않음 + } +} \ No newline at end of file From dc79dc62eff76b52661872eecccdc38294d5a3d6 Mon Sep 17 00:00:00 2001 From: jermany17 Date: Wed, 2 Oct 2024 14:03:53 +0900 Subject: [PATCH 6/6] =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EB=A7=88=EC=A7=80?= =?UTF-8?q?=EB=A7=89=20=EA=B0=9C=ED=96=89=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/controller/App.java | 2 +- src/main/java/domain/Lotto.java | 2 +- src/main/java/domain/LottoGame.java | 1 + src/main/java/view/Input.java | 2 +- src/test/java/LottoTest.java | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/controller/App.java b/src/main/java/controller/App.java index 58efe9bd..7cc44ab9 100644 --- a/src/main/java/controller/App.java +++ b/src/main/java/controller/App.java @@ -46,4 +46,4 @@ public static void main(String[] args) { Output.ResultOfLotto(LottoList, LastWeekLotto, BonusBall, total*1000); Input.closeScanner(); } -} \ No newline at end of file +} diff --git a/src/main/java/domain/Lotto.java b/src/main/java/domain/Lotto.java index dc13ccf3..70284f11 100644 --- a/src/main/java/domain/Lotto.java +++ b/src/main/java/domain/Lotto.java @@ -9,4 +9,4 @@ public class Lotto { public Lotto(List lottoNum){ this.lotto = lottoNum; } -} \ No newline at end of file +} diff --git a/src/main/java/domain/LottoGame.java b/src/main/java/domain/LottoGame.java index 63b796d0..690b3f06 100644 --- a/src/main/java/domain/LottoGame.java +++ b/src/main/java/domain/LottoGame.java @@ -23,3 +23,4 @@ public static int matchBonus(List Lotto, String BonusBall){ return 0; } } + diff --git a/src/main/java/view/Input.java b/src/main/java/view/Input.java index 24064609..ee5637dd 100644 --- a/src/main/java/view/Input.java +++ b/src/main/java/view/Input.java @@ -59,4 +59,4 @@ public static void closeScanner() { scanner.close(); } } -} \ No newline at end of file +} diff --git a/src/test/java/LottoTest.java b/src/test/java/LottoTest.java index 571ef400..0d4f4390 100644 --- a/src/test/java/LottoTest.java +++ b/src/test/java/LottoTest.java @@ -51,4 +51,4 @@ public class LottoTest { int result = LottoGame.matchBonus(lotto, bonusBall); assertEquals(0, result); // 보너스볼이 일치하지 않음 } -} \ No newline at end of file +}