From 958541e9c5ea99fe99c663258e8dc02ccf7c1381 Mon Sep 17 00:00:00 2001 From: nyeroni Date: Wed, 1 May 2024 21:09:12 +0900 Subject: [PATCH 1/7] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EA=B5=AC?= =?UTF-8?q?=EB=A7=A4=ED=95=A0=20=EA=B8=88=EC=95=A1=20=EC=9E=85=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/view/InputView.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/view/InputView.java diff --git a/src/main/java/view/InputView.java b/src/main/java/view/InputView.java new file mode 100644 index 00000000..dfc734d7 --- /dev/null +++ b/src/main/java/view/InputView.java @@ -0,0 +1,16 @@ +package view; + +import java.util.Scanner; + +public class InputView { + + private final static String INPUT_PRICE = "구입금액을 입력해 주세요."; + private static final Scanner scanner = new Scanner(System.in); + + + public int inputPrice(){ + System.out.println(INPUT_PRICE); + int price = scanner.nextInt(); + return price; + } +} From 86275867b87fa57c08c1e14448cba48c82018dcc Mon Sep 17 00:00:00 2001 From: nyeroni Date: Wed, 1 May 2024 21:09:20 +0900 Subject: [PATCH 2/7] =?UTF-8?q?feat:=20=EA=B5=AC=EB=A7=A4=ED=95=9C=20?= =?UTF-8?q?=EB=A1=9C=EB=98=90=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/view/OutputView.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/view/OutputView.java diff --git a/src/main/java/view/OutputView.java b/src/main/java/view/OutputView.java new file mode 100644 index 00000000..7226ff81 --- /dev/null +++ b/src/main/java/view/OutputView.java @@ -0,0 +1,16 @@ +package view; + +import java.util.List; + +public class OutputView { + + private final static String BUY_MESSAGE = "개를 구매했습니다."; + + public void countPrint (int count){ + System.out.println("\n" + count + BUY_MESSAGE); + + } + public void lottoPrint(List numbers) { + System.out.println(numbers); + } +} From c0861500d45ecdc49c4704e71b1914aeeb11111b Mon Sep 17 00:00:00 2001 From: nyeroni Date: Wed, 1 May 2024 21:09:38 +0900 Subject: [PATCH 3/7] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EB=9E=9C?= =?UTF-8?q?=EB=8D=A4=20=EB=B2=88=ED=98=B8=EB=A1=9C=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/model/AutoLotto.java | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/java/model/AutoLotto.java diff --git a/src/main/java/model/AutoLotto.java b/src/main/java/model/AutoLotto.java new file mode 100644 index 00000000..287069a6 --- /dev/null +++ b/src/main/java/model/AutoLotto.java @@ -0,0 +1,36 @@ +package model; + +import java.util.*; + +public class AutoLotto { + + private static final int MAX_LOTTO_NUMBER = 45; + private static final int CNT_LOTTO_NUMBER = 6; + + private static List lottoNums = new ArrayList<>(); + public AutoLotto(){ + createAutoLotto(); + } + public void createAutoLotto(){ + Random random = new Random(); + Set uniqueNumbers = new TreeSet<>(); // 중복되지 않는 숫자를 보장하는 TreeSet 사용 + + // 로또 번호 생성 + while (uniqueNumbers.size() < CNT_LOTTO_NUMBER) { + int num = random.nextInt(MAX_LOTTO_NUMBER) + 1; + uniqueNumbers.add(num); + } + + lottoNums = new ArrayList<>(uniqueNumbers); + + } + public List sortLotto(List lottoNums){ + List sortLottoList = new ArrayList<>(lottoNums); + sortLottoList.sort(Comparator.naturalOrder()); + return sortLottoList; + } + public List getAutoLotto(){ + return lottoNums; + } + +} From d435b8e5be50c38e5b0fd63a3015ce1987798313 Mon Sep 17 00:00:00 2001 From: nyeroni Date: Wed, 1 May 2024 21:09:47 +0900 Subject: [PATCH 4/7] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/model/Lotto.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/main/java/model/Lotto.java diff --git a/src/main/java/model/Lotto.java b/src/main/java/model/Lotto.java new file mode 100644 index 00000000..a3bd0f70 --- /dev/null +++ b/src/main/java/model/Lotto.java @@ -0,0 +1,16 @@ +package model; + +import java.util.List; + +public class Lotto { + private static final int BONUS_NUMBER_INDEX = 6; + private final List numbers; + + public Lotto(List numbers) { + this.numbers = numbers; + } + + public ListgetNumbers(){ + return numbers; + } +} From 07b7bc73f30be653d69b28c756c47c6b918a2ccc Mon Sep 17 00:00:00 2001 From: nyeroni Date: Wed, 1 May 2024 21:09:55 +0900 Subject: [PATCH 5/7] =?UTF-8?q?feat:=20=EC=B4=9D=20=EA=B5=AC=EB=A7=A4?= =?UTF-8?q?=ED=95=9C=20=EB=A1=9C=EB=98=90=EB=A5=BC=20list=EB=A1=9C=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/model/LottoList.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main/java/model/LottoList.java diff --git a/src/main/java/model/LottoList.java b/src/main/java/model/LottoList.java new file mode 100644 index 00000000..f15102d7 --- /dev/null +++ b/src/main/java/model/LottoList.java @@ -0,0 +1,22 @@ +package model; + +import java.util.ArrayList; +import java.util.List; + +public class LottoList { + List lottoList = new ArrayList<>(); + private int totalPrice; + + public LottoList(Lotto lotto){ + lottoList.add(lotto); + } + public List getLottoList(){ + return lottoList; + } + public void setTotalPrice(int reward){ + this.totalPrice+=reward; + } + public int getTotalPrice(){ + return totalPrice; + } +} From 5ed6feaceaa9578d6e696cd752abf4569c073b39 Mon Sep 17 00:00:00 2001 From: nyeroni Date: Wed, 1 May 2024 21:10:13 +0900 Subject: [PATCH 6/7] =?UTF-8?q?feat:=20=EA=B5=AC=EB=A7=A4=ED=95=A0=20?= =?UTF-8?q?=EA=B0=80=EA=B2=A9=20=EC=9E=85=EB=A0=A5=20=ED=9B=84=20=ED=95=B4?= =?UTF-8?q?=EB=8B=B9=20=EA=B0=80=EA=B2=A9=20=EB=A7=8C=ED=81=BC=20=EB=A1=9C?= =?UTF-8?q?=EB=98=90=20=EC=83=9D=EC=84=B1=20=EB=B0=8F=20=EC=B6=9C=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/controller/LottoController.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 src/main/java/controller/LottoController.java diff --git a/src/main/java/controller/LottoController.java b/src/main/java/controller/LottoController.java new file mode 100644 index 00000000..42b66c53 --- /dev/null +++ b/src/main/java/controller/LottoController.java @@ -0,0 +1,48 @@ +package controller; + +import model.AutoLotto; +import model.Lotto; +import model.LottoList; +import view.InputView; +import view.OutputView; + +import java.util.ArrayList; +import java.util.List; + +public class LottoController { + private InputView inputView = new InputView(); + private OutputView outputView = new OutputView(); + private AutoLotto autoLotto; + private LottoList lottoList; + + + public LottoController(){ + lottoStart(); + } + public void lottoStart() { + int price = inputMoney(); + viewLotto(price); + } + + public int inputMoney(){ + return inputView.inputPrice(); + } + public void viewLotto(int price){ + int count = price/1000; + outputView.countPrint(count); + lottoList = makeLottolist(count); + } + public LottoList makeLottolist(int count){ + for(int i=0; i lotto = new ArrayList<>(); + AutoLotto autoLotto = new AutoLotto(); + lotto = autoLotto.getAutoLotto(); + outputView.lottoPrint(lotto); + return new Lotto(lotto); + } +} From 2fd7c316bebae88497d7072bedf989fc67ab6148 Mon Sep 17 00:00:00 2001 From: nyeroni Date: Wed, 1 May 2024 21:10:20 +0900 Subject: [PATCH 7/7] =?UTF-8?q?feat:=20=EC=8B=A4=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Application.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/main/java/Application.java diff --git a/src/main/java/Application.java b/src/main/java/Application.java new file mode 100644 index 00000000..2588f582 --- /dev/null +++ b/src/main/java/Application.java @@ -0,0 +1,10 @@ +import controller.LottoController; + +import java.io.IOException; + +public class Application { + + public static void main(String [] args) throws IOException { + LottoController lottoController = new LottoController(); + } +}