From 0f10b2e91eeab2bb59678ad30d9508f283536aa1 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Sun, 29 Sep 2024 18:23:18 +0900 Subject: [PATCH 01/46] =?UTF-8?q?feat:=20Appconfig=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/lotto/AppConfig.java | 36 ++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/main/java/lotto/AppConfig.java diff --git a/src/main/java/lotto/AppConfig.java b/src/main/java/lotto/AppConfig.java new file mode 100644 index 00000000..597c142d --- /dev/null +++ b/src/main/java/lotto/AppConfig.java @@ -0,0 +1,36 @@ +package lotto; + +import lotto.controller.LottoController; +import lotto.repository.LottoRepository; +import lotto.repository.LottoRepositoryImpl; +import lotto.service.LottoService; +import lotto.service.LottoServiceImpl; +import lotto.view.InputView; +import lotto.view.OutputView; + +import java.security.Provider; + +public class AppConfig { + + public InputView inputView() { + return new InputView(); + } + + public OutputView outputView() { + return new OutputView(); + } + + // LottoRepository 인스턴스를 생성하는 메서드 + public LottoRepository lottoRepository() { + return new LottoRepositoryImpl(); + } + + public LottoService lottoService() { + return new LottoServiceImpl(lottoRepository()); + } + + public LottoController lottoController() { + return new LottoController(lottoService(), inputView(), outputView()); + } + +} From 0f3bff693de75c006718605daecdef2ed107a1d7 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Sun, 29 Sep 2024 18:27:02 +0900 Subject: [PATCH 02/46] =?UTF-8?q?feat:=20Controller=EC=97=90=20=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=A3=BC?= =?UTF-8?q?=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lotto/controller/LottoController.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/main/java/lotto/controller/LottoController.java diff --git a/src/main/java/lotto/controller/LottoController.java b/src/main/java/lotto/controller/LottoController.java new file mode 100644 index 00000000..004f2abd --- /dev/null +++ b/src/main/java/lotto/controller/LottoController.java @@ -0,0 +1,24 @@ +package lotto.controller; + +import lotto.service.LottoService; +import lotto.view.InputView; +import lotto.view.OutputView; + +public class LottoController { + + private final LottoService lottoService; + private final InputView inputView; + private final OutputView outputView; + + public LottoController(LottoService lottoService, InputView inputView, OutputView outputView) { + this.lottoService = lottoService; + this.inputView = inputView; + this.outputView = outputView; + } + + + public void run() { + + } +} + From aad9909e4e67aeb64cedadbf7f7e2ec1cfff7725 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Sun, 29 Sep 2024 19:07:20 +0900 Subject: [PATCH 03/46] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EA=B5=AC?= =?UTF-8?q?=EB=A7=A4=20=EB=A9=94=EC=86=8C=EB=93=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/lotto/service/LottoService.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 src/main/java/lotto/service/LottoService.java diff --git a/src/main/java/lotto/service/LottoService.java b/src/main/java/lotto/service/LottoService.java new file mode 100644 index 00000000..cbb378ac --- /dev/null +++ b/src/main/java/lotto/service/LottoService.java @@ -0,0 +1,10 @@ +package lotto.service; + +import lotto.model.Lotto; + +import java.util.List; + +public interface LottoService { + List purchaseLotto(int amount); + +} From 0ab6887ec51f33fb631da3c708eab04a8ea5d55c Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Sun, 29 Sep 2024 19:08:21 +0900 Subject: [PATCH 04/46] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EA=B5=AC?= =?UTF-8?q?=EB=A7=A4=20=EA=B0=AF=EC=88=98=20=ED=8C=8C=EC=95=85,=20reposito?= =?UTF-8?q?ry=20=EC=A0=80=EC=9E=A5=20=EA=B8=B0=EB=8A=A5=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 --- .../java/lotto/service/LottoServiceImpl.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/main/java/lotto/service/LottoServiceImpl.java diff --git a/src/main/java/lotto/service/LottoServiceImpl.java b/src/main/java/lotto/service/LottoServiceImpl.java new file mode 100644 index 00000000..cdee3076 --- /dev/null +++ b/src/main/java/lotto/service/LottoServiceImpl.java @@ -0,0 +1,29 @@ +package lotto.service; +import lotto.model.Lotto; +import lotto.repository.LottoRepository; +import java.util.ArrayList; +import java.util.List; + +public class LottoServiceImpl implements LottoService { + + private final LottoRepository lottoRepository; + + public LottoServiceImpl(LottoRepository lottoRepository) { + this.lottoRepository = lottoRepository; + } + + @Override + public List purchaseLotto(int amount) { + int numberOfLotto = amount / 1000; + List purchasedLotto = new ArrayList<>(); + for (int i = 0; i < numberOfLotto; i++) { + Lotto lotto = lottoRepository.createLotto(); + purchasedLotto.add(lotto); + } + return purchasedLotto; + } + + + + +} From c1db8c3f02d0e84dd64f6ff93b5dcbee0f485282 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Sun, 29 Sep 2024 19:24:46 +0900 Subject: [PATCH 05/46] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5,=20=EC=A0=80=EC=9E=A5=EB=90=9C=20=EB=A1=9C=EB=98=90?= =?UTF-8?q?=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=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/lotto/repository/LottoRepository.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/main/java/lotto/repository/LottoRepository.java diff --git a/src/main/java/lotto/repository/LottoRepository.java b/src/main/java/lotto/repository/LottoRepository.java new file mode 100644 index 00000000..aff26ed8 --- /dev/null +++ b/src/main/java/lotto/repository/LottoRepository.java @@ -0,0 +1,9 @@ +package lotto.repository; + +import lotto.model.Lotto; +import java.util.List; + +public interface LottoRepository { + void saveLotto(Lotto lotto); + List findAllLotto(); +} \ No newline at end of file From 01e6b202e063f02bf07b1ca4e107d6a5e01e8ade Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Sun, 29 Sep 2024 19:25:41 +0900 Subject: [PATCH 06/46] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5,=20=EB=B0=98=ED=99=98=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lotto/repository/LottoRepositoryImpl.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/lotto/repository/LottoRepositoryImpl.java diff --git a/src/main/java/lotto/repository/LottoRepositoryImpl.java b/src/main/java/lotto/repository/LottoRepositoryImpl.java new file mode 100644 index 00000000..38275d5c --- /dev/null +++ b/src/main/java/lotto/repository/LottoRepositoryImpl.java @@ -0,0 +1,20 @@ +package lotto.repository; + +import lotto.model.Lotto; +import java.util.ArrayList; +import java.util.List; + +public class LottoRepositoryImpl implements LottoRepository { + + private final List lottoStorage = new ArrayList<>(); + + @Override + public void saveLotto(Lotto lotto) { + lottoStorage.add(lotto); + } + + @Override + public List findAllLotto() { + return new ArrayList<>(lottoStorage); + } +} From 1732633aa2309312897ada86f5e3758c794ac6f7 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Sun, 29 Sep 2024 19:46:26 +0900 Subject: [PATCH 07/46] =?UTF-8?q?feat:=20=EB=9E=9C=EB=8D=A4=20=EB=A1=9C?= =?UTF-8?q?=EB=98=90=EB=B2=88=ED=98=B8=20=EC=83=9D=EC=84=B1=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/main/java/lotto/service/LottoServiceImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/lotto/service/LottoServiceImpl.java b/src/main/java/lotto/service/LottoServiceImpl.java index cdee3076..5e7dc854 100644 --- a/src/main/java/lotto/service/LottoServiceImpl.java +++ b/src/main/java/lotto/service/LottoServiceImpl.java @@ -1,4 +1,5 @@ package lotto.service; +import camp.nextstep.edu.missionutils.Randoms; import lotto.model.Lotto; import lotto.repository.LottoRepository; import java.util.ArrayList; @@ -16,14 +17,13 @@ public LottoServiceImpl(LottoRepository lottoRepository) { public List purchaseLotto(int amount) { int numberOfLotto = amount / 1000; List purchasedLotto = new ArrayList<>(); + for (int i = 0; i < numberOfLotto; i++) { - Lotto lotto = lottoRepository.createLotto(); + List lottoNumbers = Randoms.pickUniqueNumbersInRange(1, 45, 6); + Lotto lotto = new Lotto(lottoNumbers); purchasedLotto.add(lotto); } return purchasedLotto; } - - - } From 101765efb6634b9e07b2712fec962ed7cce2f48c Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Sat, 5 Oct 2024 18:08:05 +0900 Subject: [PATCH 08/46] =?UTF-8?q?feat:=20=EB=8B=B9=EC=B2=A8=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20+=20=EB=B3=B4=EB=84=88=EC=8A=A4=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=9E=85=EB=A0=A5=20=EB=B0=9B=EB=8A=94=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=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/lotto/view/InputView.java | 41 +++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/main/java/lotto/view/InputView.java diff --git a/src/main/java/lotto/view/InputView.java b/src/main/java/lotto/view/InputView.java new file mode 100644 index 00000000..6c1bc31f --- /dev/null +++ b/src/main/java/lotto/view/InputView.java @@ -0,0 +1,41 @@ +package lotto.view; + +import camp.nextstep.edu.missionutils.Console; +import java.util.ArrayList; +import java.util.List; + +public class InputView { + + private static List winningNumberList; + + public static int inputPlayerPrice() { + return Integer.parseInt(Console.readLine()); + } + + public static List inputLottoWinningNum() { + return numberList(Console.readLine()); + } + + public static int inputBonusNumber() { + return Integer.parseInt(Console.readLine()); + } + + //for문 서비스 쪽으로 옮겨야 함 + public static List numberList(String winningNumber) { + String[] result = winningNumber.split(","); + winningNumberList = new ArrayList<>(); + for (int i = 0; i < result.length; i++) { + winningNumberList.add(conventToInt(result[i])); + } + return winningNumberList; + } + + private static int conventToInt(String inputNumber) { + try { + return Integer.parseInt(inputNumber); + } catch (NumberFormatException e) { + throw new IllegalArgumentException(); + } + } + +} From 66b3cc4dd2ee1d7b465dd51e193b6fbbf57e0c2f Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Sat, 5 Oct 2024 18:09:09 +0900 Subject: [PATCH 09/46] =?UTF-8?q?feat:=20=EB=8B=B9=EC=B2=A8=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20+=20=EB=B3=B4=EB=84=88=EC=8A=A4=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=9E=85=EB=A0=A5=20=EB=B0=9B=EB=8A=94=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=EB=AC=B8=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/view/OutputView.java | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/main/java/lotto/view/OutputView.java diff --git a/src/main/java/lotto/view/OutputView.java b/src/main/java/lotto/view/OutputView.java new file mode 100644 index 00000000..34581dc4 --- /dev/null +++ b/src/main/java/lotto/view/OutputView.java @@ -0,0 +1,43 @@ +package lotto.view; + +public class OutputView { + private static final String TICKET_COUNT = "개를 구매했습니다."; + private static final String INPUT_LOTTO_PRICE = "구입금액을 입력해 주세요."; + private static final String INPUT_LOTTO_WINNING = "당첨 번호를 입력해 주세요."; + private static final String INPUT_BONUS_NUMBER = "보너스 번호를 입력해 주세요."; + private static final String ERROR_MESSAGE = "로또 번호를 6개 입력해 주세요."; + + + public static void printTicketCount(int count) { + System.out.println(count + TICKET_COUNT); + } + + public static void printSuccessMessage(String message, int numberOfMatch) { + System.out.println(message + numberOfMatch + "개"); + } + + public static void printInputLottoPriceMessage() { + System.out.println(INPUT_LOTTO_PRICE); + } + + public static void printSuccessResult() { + System.out.println("당첨 통계"); + System.out.println("---"); + } + + public static void printInputLottoWinningMessage() { + System.out.println(INPUT_LOTTO_WINNING); + } + + public static void printInputBonusNumberMessage() { + System.out.println(INPUT_BONUS_NUMBER); + } + + public static void printErrorMessage() { + System.out.println(ERROR_MESSAGE); + } + + public static void printRevenueRate(double EarningRate) { + System.out.println("총 수익률은 " + String.format("%.1f", EarningRate) + "%입니다."); + } +} From 0a4199768d64bf36d09ba3c123fc11a923827a40 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Sat, 5 Oct 2024 18:16:47 +0900 Subject: [PATCH 10/46] =?UTF-8?q?feat:=20=EB=8B=B9=EC=B2=A8=20=EB=A1=9C?= =?UTF-8?q?=EB=98=90=EB=B2=88=ED=98=B8=20=EC=9E=85=EB=A0=A5=20=EB=B0=8F=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=20=EB=A9=94=EC=86=8C=EB=93=9C=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lotto/service/LottoServiceImpl.java | 43 ++++++++++++++----- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/src/main/java/lotto/service/LottoServiceImpl.java b/src/main/java/lotto/service/LottoServiceImpl.java index 5e7dc854..4ab854bf 100644 --- a/src/main/java/lotto/service/LottoServiceImpl.java +++ b/src/main/java/lotto/service/LottoServiceImpl.java @@ -1,29 +1,50 @@ package lotto.service; -import camp.nextstep.edu.missionutils.Randoms; + import lotto.model.Lotto; +import lotto.model.WinningNumbers; import lotto.repository.LottoRepository; -import java.util.ArrayList; +import lotto.view.InputView; +import lotto.view.OutputView; + import java.util.List; +import java.util.stream.IntStream; public class LottoServiceImpl implements LottoService { private final LottoRepository lottoRepository; + private static final int LOOTO_AMOUNT = 1000; public LottoServiceImpl(LottoRepository lottoRepository) { this.lottoRepository = lottoRepository; } @Override - public List purchaseLotto(int amount) { - int numberOfLotto = amount / 1000; - List purchasedLotto = new ArrayList<>(); - - for (int i = 0; i < numberOfLotto; i++) { - List lottoNumbers = Randoms.pickUniqueNumbersInRange(1, 45, 6); - Lotto lotto = new Lotto(lottoNumbers); - purchasedLotto.add(lotto); + public void purchaseLottos(int amount) { + int numberOfLotto = amount / LOOTO_AMOUNT; + + IntStream.range(0, numberOfLotto).forEach(i -> { + Lotto lotto = Lotto.createRandomLotto(); // Lotto도메인에서 팩토리 메소드 호출 + saveLottoNums(lotto); + }); + } + + @Override + public void inputWinningNumbers(List winningNumbers, int bonusNumber) { + try { + WinningNumbers winningNumbersObj = new WinningNumbers(winningNumbers, bonusNumber); + lottoRepository.saveWinningNumbers(winningNumbersObj); + } catch (IllegalArgumentException e) { + OutputView.printErrorMessage(); } - return purchasedLotto; + } + + @Override + public void saveWinningNumbers(WinningNumbers winningNumbers) { + lottoRepository.saveWinningNumbers(winningNumbers); + } + + public void saveLottoNums(Lotto lotto){ + lottoRepository.saveLotto(lotto); } } From b3f12088397cd260d273da49033d5101785bb7c4 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Sat, 5 Oct 2024 18:17:42 +0900 Subject: [PATCH 11/46] =?UTF-8?q?feat:=20=EB=8B=B9=EC=B2=A8=20=EB=A1=9C?= =?UTF-8?q?=EB=98=90=EB=B2=88=ED=98=B8=20=EC=A0=80=EC=9E=A5=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=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/lotto/repository/LottoRepository.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/lotto/repository/LottoRepository.java b/src/main/java/lotto/repository/LottoRepository.java index aff26ed8..c0aead7e 100644 --- a/src/main/java/lotto/repository/LottoRepository.java +++ b/src/main/java/lotto/repository/LottoRepository.java @@ -1,9 +1,15 @@ package lotto.repository; import lotto.model.Lotto; +import lotto.model.WinningNumbers; import java.util.List; public interface LottoRepository { void saveLotto(Lotto lotto); + List findAllLotto(); -} \ No newline at end of file + + void saveWinningNumbers(WinningNumbers winningNumbers); + +// WinningNumbers findWinningNumbers(); +} From 6acfb65bcd6035e9c1beae26675ea8bfe2f15a23 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Sat, 5 Oct 2024 18:18:20 +0900 Subject: [PATCH 12/46] =?UTF-8?q?feat:=20=EB=9E=9C=EB=8D=A4=20=EB=A1=9C?= =?UTF-8?q?=EB=98=90=20=EB=B2=88=ED=98=B8=20=EC=A0=80=EC=9E=A5=EC=86=8C?= =?UTF-8?q?=EC=99=80=20=EB=8B=B9=EC=B2=A8=20=EB=B2=88=ED=98=B8=20=EC=A0=80?= =?UTF-8?q?=EC=9E=A5=EC=86=8C=EB=A5=BC=20=EB=B6=84=EB=A6=AC=ED=95=98?= =?UTF-8?q?=EC=97=AC=20=EC=A0=80=EC=9E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lotto/repository/LottoRepositoryImpl.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/lotto/repository/LottoRepositoryImpl.java b/src/main/java/lotto/repository/LottoRepositoryImpl.java index 38275d5c..3537f51d 100644 --- a/src/main/java/lotto/repository/LottoRepositoryImpl.java +++ b/src/main/java/lotto/repository/LottoRepositoryImpl.java @@ -1,12 +1,14 @@ package lotto.repository; import lotto.model.Lotto; +import lotto.model.WinningNumbers; import java.util.ArrayList; import java.util.List; public class LottoRepositoryImpl implements LottoRepository { - private final List lottoStorage = new ArrayList<>(); + private static final List lottoStorage = new ArrayList<>(); + private static final List winningNumbersStorage = new ArrayList<>(); @Override public void saveLotto(Lotto lotto) { @@ -17,4 +19,10 @@ public void saveLotto(Lotto lotto) { public List findAllLotto() { return new ArrayList<>(lottoStorage); } + + @Override + public void saveWinningNumbers(WinningNumbers winningNumbers) { + winningNumbersStorage.add(winningNumbers); // 당첨 번호 저장 + } + } From f9f43d7f41095ca98ae8e6cb97a6db31d11c7382 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Sat, 5 Oct 2024 18:18:52 +0900 Subject: [PATCH 13/46] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EB=8B=B9?= =?UTF-8?q?=EC=B2=A8=EB=B2=88=ED=98=B8=20=EB=A9=94=EC=86=8C=EB=93=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/lotto/service/LottoService.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/lotto/service/LottoService.java b/src/main/java/lotto/service/LottoService.java index cbb378ac..3653dbeb 100644 --- a/src/main/java/lotto/service/LottoService.java +++ b/src/main/java/lotto/service/LottoService.java @@ -1,10 +1,17 @@ package lotto.service; import lotto.model.Lotto; +import lotto.model.WinningNumbers; import java.util.List; public interface LottoService { - List purchaseLotto(int amount); + void purchaseLottos(int amount); + + void saveLottoNums(Lotto lottoNums); + + void inputWinningNumbers(List winningNumbers, int bonusNumber); + + void saveWinningNumbers(WinningNumbers winningNumbers); } From 3e916f3c803af86e2ce7efd09e7fde1fe6afc15a Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Sat, 5 Oct 2024 18:21:08 +0900 Subject: [PATCH 14/46] =?UTF-8?q?feat:=20=EB=8B=B9=EC=B2=A8=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=9E=85=EB=A0=A5=20=EB=B0=9B=EC=9D=84=20=EC=88=98?= =?UTF-8?q?=20=EC=9E=88=EB=8F=84=EB=A1=9D=20=EC=84=9C=EB=B9=84=EC=8A=A4?= =?UTF-8?q?=EC=99=80=20=EC=97=B0=EA=B2=B0,=20=EA=B0=81=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=EB=90=98=EC=96=B4=EC=95=BC=20=ED=95=98=EB=8A=94=20?= =?UTF-8?q?=EB=A9=94=EC=8B=9C=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lotto/controller/LottoController.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/lotto/controller/LottoController.java b/src/main/java/lotto/controller/LottoController.java index 004f2abd..b4a5dd94 100644 --- a/src/main/java/lotto/controller/LottoController.java +++ b/src/main/java/lotto/controller/LottoController.java @@ -3,6 +3,9 @@ import lotto.service.LottoService; import lotto.view.InputView; import lotto.view.OutputView; +import static lotto.view.InputView.inputBonusNumber; +import java.util.List; + public class LottoController { @@ -16,9 +19,28 @@ public LottoController(LottoService lottoService, InputView inputView, OutputVie this.outputView = outputView; } - public void run() { + purchaseLottos(); + + inputWinningNumbers(); + } + + private void purchaseLottos() { + outputView.printInputLottoPriceMessage(); + int amount = inputView.inputPlayerPrice(); + lottoService.purchaseLottos(amount); } + + private void inputWinningNumbers() { + outputView.printInputLottoWinningMessage(); + List winningNumbers = inputView.inputLottoWinningNum(); + + outputView.printInputBonusNumberMessage(); + int bonusNumber = inputBonusNumber(); + + lottoService.inputWinningNumbers(winningNumbers, bonusNumber); + } + } From 37e1ece336c3979b33f6ae0acad1f84aee78a897 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Sat, 5 Oct 2024 19:12:16 +0900 Subject: [PATCH 15/46] =?UTF-8?q?feat:=20=EC=98=88=EC=99=B8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EB=AC=B8=EA=B5=AC=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/controller/LottoController.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/lotto/controller/LottoController.java b/src/main/java/lotto/controller/LottoController.java index b4a5dd94..a9a974ed 100644 --- a/src/main/java/lotto/controller/LottoController.java +++ b/src/main/java/lotto/controller/LottoController.java @@ -1,5 +1,6 @@ package lotto.controller; +import lotto.model.Lotto; import lotto.service.LottoService; import lotto.view.InputView; import lotto.view.OutputView; @@ -29,6 +30,7 @@ public void run() { private void purchaseLottos() { outputView.printInputLottoPriceMessage(); int amount = inputView.inputPlayerPrice(); + Lotto.validatePurchaseAmount(amount); //유효성 검사 lottoService.purchaseLottos(amount); } From 37285df55e164acf773c357bf7f3be4893d193f8 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Sat, 5 Oct 2024 19:12:29 +0900 Subject: [PATCH 16/46] =?UTF-8?q?feat:=20=EC=98=88=EC=99=B8=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=20=EB=AC=B8=EA=B5=AC=20=EC=B6=94=EA=B0=80=20outputvew?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/view/OutputView.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/lotto/view/OutputView.java b/src/main/java/lotto/view/OutputView.java index 34581dc4..0af07fc5 100644 --- a/src/main/java/lotto/view/OutputView.java +++ b/src/main/java/lotto/view/OutputView.java @@ -5,8 +5,8 @@ public class OutputView { private static final String INPUT_LOTTO_PRICE = "구입금액을 입력해 주세요."; private static final String INPUT_LOTTO_WINNING = "당첨 번호를 입력해 주세요."; private static final String INPUT_BONUS_NUMBER = "보너스 번호를 입력해 주세요."; - private static final String ERROR_MESSAGE = "로또 번호를 6개 입력해 주세요."; - + private static final String ERROR_MESSAGE = "[ERROR] 로또 번호를 6개 입력해 주세요."; + private static final String ERROR_INVALID_NUMBER = "[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다."; public static void printTicketCount(int count) { System.out.println(count + TICKET_COUNT); @@ -37,6 +37,10 @@ public static void printErrorMessage() { System.out.println(ERROR_MESSAGE); } + public static void printErrorMessageInvalidNumber() { + System.out.println(ERROR_INVALID_NUMBER); + } + public static void printRevenueRate(double EarningRate) { System.out.println("총 수익률은 " + String.format("%.1f", EarningRate) + "%입니다."); } From ed4118bb0525c24ccaaef79f862bbe219930ad5a Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Sun, 6 Oct 2024 17:13:53 +0900 Subject: [PATCH 17/46] =?UTF-8?q?feat:=20=EA=B8=88=EC=95=A1=20=EC=9E=98?= =?UTF-8?q?=EB=AA=BB=20=EB=84=A3=EC=97=88=EC=9D=84=20=EB=95=8C=20=EB=AC=B8?= =?UTF-8?q?=EA=B5=AC=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/view/OutputView.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/lotto/view/OutputView.java b/src/main/java/lotto/view/OutputView.java index 0af07fc5..9e32702f 100644 --- a/src/main/java/lotto/view/OutputView.java +++ b/src/main/java/lotto/view/OutputView.java @@ -5,6 +5,8 @@ public class OutputView { private static final String INPUT_LOTTO_PRICE = "구입금액을 입력해 주세요."; private static final String INPUT_LOTTO_WINNING = "당첨 번호를 입력해 주세요."; private static final String INPUT_BONUS_NUMBER = "보너스 번호를 입력해 주세요."; + private static final String ERROR_MINIMUM_PURCHASE_AMOUNT = "[ERROR] 구입 금액은 최소 1,000원이 필요합니다."; + private static final String ERROR_INVALID_PURCHASE_AMOUNT = "[ERROR] 구입 금액은 1,000원 단위로 입력해야 합니다."; private static final String ERROR_MESSAGE = "[ERROR] 로또 번호를 6개 입력해 주세요."; private static final String ERROR_INVALID_NUMBER = "[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다."; @@ -31,6 +33,15 @@ public static void printInputLottoWinningMessage() { public static void printInputBonusNumberMessage() { System.out.println(INPUT_BONUS_NUMBER); + + } + + public static void printMinimumPurchaseMessage() { + System.out.println(ERROR_MINIMUM_PURCHASE_AMOUNT); + } + + public static void printInvalidPurchaseMessage() { + System.out.println(ERROR_INVALID_PURCHASE_AMOUNT); } public static void printErrorMessage() { From 794e95a21f55b7ff95baab2691f50863877723da Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Sun, 6 Oct 2024 17:15:32 +0900 Subject: [PATCH 18/46] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EA=B8=88?= =?UTF-8?q?=EC=95=A1=20=EC=9E=98=EB=AA=BB=20=EB=84=A3=EC=97=88=EC=9D=84=20?= =?UTF-8?q?=EB=95=8C=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=B0=8F=20=EB=8B=B9=EC=B2=A8=20=EB=B2=88=ED=98=B8?= =?UTF-8?q?=20=EC=9E=98=EB=AA=BB=20=EB=84=A3=EC=97=88=EC=9D=84=20=EB=95=8C?= =?UTF-8?q?=20=EC=98=88=EC=99=B8=EC=B2=98=EB=A6=AC=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lotto/controller/LottoController.java | 34 +++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/main/java/lotto/controller/LottoController.java b/src/main/java/lotto/controller/LottoController.java index a9a974ed..799fefba 100644 --- a/src/main/java/lotto/controller/LottoController.java +++ b/src/main/java/lotto/controller/LottoController.java @@ -21,28 +21,42 @@ public LottoController(LottoService lottoService, InputView inputView, OutputVie } public void run() { - purchaseLottos(); - inputWinningNumbers(); } private void purchaseLottos() { outputView.printInputLottoPriceMessage(); - int amount = inputView.inputPlayerPrice(); - Lotto.validatePurchaseAmount(amount); //유효성 검사 - lottoService.purchaseLottos(amount); + + while (true) { + int amount = inputView.inputPlayerPrice(); + try { + lottoService.purchaseLottos(amount); + break; + } catch (IllegalArgumentException e) { + outputView.printInputLottoPriceMessage(); + } + } } private void inputWinningNumbers() { - outputView.printInputLottoWinningMessage(); - List winningNumbers = inputView.inputLottoWinningNum(); - + List winningNumbers; + + while (true) { + outputView.printInputLottoWinningMessage(); + try { + winningNumbers = inputView.inputLottoWinningNum(); + Lotto lotto = new Lotto(winningNumbers); // 유효성 검사 수행 + break; + } catch (IllegalArgumentException e) { +// outputView.printErrorMessage(); + } + } outputView.printInputBonusNumberMessage(); int bonusNumber = inputBonusNumber(); - lottoService.inputWinningNumbers(winningNumbers, bonusNumber); } -} + +} From 93f171e0a159aebaedb4e89c0a237e7f4652cff8 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Sun, 6 Oct 2024 18:05:51 +0900 Subject: [PATCH 19/46] =?UTF-8?q?feat:=20=EB=8B=B9=EC=B2=A8=20=EB=B2=88?= =?UTF-8?q?=ED=98=B8=20=EC=9E=85=EB=A0=A5=20=EC=9D=B4=ED=9B=84=20=EA=B5=AC?= =?UTF-8?q?=EB=A7=A4=ED=95=9C=20=EB=A1=9C=EB=98=90=20=EA=B0=AF=EC=88=98+?= =?UTF-8?q?=EB=9E=9C=EB=8D=A4=20=EB=B2=88=ED=98=B8=20=EC=B6=9C=EB=A0=A5=20?= =?UTF-8?q?=EB=A9=94=EC=86=8C=EB=93=9C=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/service/LottoServiceImpl.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/lotto/service/LottoServiceImpl.java b/src/main/java/lotto/service/LottoServiceImpl.java index 4ab854bf..7700c541 100644 --- a/src/main/java/lotto/service/LottoServiceImpl.java +++ b/src/main/java/lotto/service/LottoServiceImpl.java @@ -20,19 +20,28 @@ public LottoServiceImpl(LottoRepository lottoRepository) { @Override public void purchaseLottos(int amount) { - int numberOfLotto = amount / LOOTO_AMOUNT; + Lotto.validatePurchaseAmount(amount); + int numberOfLotto = amount / LOOTO_AMOUNT; IntStream.range(0, numberOfLotto).forEach(i -> { Lotto lotto = Lotto.createRandomLotto(); // Lotto도메인에서 팩토리 메소드 호출 saveLottoNums(lotto); }); } + private void outputPurchasedLottos() { + List purchasedLottos = lottoRepository.findAllLotto(); + OutputView.printTicketCount(purchasedLottos.size()); + purchasedLottos.forEach(lotto -> System.out.println(lotto.getNumbers())); // 각 로또 번호 출력 + } + @Override public void inputWinningNumbers(List winningNumbers, int bonusNumber) { try { WinningNumbers winningNumbersObj = new WinningNumbers(winningNumbers, bonusNumber); lottoRepository.saveWinningNumbers(winningNumbersObj); + + outputPurchasedLottos(); } catch (IllegalArgumentException e) { OutputView.printErrorMessage(); } From 3e6801b59261f3d0c2a0cb45dd79b782b0210069 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Sun, 6 Oct 2024 23:15:20 +0900 Subject: [PATCH 20/46] =?UTF-8?q?feat:=20=EC=B2=98=EC=9D=8C=EC=97=90?= =?UTF-8?q?=EB=8A=94=20=EB=8B=A8=EC=88=9C=ED=9E=88=20=EC=A0=80=EC=9E=A5?= =?UTF-8?q?=ED=95=A0=20=EB=A9=94=EC=86=8C=EB=93=9C=EB=A1=9C=20=EC=83=9D?= =?UTF-8?q?=EA=B0=81=ED=96=88=EC=9C=BC=EB=82=98=20inputWinningNumbers?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EB=A0=88=ED=8C=8C=EC=A7=80=ED=86=A0?= =?UTF-8?q?=EB=A6=AC=EC=97=90=20=EC=A0=80=EC=9E=A5=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=EB=A5=BC=20=EB=B6=88=EB=9F=AC=EC=99=94=EA=B8=B0=20?= =?UTF-8?q?=EB=95=8C=EB=AC=B8=EC=97=90=20=EB=8B=B9=EC=B2=A8=20=EB=A1=9C?= =?UTF-8?q?=EB=98=90=EB=B2=88=ED=98=B8=EB=A5=BC=20=EC=B2=B4=ED=81=AC?= =?UTF-8?q?=ED=95=98=EA=B3=A0=20=EA=B2=B0=EA=B3=BC=EA=B0=92=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EC=B6=9C=EB=A0=A5=ED=95=98=EB=8A=94=20=EB=A9=94?= =?UTF-8?q?=EC=86=8C=EB=93=9C=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/service/LottoService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/lotto/service/LottoService.java b/src/main/java/lotto/service/LottoService.java index 3653dbeb..c645e355 100644 --- a/src/main/java/lotto/service/LottoService.java +++ b/src/main/java/lotto/service/LottoService.java @@ -13,5 +13,6 @@ public interface LottoService { void inputWinningNumbers(List winningNumbers, int bonusNumber); - void saveWinningNumbers(WinningNumbers winningNumbers); + void checkAndPrintResults(); + } From 004a334de0ab9013b331e050808f8cc3a1c87333 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Sun, 6 Oct 2024 23:15:59 +0900 Subject: [PATCH 21/46] =?UTF-8?q?feat:=20=EB=AA=A8=EB=93=A0=20=EA=B5=AC?= =?UTF-8?q?=EB=A7=A4=20=EB=A1=9C=EB=98=90=EC=99=80=20=EB=8B=B9=EC=B2=A8=20?= =?UTF-8?q?=EB=A1=9C=EB=98=90=EB=B2=88=ED=98=B8=EB=A5=BC=20=EB=B9=84?= =?UTF-8?q?=EA=B5=90=20=ED=9B=84=20=EC=B6=9C=EB=A0=A5=20=EA=B8=B0=EB=8A=A5?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lotto/service/LottoServiceImpl.java | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main/java/lotto/service/LottoServiceImpl.java b/src/main/java/lotto/service/LottoServiceImpl.java index 7700c541..4dc19481 100644 --- a/src/main/java/lotto/service/LottoServiceImpl.java +++ b/src/main/java/lotto/service/LottoServiceImpl.java @@ -1,6 +1,7 @@ package lotto.service; import lotto.model.Lotto; +import lotto.model.LottoResult; import lotto.model.WinningNumbers; import lotto.repository.LottoRepository; import lotto.view.InputView; @@ -12,10 +13,12 @@ public class LottoServiceImpl implements LottoService { private final LottoRepository lottoRepository; + private LottoResult lottoResult; private static final int LOOTO_AMOUNT = 1000; public LottoServiceImpl(LottoRepository lottoRepository) { this.lottoRepository = lottoRepository; + this.lottoResult = new LottoResult(); } @Override @@ -42,18 +45,36 @@ public void inputWinningNumbers(List winningNumbers, int bonusNumber) { lottoRepository.saveWinningNumbers(winningNumbersObj); outputPurchasedLottos(); + checkAndPrintResults(); } catch (IllegalArgumentException e) { OutputView.printErrorMessage(); } } - @Override - public void saveWinningNumbers(WinningNumbers winningNumbers) { - lottoRepository.saveWinningNumbers(winningNumbers); - } public void saveLottoNums(Lotto lotto){ lottoRepository.saveLotto(lotto); } + public void checkAndPrintResults() { + // 모든 구매 로또와 당첨 번호를 비교하는 메서드 + List purchasedLottos = lottoRepository.findAllLotto(); + WinningNumbers winningNumbers = lottoRepository.findWinningNumbers(); // 저장된 당첨 번호 가져오기 + int matchCount; + + for (Lotto lotto : purchasedLottos) { + matchCount = (int) lotto.getNumbers().stream() + .filter(winningNumbers.getNumbers()::contains) + .count(); + + boolean hasBonus = lotto.getNumbers().contains(winningNumbers.getBonusNumber()); + lottoResult.updateResult(matchCount, hasBonus); // 결과 업데이트 + } + lottoResult.printResult(); // 결과 출력 + + // 수익률 계산 및 출력 + double yield = lottoResult.calculateYield(purchasedLottos.size() * LOOTO_AMOUNT); + System.out.printf("총 수익률은 %.2f%%입니다.\n", yield); +} + } From d31c6e23bf25043322a028a8927e1d66ed35f99a Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Sun, 6 Oct 2024 23:16:31 +0900 Subject: [PATCH 22/46] =?UTF-8?q?feat:=20=EC=B5=9C=EC=A2=85=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=20=EA=B0=92=20=ED=81=B4=EB=9E=98=EC=8A=A4=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/lotto/model/LottoResult.java | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/main/java/lotto/model/LottoResult.java diff --git a/src/main/java/lotto/model/LottoResult.java b/src/main/java/lotto/model/LottoResult.java new file mode 100644 index 00000000..9b186f0c --- /dev/null +++ b/src/main/java/lotto/model/LottoResult.java @@ -0,0 +1,82 @@ +package lotto.model; + +import java.text.DecimalFormat; +import java.util.LinkedHashMap; +import java.util.Map; + +public class LottoResult { + + private static final int FIRST_PRIZE_COUNT = 6; + private static final int SECOND_PRIZE_COUNT = 5; + private static final int THIRD_PRIZE_COUNT = 5; + private static final int FOURTH_PRIZE_COUNT = 4; + private static final int FIFTH_PRIZE_COUNT = 3; + + private static final int FIRST_PRIZE_AMOUNT = 2_000_000_000; + private static final int SECOND_PRIZE_AMOUNT = 30_000_000; + private static final int THIRD_PRIZE_AMOUNT = 1_500_000; + private static final int FOURTH_PRIZE_AMOUNT = 50_000; + private static final int FIFTH_PRIZE_AMOUNT = 5_000; + + private final Map prizeCounts = new LinkedHashMap<>(); + + public LottoResult() { + prizeCounts.put("3개 일치", 0); + prizeCounts.put("4개 일치", 0); + prizeCounts.put("5개 일치", 0); + prizeCounts.put("5개 일치, 보너스 볼 일치", 0); + prizeCounts.put("6개 일치", 0); + } + + public void updateResult(int matchCount, boolean hasBonus) { + if (matchCount == FIRST_PRIZE_COUNT) { + prizeCounts.put("6개 일치", prizeCounts.get("6개 일치") + 1); + } else if (matchCount == SECOND_PRIZE_COUNT && hasBonus) { + prizeCounts.put("5개 일치, 보너스 볼 일치", prizeCounts.get("5개 일치, 보너스 볼 일치") + 1); + } else if (matchCount == THIRD_PRIZE_COUNT) { + prizeCounts.put("5개 일치", prizeCounts.get("5개 일치") + 1); + } else if (matchCount == FOURTH_PRIZE_COUNT) { + prizeCounts.put("4개 일치", prizeCounts.get("4개 일치") + 1); + } else if (matchCount == FIFTH_PRIZE_COUNT) { + prizeCounts.put("3개 일치", prizeCounts.get("3개 일치") + 1); + } + } + + public void printResult() { + System.out.println("당첨 통계"); + System.out.println("----"); + DecimalFormat decimalFormat = new DecimalFormat("#,###"); + + // 상금 및 개수 출력 + for (String prize : prizeCounts.keySet()) { + int count = prizeCounts.get(prize); + int prizeAmount = getPrizeAmount(prize); // 해당 상금 가져오기 + String formattedPrizeAmount = decimalFormat.format(prizeAmount); // 상금을 쉼표가 있는 형식으로 변환 + System.out.println(prize + " (" + formattedPrizeAmount + "원) - " + count + "개"); + } + } + + public int getPrizeAmount(String prize) { + switch (prize) { + case "6개 일치": + return FIRST_PRIZE_AMOUNT; + case "5개 일치, 보너스 볼 일치": + return SECOND_PRIZE_AMOUNT; + case "5개 일치": + return THIRD_PRIZE_AMOUNT; + case "4개 일치": + return FOURTH_PRIZE_AMOUNT; + case "3개 일치": + return FIFTH_PRIZE_AMOUNT; + default: + return 0; + } + } + + public double calculateYield(int totalAmountSpent) { + int totalPrize = prizeCounts.entrySet().stream() + .mapToInt(entry -> entry.getValue() * getPrizeAmount(entry.getKey())) + .sum(); + return Math.round((totalPrize / (double) totalAmountSpent) * 10000.0) / 100.0; // 소수점 둘째 자리에서 반올림 + } +} From e28771dd9b66fb07909c25428e9a8d69b6867a99 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Sun, 6 Oct 2024 23:18:53 +0900 Subject: [PATCH 23/46] =?UTF-8?q?feat:=206=EA=B0=9C=EC=A4=91=20=EC=B2=AB?= =?UTF-8?q?=EB=B2=88=EC=A7=B8=20=EB=8B=B9=EC=B2=A8=20=EB=B2=88=ED=98=B8=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/repository/LottoRepositoryImpl.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/lotto/repository/LottoRepositoryImpl.java b/src/main/java/lotto/repository/LottoRepositoryImpl.java index 3537f51d..676e6997 100644 --- a/src/main/java/lotto/repository/LottoRepositoryImpl.java +++ b/src/main/java/lotto/repository/LottoRepositoryImpl.java @@ -24,5 +24,9 @@ public List findAllLotto() { public void saveWinningNumbers(WinningNumbers winningNumbers) { winningNumbersStorage.add(winningNumbers); // 당첨 번호 저장 } + @Override + public WinningNumbers findWinningNumbers() { + return winningNumbersStorage.isEmpty() ? null : winningNumbersStorage.get(0); // 6개중 첫 번째 저장된 당첨 번호 반환 + } } From 1ed40b417058e44caecabf48e15dc84e4328a22d Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Mon, 7 Oct 2024 00:39:18 +0900 Subject: [PATCH 24/46] =?UTF-8?q?feat:=206=EA=B0=9C=EC=A4=91=20=EC=B2=AB?= =?UTF-8?q?=EB=B2=88=EC=A7=B8=20=EB=8B=B9=EC=B2=A8=20=EB=B2=88=ED=98=B8=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=20=EA=B8=B0=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 ++ src/main/java/lotto/AppConfig.java | 11 ++--- src/main/java/lotto/Application.java | 9 +++- src/main/java/lotto/Lotto.java | 20 -------- .../lotto/controller/LottoController.java | 4 +- src/main/java/lotto/model/Lotto.java | 49 +++++++++++++++++++ src/main/java/lotto/model/WinningNumbers.java | 22 +++++++++ .../lotto/repository/LottoRepository.java | 2 +- src/main/java/lotto/service/LottoService.java | 2 - .../java/lotto/service/LottoServiceImpl.java | 3 +- src/main/java/lotto/view/InputView.java | 2 +- src/main/java/lotto/view/OutputView.java | 13 ----- src/test/java/lotto/LottoTest.java | 1 + 13 files changed, 91 insertions(+), 50 deletions(-) delete mode 100644 src/main/java/lotto/Lotto.java create mode 100644 src/main/java/lotto/model/Lotto.java create mode 100644 src/main/java/lotto/model/WinningNumbers.java diff --git a/build.gradle b/build.gradle index 9d087b14..88edc371 100644 --- a/build.gradle +++ b/build.gradle @@ -20,3 +20,6 @@ java { test { useJUnitPlatform() } +tasks.withType(JavaExec) { + jvmArgs '--add-opens', 'java.base/java.util=ALL-UNNAMED' +} diff --git a/src/main/java/lotto/AppConfig.java b/src/main/java/lotto/AppConfig.java index 597c142d..ec255747 100644 --- a/src/main/java/lotto/AppConfig.java +++ b/src/main/java/lotto/AppConfig.java @@ -8,24 +8,21 @@ import lotto.view.InputView; import lotto.view.OutputView; -import java.security.Provider; - public class AppConfig { - public InputView inputView() { + private InputView inputView() { return new InputView(); } - public OutputView outputView() { + private OutputView outputView() { return new OutputView(); } - // LottoRepository 인스턴스를 생성하는 메서드 - public LottoRepository lottoRepository() { + private LottoRepository lottoRepository() { return new LottoRepositoryImpl(); } - public LottoService lottoService() { + private LottoService lottoService() { return new LottoServiceImpl(lottoRepository()); } diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java index d190922b..c8c4d942 100644 --- a/src/main/java/lotto/Application.java +++ b/src/main/java/lotto/Application.java @@ -1,7 +1,14 @@ package lotto; + +import lotto.controller.LottoController; + public class Application { public static void main(String[] args) { - // TODO: 프로그램 구현 + + AppConfig appConfig = new AppConfig(); + LottoController lottoController = appConfig.lottoController(); + lottoController.run(); + } } diff --git a/src/main/java/lotto/Lotto.java b/src/main/java/lotto/Lotto.java deleted file mode 100644 index 519793d1..00000000 --- a/src/main/java/lotto/Lotto.java +++ /dev/null @@ -1,20 +0,0 @@ -package lotto; - -import java.util.List; - -public class Lotto { - private final List numbers; - - public Lotto(List numbers) { - validate(numbers); - this.numbers = numbers; - } - - private void validate(List numbers) { - if (numbers.size() != 6) { - throw new IllegalArgumentException(); - } - } - - // TODO: 추가 기능 구현 -} diff --git a/src/main/java/lotto/controller/LottoController.java b/src/main/java/lotto/controller/LottoController.java index 799fefba..ffbd6051 100644 --- a/src/main/java/lotto/controller/LottoController.java +++ b/src/main/java/lotto/controller/LottoController.java @@ -49,7 +49,7 @@ private void inputWinningNumbers() { Lotto lotto = new Lotto(winningNumbers); // 유효성 검사 수행 break; } catch (IllegalArgumentException e) { -// outputView.printErrorMessage(); + } } outputView.printInputBonusNumberMessage(); @@ -57,6 +57,4 @@ private void inputWinningNumbers() { lottoService.inputWinningNumbers(winningNumbers, bonusNumber); } - - } diff --git a/src/main/java/lotto/model/Lotto.java b/src/main/java/lotto/model/Lotto.java new file mode 100644 index 00000000..14a59bcb --- /dev/null +++ b/src/main/java/lotto/model/Lotto.java @@ -0,0 +1,49 @@ +package lotto.model; + +import camp.nextstep.edu.missionutils.Randoms; +import lotto.view.OutputView; +import java.util.Collections; +import java.util.List; + +public class Lotto { + private final List numbers; //로또 갯수 저장필드 + private static final int LOOTO_AMOUNT = 1000; + + public Lotto(List numbers) { + validate(numbers); + this.numbers = numbers; + } + + public static Lotto createRandomLotto() { + List lottoNumbers = Randoms.pickUniqueNumbersInRange(1, 45, 6); + Collections.sort(lottoNumbers); + return new Lotto(lottoNumbers); + } + public List getNumbers() { + return numbers; + } + + public static void validatePurchaseAmount(int amount) { + if (amount < LOOTO_AMOUNT) { + OutputView.printMinimumPurchaseMessage(); + throw new IllegalArgumentException(); + } + if (amount % LOOTO_AMOUNT != 0) { + OutputView.printInvalidPurchaseMessage(); + throw new IllegalArgumentException(); + } + } + + private void validate(List numbers) { + if (numbers.size() != 6) { + OutputView.printErrorMessage(); + throw new IllegalArgumentException(); + } + for (Integer number : numbers) { + if (number < 1 || number > 45) { + OutputView.printErrorMessageInvalidNumber(); + throw new IllegalArgumentException(); + } + } + } +} diff --git a/src/main/java/lotto/model/WinningNumbers.java b/src/main/java/lotto/model/WinningNumbers.java new file mode 100644 index 00000000..ccc4b17e --- /dev/null +++ b/src/main/java/lotto/model/WinningNumbers.java @@ -0,0 +1,22 @@ +package lotto.model; + +import java.util.List; + +public class WinningNumbers { + private final List numbers; + private final int bonusNumber; + + public WinningNumbers(List numbers, int bonusNumber) { + this.numbers = numbers; + this.bonusNumber = bonusNumber; + } + + public List getNumbers() { + return numbers; + } + + public int getBonusNumber() { + return bonusNumber; + } + +} diff --git a/src/main/java/lotto/repository/LottoRepository.java b/src/main/java/lotto/repository/LottoRepository.java index c0aead7e..53d39352 100644 --- a/src/main/java/lotto/repository/LottoRepository.java +++ b/src/main/java/lotto/repository/LottoRepository.java @@ -11,5 +11,5 @@ public interface LottoRepository { void saveWinningNumbers(WinningNumbers winningNumbers); -// WinningNumbers findWinningNumbers(); + WinningNumbers findWinningNumbers(); } diff --git a/src/main/java/lotto/service/LottoService.java b/src/main/java/lotto/service/LottoService.java index c645e355..df41ed35 100644 --- a/src/main/java/lotto/service/LottoService.java +++ b/src/main/java/lotto/service/LottoService.java @@ -1,8 +1,6 @@ package lotto.service; import lotto.model.Lotto; -import lotto.model.WinningNumbers; - import java.util.List; public interface LottoService { diff --git a/src/main/java/lotto/service/LottoServiceImpl.java b/src/main/java/lotto/service/LottoServiceImpl.java index 4dc19481..a64a8af0 100644 --- a/src/main/java/lotto/service/LottoServiceImpl.java +++ b/src/main/java/lotto/service/LottoServiceImpl.java @@ -4,7 +4,6 @@ import lotto.model.LottoResult; import lotto.model.WinningNumbers; import lotto.repository.LottoRepository; -import lotto.view.InputView; import lotto.view.OutputView; import java.util.List; @@ -13,7 +12,7 @@ public class LottoServiceImpl implements LottoService { private final LottoRepository lottoRepository; - private LottoResult lottoResult; + private final LottoResult lottoResult; private static final int LOOTO_AMOUNT = 1000; public LottoServiceImpl(LottoRepository lottoRepository) { diff --git a/src/main/java/lotto/view/InputView.java b/src/main/java/lotto/view/InputView.java index 6c1bc31f..272e5e7f 100644 --- a/src/main/java/lotto/view/InputView.java +++ b/src/main/java/lotto/view/InputView.java @@ -20,7 +20,7 @@ public static int inputBonusNumber() { return Integer.parseInt(Console.readLine()); } - //for문 서비스 쪽으로 옮겨야 함 + //for문 서비스 쪽으로 옮겨야 하는데 못하겠네.. public static List numberList(String winningNumber) { String[] result = winningNumber.split(","); winningNumberList = new ArrayList<>(); diff --git a/src/main/java/lotto/view/OutputView.java b/src/main/java/lotto/view/OutputView.java index 9e32702f..33bd1426 100644 --- a/src/main/java/lotto/view/OutputView.java +++ b/src/main/java/lotto/view/OutputView.java @@ -14,19 +14,10 @@ public static void printTicketCount(int count) { System.out.println(count + TICKET_COUNT); } - public static void printSuccessMessage(String message, int numberOfMatch) { - System.out.println(message + numberOfMatch + "개"); - } - public static void printInputLottoPriceMessage() { System.out.println(INPUT_LOTTO_PRICE); } - public static void printSuccessResult() { - System.out.println("당첨 통계"); - System.out.println("---"); - } - public static void printInputLottoWinningMessage() { System.out.println(INPUT_LOTTO_WINNING); } @@ -51,8 +42,4 @@ public static void printErrorMessage() { public static void printErrorMessageInvalidNumber() { System.out.println(ERROR_INVALID_NUMBER); } - - public static void printRevenueRate(double EarningRate) { - System.out.println("총 수익률은 " + String.format("%.1f", EarningRate) + "%입니다."); - } } diff --git a/src/test/java/lotto/LottoTest.java b/src/test/java/lotto/LottoTest.java index 0f3af0f6..19e699c4 100644 --- a/src/test/java/lotto/LottoTest.java +++ b/src/test/java/lotto/LottoTest.java @@ -1,5 +1,6 @@ package lotto; +import lotto.model.Lotto; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; From f27b5a4ddee62dc5b3caa4fa971d90d44d19c1f0 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Tue, 8 Oct 2024 17:23:47 +0900 Subject: [PATCH 25/46] =?UTF-8?q?feat:=20ErrorMessage=20=EC=A0=84=EC=9A=A9?= =?UTF-8?q?=20enum=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/lotto/view/ErrorMessage.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/lotto/view/ErrorMessage.java diff --git a/src/main/java/lotto/view/ErrorMessage.java b/src/main/java/lotto/view/ErrorMessage.java new file mode 100644 index 00000000..dfe21eb6 --- /dev/null +++ b/src/main/java/lotto/view/ErrorMessage.java @@ -0,0 +1,20 @@ +package lotto.view; + +public enum ErrorMessage { + + ERROR_MINIMUM_PURCHASE_AMOUNT("[ERROR] 구입 금액은 최소 1,000원이 필요합니다."), + ERROR_INVALID_PURCHASE_AMOUNT("[ERROR] 구입 금액은 1,000원 단위로 입력해야 합니다."), + ERROR_MESSAGE("[ERROR] 로또 번호를 6개 입력해 주세요."), + ERROR_INVALID_NUMBER("[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다."); + + private String message; + + ErrorMessage(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + +} From 67aacf4bda4b24fc050725c57abc70db19ad7839 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Tue, 8 Oct 2024 17:24:04 +0900 Subject: [PATCH 26/46] =?UTF-8?q?feat:=20=EA=B8=B0=EC=A1=B4=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EA=B4=80=EB=A0=A8=EB=90=9C=20output=20=EC=A0=84?= =?UTF-8?q?=EB=B6=80=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/view/OutputView.java | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/src/main/java/lotto/view/OutputView.java b/src/main/java/lotto/view/OutputView.java index 33bd1426..9a8f3583 100644 --- a/src/main/java/lotto/view/OutputView.java +++ b/src/main/java/lotto/view/OutputView.java @@ -5,10 +5,6 @@ public class OutputView { private static final String INPUT_LOTTO_PRICE = "구입금액을 입력해 주세요."; private static final String INPUT_LOTTO_WINNING = "당첨 번호를 입력해 주세요."; private static final String INPUT_BONUS_NUMBER = "보너스 번호를 입력해 주세요."; - private static final String ERROR_MINIMUM_PURCHASE_AMOUNT = "[ERROR] 구입 금액은 최소 1,000원이 필요합니다."; - private static final String ERROR_INVALID_PURCHASE_AMOUNT = "[ERROR] 구입 금액은 1,000원 단위로 입력해야 합니다."; - private static final String ERROR_MESSAGE = "[ERROR] 로또 번호를 6개 입력해 주세요."; - private static final String ERROR_INVALID_NUMBER = "[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다."; public static void printTicketCount(int count) { System.out.println(count + TICKET_COUNT); @@ -24,22 +20,10 @@ public static void printInputLottoWinningMessage() { public static void printInputBonusNumberMessage() { System.out.println(INPUT_BONUS_NUMBER); - - } - - public static void printMinimumPurchaseMessage() { - System.out.println(ERROR_MINIMUM_PURCHASE_AMOUNT); } - public static void printInvalidPurchaseMessage() { - System.out.println(ERROR_INVALID_PURCHASE_AMOUNT); + public static void printErrorMessage(ErrorMessage errorMessage) { + System.out.println(errorMessage.getMessage()); } - public static void printErrorMessage() { - System.out.println(ERROR_MESSAGE); - } - - public static void printErrorMessageInvalidNumber() { - System.out.println(ERROR_INVALID_NUMBER); - } } From a9cbd094e71957834675a13cc63444ab8978c569 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Tue, 8 Oct 2024 17:26:57 +0900 Subject: [PATCH 27/46] =?UTF-8?q?feat:=20=EC=BD=94=EB=93=9C=20=EC=9E=AC?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EC=84=B1=20=EB=B0=8F=20=EC=9C=A0=EC=A7=80?= =?UTF-8?q?=EB=B3=B4=EC=88=98=EC=84=B1=EC=9D=84=20=EC=9C=84=ED=95=9C=20?= =?UTF-8?q?=EC=83=81=EC=88=98=20=EC=84=A0=EC=96=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/model/LottoResult.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/lotto/model/LottoResult.java b/src/main/java/lotto/model/LottoResult.java index 9b186f0c..d8d5dc6c 100644 --- a/src/main/java/lotto/model/LottoResult.java +++ b/src/main/java/lotto/model/LottoResult.java @@ -18,14 +18,20 @@ public class LottoResult { private static final int FOURTH_PRIZE_AMOUNT = 50_000; private static final int FIFTH_PRIZE_AMOUNT = 5_000; + private static final String THREE_MATCH = "3개 일치"; + private static final String FOUR_MATCH = "4개 일치"; + private static final String FIVE_MATCH = "5개 일치"; + private static final String FIVE_MATCH_BONUS = "5개 일치, 보너스 볼 일치"; + private static final String SIX_MATCH = "6개 일치"; + private final Map prizeCounts = new LinkedHashMap<>(); public LottoResult() { - prizeCounts.put("3개 일치", 0); - prizeCounts.put("4개 일치", 0); - prizeCounts.put("5개 일치", 0); - prizeCounts.put("5개 일치, 보너스 볼 일치", 0); - prizeCounts.put("6개 일치", 0); + prizeCounts.put(THREE_MATCH, 0); + prizeCounts.put(FOUR_MATCH, 0); + prizeCounts.put(FIVE_MATCH, 0); + prizeCounts.put(FIVE_MATCH_BONUS, 0); + prizeCounts.put(SIX_MATCH, 0); } public void updateResult(int matchCount, boolean hasBonus) { From f782cba9a442239c8ebd886e2836f30e867b4e2b Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Tue, 8 Oct 2024 17:28:12 +0900 Subject: [PATCH 28/46] =?UTF-8?q?feat:=20=EA=B0=80=EB=8F=85=EC=84=B1?= =?UTF-8?q?=EC=9D=84=20=EC=9C=84=ED=95=B4=20public=20=EB=A9=94=EC=86=8C?= =?UTF-8?q?=EB=93=9C=EB=A5=BC=20=EC=83=81=EB=8B=A8=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EC=9E=AC=EB=B0=B0=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/AppConfig.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/lotto/AppConfig.java b/src/main/java/lotto/AppConfig.java index ec255747..2f1ee935 100644 --- a/src/main/java/lotto/AppConfig.java +++ b/src/main/java/lotto/AppConfig.java @@ -10,6 +10,10 @@ public class AppConfig { + public LottoController lottoController() { + return new LottoController(lottoService(), inputView(), outputView()); + } + private InputView inputView() { return new InputView(); } @@ -26,8 +30,4 @@ private LottoService lottoService() { return new LottoServiceImpl(lottoRepository()); } - public LottoController lottoController() { - return new LottoController(lottoService(), inputView(), outputView()); - } - } From fa0b41fdd2258b6da3dcfc8a45aff9e8e3c017c5 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Tue, 8 Oct 2024 17:29:25 +0900 Subject: [PATCH 29/46] =?UTF-8?q?feat:=20=EC=97=B4=EA=B1=B0=ED=98=95=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EB=A9=94=EC=84=B8=EC=A7=80=20=ED=98=B8?= =?UTF-8?q?=EC=B6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/service/LottoServiceImpl.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/lotto/service/LottoServiceImpl.java b/src/main/java/lotto/service/LottoServiceImpl.java index a64a8af0..c66f621a 100644 --- a/src/main/java/lotto/service/LottoServiceImpl.java +++ b/src/main/java/lotto/service/LottoServiceImpl.java @@ -4,6 +4,7 @@ import lotto.model.LottoResult; import lotto.model.WinningNumbers; import lotto.repository.LottoRepository; +import lotto.view.ErrorMessage; import lotto.view.OutputView; import java.util.List; @@ -11,9 +12,11 @@ public class LottoServiceImpl implements LottoService { + private static final int LOOTO_AMOUNT = 1000; + private final LottoRepository lottoRepository; private final LottoResult lottoResult; - private static final int LOOTO_AMOUNT = 1000; + public LottoServiceImpl(LottoRepository lottoRepository) { this.lottoRepository = lottoRepository; @@ -46,7 +49,7 @@ public void inputWinningNumbers(List winningNumbers, int bonusNumber) { outputPurchasedLottos(); checkAndPrintResults(); } catch (IllegalArgumentException e) { - OutputView.printErrorMessage(); + OutputView.printErrorMessage(ErrorMessage.ERROR_MESSAGE); } } From 778f4cac80eb6dc16f03056f4916c463df56ccfc Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Wed, 9 Oct 2024 23:46:57 +0900 Subject: [PATCH 30/46] =?UTF-8?q?feat:=20=EB=B0=98=EB=B3=B5=EB=AC=B8?= =?UTF-8?q?=EC=9D=98=20=EC=A1=B0=EA=B1=B4=EC=9D=84=20=EB=B3=80=EC=88=98?= =?UTF-8?q?=EB=A1=9C=20=EC=84=A0=EC=96=B8=ED=95=98=EC=97=AC=20=ED=86=B5?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/controller/LottoController.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/lotto/controller/LottoController.java b/src/main/java/lotto/controller/LottoController.java index ffbd6051..ab343ff7 100644 --- a/src/main/java/lotto/controller/LottoController.java +++ b/src/main/java/lotto/controller/LottoController.java @@ -27,12 +27,13 @@ public void run() { private void purchaseLottos() { outputView.printInputLottoPriceMessage(); - - while (true) { + boolean isPurchasing = true; + while (isPurchasing) { int amount = inputView.inputPlayerPrice(); + try { lottoService.purchaseLottos(amount); - break; + isPurchasing = false; } catch (IllegalArgumentException e) { outputView.printInputLottoPriceMessage(); } @@ -41,7 +42,6 @@ private void purchaseLottos() { private void inputWinningNumbers() { List winningNumbers; - while (true) { outputView.printInputLottoWinningMessage(); try { From 31aa2d91c00ff90ec24cca9aa025bcc6d31e61e7 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Wed, 9 Oct 2024 23:51:09 +0900 Subject: [PATCH 31/46] =?UTF-8?q?feat:=20=EC=83=81=EC=88=98=20=EB=B6=88?= =?UTF-8?q?=EB=B3=80=EC=84=B1=EC=9D=84=20=EC=9C=84=ED=95=B4=20final=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/view/ErrorMessage.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/lotto/view/ErrorMessage.java b/src/main/java/lotto/view/ErrorMessage.java index dfe21eb6..51ae115d 100644 --- a/src/main/java/lotto/view/ErrorMessage.java +++ b/src/main/java/lotto/view/ErrorMessage.java @@ -7,7 +7,7 @@ public enum ErrorMessage { ERROR_MESSAGE("[ERROR] 로또 번호를 6개 입력해 주세요."), ERROR_INVALID_NUMBER("[ERROR] 로또 번호는 1부터 45 사이의 숫자여야 합니다."); - private String message; + private final String message; ErrorMessage(String message) { this.message = message; From 3449189e38775bcaae48da2a4f0c7239a510d3c0 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Wed, 9 Oct 2024 23:55:38 +0900 Subject: [PATCH 32/46] =?UTF-8?q?feat:=20=EB=A7=A4=EC=A7=81=EB=84=98?= =?UTF-8?q?=EB=B2=84=EB=A5=BC=20=EC=83=81=EC=88=98=EB=A1=9C=20=EC=84=A0?= =?UTF-8?q?=EC=96=B8,=20Enum=EC=9C=BC=EB=A1=9C=20=EB=B0=94=EA=BE=BC=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EB=A9=94=EC=8B=9C=EC=A7=80=20=ED=98=B8?= =?UTF-8?q?=EC=B6=9C=20=EB=A9=94=EC=86=8C=EB=93=9C=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/model/Lotto.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/lotto/model/Lotto.java b/src/main/java/lotto/model/Lotto.java index 14a59bcb..bb4a6940 100644 --- a/src/main/java/lotto/model/Lotto.java +++ b/src/main/java/lotto/model/Lotto.java @@ -1,13 +1,18 @@ package lotto.model; import camp.nextstep.edu.missionutils.Randoms; +import lotto.view.ErrorMessage; import lotto.view.OutputView; import java.util.Collections; import java.util.List; public class Lotto { + private final List numbers; //로또 갯수 저장필드 private static final int LOOTO_AMOUNT = 1000; + private static final int START_INCLUSIVE = 1; + private static final int END_INCLUSIVE = 1; + private static final int COUNT = 1; public Lotto(List numbers) { validate(numbers); @@ -15,7 +20,7 @@ public Lotto(List numbers) { } public static Lotto createRandomLotto() { - List lottoNumbers = Randoms.pickUniqueNumbersInRange(1, 45, 6); + List lottoNumbers = Randoms.pickUniqueNumbersInRange(START_INCLUSIVE, END_INCLUSIVE, COUNT); Collections.sort(lottoNumbers); return new Lotto(lottoNumbers); } @@ -25,23 +30,23 @@ public List getNumbers() { public static void validatePurchaseAmount(int amount) { if (amount < LOOTO_AMOUNT) { - OutputView.printMinimumPurchaseMessage(); + OutputView.printErrorMessage(ErrorMessage.ERROR_MINIMUM_PURCHASE_AMOUNT); throw new IllegalArgumentException(); } if (amount % LOOTO_AMOUNT != 0) { - OutputView.printInvalidPurchaseMessage(); + OutputView.printErrorMessage(ErrorMessage.ERROR_INVALID_PURCHASE_AMOUNT); throw new IllegalArgumentException(); } } private void validate(List numbers) { if (numbers.size() != 6) { - OutputView.printErrorMessage(); + OutputView.printErrorMessage(ErrorMessage.ERROR_MESSAGE); throw new IllegalArgumentException(); } for (Integer number : numbers) { if (number < 1 || number > 45) { - OutputView.printErrorMessageInvalidNumber(); + OutputView.printErrorMessage(ErrorMessage.ERROR_INVALID_NUMBER); throw new IllegalArgumentException(); } } From f7bdb025b2901c72d61393d27407f7cbdd71953d Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Thu, 10 Oct 2024 04:05:41 +0900 Subject: [PATCH 33/46] =?UTF-8?q?feat:=20=EC=A4=91=EB=B3=B5=EB=90=9C=20?= =?UTF-8?q?=EB=AC=B8=EC=9E=90=EC=97=B4=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/model/LottoResult.java | 40 ++++++++++++++-------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/main/java/lotto/model/LottoResult.java b/src/main/java/lotto/model/LottoResult.java index d8d5dc6c..f15b198d 100644 --- a/src/main/java/lotto/model/LottoResult.java +++ b/src/main/java/lotto/model/LottoResult.java @@ -36,15 +36,27 @@ public LottoResult() { public void updateResult(int matchCount, boolean hasBonus) { if (matchCount == FIRST_PRIZE_COUNT) { - prizeCounts.put("6개 일치", prizeCounts.get("6개 일치") + 1); - } else if (matchCount == SECOND_PRIZE_COUNT && hasBonus) { - prizeCounts.put("5개 일치, 보너스 볼 일치", prizeCounts.get("5개 일치, 보너스 볼 일치") + 1); - } else if (matchCount == THIRD_PRIZE_COUNT) { - prizeCounts.put("5개 일치", prizeCounts.get("5개 일치") + 1); - } else if (matchCount == FOURTH_PRIZE_COUNT) { - prizeCounts.put("4개 일치", prizeCounts.get("4개 일치") + 1); - } else if (matchCount == FIFTH_PRIZE_COUNT) { - prizeCounts.put("3개 일치", prizeCounts.get("3개 일치") + 1); + prizeCounts.put(SIX_MATCH, prizeCounts.get(SIX_MATCH) + 1); + return; + } + + if (matchCount == SECOND_PRIZE_COUNT && hasBonus) { + prizeCounts.put(FIVE_MATCH_BONUS, prizeCounts.get(FIVE_MATCH_BONUS) + 1); + return; + } + + if (matchCount == SECOND_PRIZE_COUNT) { + prizeCounts.put(FIVE_MATCH, prizeCounts.get(FIVE_MATCH) + 1); + return; + } + + if (matchCount == FOURTH_PRIZE_COUNT) { + prizeCounts.put(FOUR_MATCH, prizeCounts.get(FOUR_MATCH) + 1); + return; + } + + if (matchCount == FIFTH_PRIZE_COUNT) { + prizeCounts.put(THREE_MATCH, prizeCounts.get(THREE_MATCH) + 1); } } @@ -64,15 +76,15 @@ public void printResult() { public int getPrizeAmount(String prize) { switch (prize) { - case "6개 일치": + case SIX_MATCH: return FIRST_PRIZE_AMOUNT; - case "5개 일치, 보너스 볼 일치": + case FIVE_MATCH_BONUS: return SECOND_PRIZE_AMOUNT; - case "5개 일치": + case FIVE_MATCH: return THIRD_PRIZE_AMOUNT; - case "4개 일치": + case FOUR_MATCH: return FOURTH_PRIZE_AMOUNT; - case "3개 일치": + case THREE_MATCH: return FIFTH_PRIZE_AMOUNT; default: return 0; From f789556200ce8d09186b25784f6cea18c1f82493 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Thu, 10 Oct 2024 04:06:16 +0900 Subject: [PATCH 34/46] =?UTF-8?q?feat:=206=EA=B0=9C=EC=A4=91=20=EB=A7=88?= =?UTF-8?q?=EC=A7=80=EB=A7=89=20=EC=A0=80=EC=9E=A5=20=EB=B2=88=ED=98=B8=20?= =?UTF-8?q?=EB=B0=98=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/repository/LottoRepositoryImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/lotto/repository/LottoRepositoryImpl.java b/src/main/java/lotto/repository/LottoRepositoryImpl.java index 676e6997..a50571f6 100644 --- a/src/main/java/lotto/repository/LottoRepositoryImpl.java +++ b/src/main/java/lotto/repository/LottoRepositoryImpl.java @@ -26,7 +26,7 @@ public void saveWinningNumbers(WinningNumbers winningNumbers) { } @Override public WinningNumbers findWinningNumbers() { - return winningNumbersStorage.isEmpty() ? null : winningNumbersStorage.get(0); // 6개중 첫 번째 저장된 당첨 번호 반환 + return winningNumbersStorage.isEmpty() ? null : winningNumbersStorage.get(winningNumbersStorage.size() - 1); } } From 81f8e7522ee39a424eb0b1145a8169b83de6b0a4 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Thu, 10 Oct 2024 04:06:48 +0900 Subject: [PATCH 35/46] =?UTF-8?q?feat:=20while=EB=AC=B8=20=EB=B3=80?= =?UTF-8?q?=EC=88=98=EC=84=A0=EC=96=B8=20=EB=B0=A9=EC=8B=9D=EC=9C=BC?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/controller/LottoController.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/lotto/controller/LottoController.java b/src/main/java/lotto/controller/LottoController.java index ab343ff7..466beabd 100644 --- a/src/main/java/lotto/controller/LottoController.java +++ b/src/main/java/lotto/controller/LottoController.java @@ -27,10 +27,10 @@ public void run() { private void purchaseLottos() { outputView.printInputLottoPriceMessage(); + boolean isPurchasing = true; while (isPurchasing) { int amount = inputView.inputPlayerPrice(); - try { lottoService.purchaseLottos(amount); isPurchasing = false; @@ -41,17 +41,20 @@ private void purchaseLottos() { } private void inputWinningNumbers() { - List winningNumbers; - while (true) { + List winningNumbers = null; + boolean isInputting = true; + + while (isInputting) { outputView.printInputLottoWinningMessage(); try { winningNumbers = inputView.inputLottoWinningNum(); - Lotto lotto = new Lotto(winningNumbers); // 유효성 검사 수행 - break; + new Lotto(winningNumbers); // 유효성 검사 수행 + isInputting = false; } catch (IllegalArgumentException e) { } } + outputView.printInputBonusNumberMessage(); int bonusNumber = inputBonusNumber(); lottoService.inputWinningNumbers(winningNumbers, bonusNumber); From 326660de2432249669d785e4499143de4735a770 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Thu, 10 Oct 2024 04:07:04 +0900 Subject: [PATCH 36/46] =?UTF-8?q?feat:=20=EC=98=A4=ED=83=80=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/model/Lotto.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/lotto/model/Lotto.java b/src/main/java/lotto/model/Lotto.java index bb4a6940..a93b6289 100644 --- a/src/main/java/lotto/model/Lotto.java +++ b/src/main/java/lotto/model/Lotto.java @@ -9,10 +9,10 @@ public class Lotto { private final List numbers; //로또 갯수 저장필드 - private static final int LOOTO_AMOUNT = 1000; + private static final int LOTTO_AMOUNT = 1000; private static final int START_INCLUSIVE = 1; - private static final int END_INCLUSIVE = 1; - private static final int COUNT = 1; + private static final int END_INCLUSIVE = 45; + private static final int COUNT = 6; public Lotto(List numbers) { validate(numbers); @@ -29,11 +29,11 @@ public List getNumbers() { } public static void validatePurchaseAmount(int amount) { - if (amount < LOOTO_AMOUNT) { + if (amount < LOTTO_AMOUNT) { OutputView.printErrorMessage(ErrorMessage.ERROR_MINIMUM_PURCHASE_AMOUNT); throw new IllegalArgumentException(); } - if (amount % LOOTO_AMOUNT != 0) { + if (amount % LOTTO_AMOUNT != 0) { OutputView.printErrorMessage(ErrorMessage.ERROR_INVALID_PURCHASE_AMOUNT); throw new IllegalArgumentException(); } From 6254b9a6dc753ba48f1d0512f68b069be0301643 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Thu, 10 Oct 2024 04:07:43 +0900 Subject: [PATCH 37/46] =?UTF-8?q?feat:=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20static=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/view/InputView.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/java/lotto/view/InputView.java b/src/main/java/lotto/view/InputView.java index 272e5e7f..f46203f3 100644 --- a/src/main/java/lotto/view/InputView.java +++ b/src/main/java/lotto/view/InputView.java @@ -6,13 +6,11 @@ public class InputView { - private static List winningNumberList; - - public static int inputPlayerPrice() { + public int inputPlayerPrice() { return Integer.parseInt(Console.readLine()); } - public static List inputLottoWinningNum() { + public List inputLottoWinningNum() { return numberList(Console.readLine()); } @@ -23,7 +21,7 @@ public static int inputBonusNumber() { //for문 서비스 쪽으로 옮겨야 하는데 못하겠네.. public static List numberList(String winningNumber) { String[] result = winningNumber.split(","); - winningNumberList = new ArrayList<>(); + List winningNumberList = new ArrayList<>(); for (int i = 0; i < result.length; i++) { winningNumberList.add(conventToInt(result[i])); } From 0e2bc0e73882f0ae658985f6b68d43d63cb1ead5 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Thu, 10 Oct 2024 04:08:00 +0900 Subject: [PATCH 38/46] =?UTF-8?q?feat:=20=EC=9D=98=EC=A1=B4=EC=84=B1=20?= =?UTF-8?q?=EC=A3=BC=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/AppConfig.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/lotto/AppConfig.java b/src/main/java/lotto/AppConfig.java index 2f1ee935..f3a1029f 100644 --- a/src/main/java/lotto/AppConfig.java +++ b/src/main/java/lotto/AppConfig.java @@ -1,6 +1,7 @@ package lotto; import lotto.controller.LottoController; +import lotto.model.LottoResult; import lotto.repository.LottoRepository; import lotto.repository.LottoRepositoryImpl; import lotto.service.LottoService; @@ -27,7 +28,7 @@ private LottoRepository lottoRepository() { } private LottoService lottoService() { - return new LottoServiceImpl(lottoRepository()); + return new LottoServiceImpl(lottoRepository(),new LottoResult()); } } From 632b5d789b07da3140472b45e44fdee4fc08a511 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Thu, 10 Oct 2024 04:08:30 +0900 Subject: [PATCH 39/46] =?UTF-8?q?feat:=20=EC=9D=98=EC=A1=B4=EC=84=B1=20?= =?UTF-8?q?=EC=A3=BC=EC=9E=85=EC=9C=BC=EB=A1=9C=20=EB=B6=88=ED=95=84?= =?UTF-8?q?=EC=9A=94=ED=95=9C=20=EA=B0=9D=EC=B2=B4=20=EC=84=A0=EC=96=B8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/lotto/service/LottoServiceImpl.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/main/java/lotto/service/LottoServiceImpl.java b/src/main/java/lotto/service/LottoServiceImpl.java index c66f621a..2bfdb27c 100644 --- a/src/main/java/lotto/service/LottoServiceImpl.java +++ b/src/main/java/lotto/service/LottoServiceImpl.java @@ -18,9 +18,9 @@ public class LottoServiceImpl implements LottoService { private final LottoResult lottoResult; - public LottoServiceImpl(LottoRepository lottoRepository) { + public LottoServiceImpl(LottoRepository lottoRepository, LottoResult lottoResult) { this.lottoRepository = lottoRepository; - this.lottoResult = new LottoResult(); + this.lottoResult = lottoResult; } @Override @@ -29,17 +29,10 @@ public void purchaseLottos(int amount) { int numberOfLotto = amount / LOOTO_AMOUNT; IntStream.range(0, numberOfLotto).forEach(i -> { - Lotto lotto = Lotto.createRandomLotto(); // Lotto도메인에서 팩토리 메소드 호출 - saveLottoNums(lotto); + saveLottoNums(Lotto.createRandomLotto()); }); } - private void outputPurchasedLottos() { - List purchasedLottos = lottoRepository.findAllLotto(); - OutputView.printTicketCount(purchasedLottos.size()); - purchasedLottos.forEach(lotto -> System.out.println(lotto.getNumbers())); // 각 로또 번호 출력 - } - @Override public void inputWinningNumbers(List winningNumbers, int bonusNumber) { try { @@ -53,7 +46,6 @@ public void inputWinningNumbers(List winningNumbers, int bonusNumber) { } } - public void saveLottoNums(Lotto lotto){ lottoRepository.saveLotto(lotto); } @@ -72,11 +64,17 @@ public void checkAndPrintResults() { boolean hasBonus = lotto.getNumbers().contains(winningNumbers.getBonusNumber()); lottoResult.updateResult(matchCount, hasBonus); // 결과 업데이트 } - lottoResult.printResult(); // 결과 출력 + lottoResult.printResult(); - // 수익률 계산 및 출력 double yield = lottoResult.calculateYield(purchasedLottos.size() * LOOTO_AMOUNT); System.out.printf("총 수익률은 %.2f%%입니다.\n", yield); -} + + } + + private void outputPurchasedLottos() { + List purchasedLottos = lottoRepository.findAllLotto(); + OutputView.printTicketCount(purchasedLottos.size()); + OutputView.printLottoNumbers(purchasedLottos); + } } From 88c541c4e50859381e32a18de3e333446493e38a Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Thu, 10 Oct 2024 04:09:54 +0900 Subject: [PATCH 40/46] =?UTF-8?q?feat:=20=EB=A1=9C=EB=98=90=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/view/OutputView.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/lotto/view/OutputView.java b/src/main/java/lotto/view/OutputView.java index 9a8f3583..2334d145 100644 --- a/src/main/java/lotto/view/OutputView.java +++ b/src/main/java/lotto/view/OutputView.java @@ -1,5 +1,9 @@ package lotto.view; +import lotto.model.Lotto; + +import java.util.List; + public class OutputView { private static final String TICKET_COUNT = "개를 구매했습니다."; private static final String INPUT_LOTTO_PRICE = "구입금액을 입력해 주세요."; @@ -26,4 +30,8 @@ public static void printErrorMessage(ErrorMessage errorMessage) { System.out.println(errorMessage.getMessage()); } + public static void printLottoNumbers(List purchasedLottos) { + purchasedLottos.forEach(lotto -> System.out.println(lotto.getNumbers())); + } + } From 22ad9ff408c4957e6e92f9ce70ccc4b5821e39b5 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Thu, 10 Oct 2024 04:48:35 +0900 Subject: [PATCH 41/46] Update README.md and other modified files --- docs/README.md | 46 +++++++++++++++++++ src/main/java/lotto/Application.java | 1 - .../lotto/repository/LottoRepositoryImpl.java | 3 +- src/main/java/lotto/service/LottoService.java | 1 - 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/docs/README.md b/docs/README.md index e69de29b..8515766c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -0,0 +1,46 @@ +기능구현 목록 +Model + +Lotto +로또 번호를 저장하고, 번호의 유효성을 검증 + +WinningNumbers +RepostoryImpl에서 사용하기 위해 당첨 번호와 보너스 번호를 임시 저장 + +LottoResult +로또 결과를 관리하고, 당첨된 로또의 개수 및 수익률을 계산 + +Repository + +LottoRepository +로또 구매 및 당첨 번호 저장과 관련된 메서드 정의 + +LottoRepositoryImpl +LottoRepository의 구현체로, 로또 및 당첨 번호를 메모리 내에서 저장하고 관리 + +Service + +LottoService +로또 구매, 당첨 번호 입력, 결과 확인 및 출력과 관련된 비즈니스 로직을 정의 + +LottoServiceImpl +LottoService의 구현체로, 로또 구매 및 결과 확인 로직을 구현. 저장소와 상호작용하여 데이터를 관리 + +View + +InputView +사용자로부터 입력을 받는 역할을 수행. 구입 금액, 당첨 번호, 보너스 번호 등을 입력받음 + +OutputView +출력 메시지를 담당. 로또 구매 결과 및 오류 메시지를 출력하는 기능을 제공. + +Controller + +LottoController +View와 Service간의 중재 역할. 프로그램의 흐름을 관리하고 각 입력에 따라 적절한 서비스를 호출 + +AppConfig +애플리케이션의 구성 정보를 관리. 각 클래스의 인스턴스를 생성하고 의존성 주입을 담당 + +Application +프로그램의 진입점. main 메서드를 포함하고, 애플리케이션을 초기화하여 실행 diff --git a/src/main/java/lotto/Application.java b/src/main/java/lotto/Application.java index c8c4d942..0b8b2367 100644 --- a/src/main/java/lotto/Application.java +++ b/src/main/java/lotto/Application.java @@ -1,6 +1,5 @@ package lotto; - import lotto.controller.LottoController; public class Application { diff --git a/src/main/java/lotto/repository/LottoRepositoryImpl.java b/src/main/java/lotto/repository/LottoRepositoryImpl.java index a50571f6..41d50cd2 100644 --- a/src/main/java/lotto/repository/LottoRepositoryImpl.java +++ b/src/main/java/lotto/repository/LottoRepositoryImpl.java @@ -22,8 +22,9 @@ public List findAllLotto() { @Override public void saveWinningNumbers(WinningNumbers winningNumbers) { - winningNumbersStorage.add(winningNumbers); // 당첨 번호 저장 + winningNumbersStorage.add(winningNumbers); } + @Override public WinningNumbers findWinningNumbers() { return winningNumbersStorage.isEmpty() ? null : winningNumbersStorage.get(winningNumbersStorage.size() - 1); diff --git a/src/main/java/lotto/service/LottoService.java b/src/main/java/lotto/service/LottoService.java index df41ed35..f6fe71f3 100644 --- a/src/main/java/lotto/service/LottoService.java +++ b/src/main/java/lotto/service/LottoService.java @@ -12,5 +12,4 @@ public interface LottoService { void inputWinningNumbers(List winningNumbers, int bonusNumber); void checkAndPrintResults(); - } From 4ef3fc333a6f55d694678a06d74fcb14d4edec3b Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Thu, 10 Oct 2024 13:03:30 +0900 Subject: [PATCH 42/46] =?UTF-8?q?feat:=20readme=20=ED=8C=8C=EC=9D=BC=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 --- README.md | 8 ++++---- docs/README.md | 49 +++++++++++++++++++------------------------------ 2 files changed, 23 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 583580a6..dcdb1f2f 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,13 @@ ## 📮 미션 제출 방법 - 미션 구현을 완료한 후 GitHub을 통해 제출해야 한다. - - 해당 리포지토리를 fork/clone + - 해당 리포지토리를 fork/clone - 미션 구현 - 미션 구현 과정에서 학습한 내용, 고민했던 점 등을 기록한 본인 깃헙 아이디 이름 md파일 작성(ex. 5uhwann.md) - 구현 완료 한 코드는 해당 리포지토리에 pr 작성 - - pr 타이틀: [#주차]객체지향 코드 연습(깃헙 아이디) - - ex. [2주차] 객체지향 코드 연습(TaetaetaE01) - - 미션 구현에서 기록한 md파일은 [COW-Spring-4](https://github.com/COW-edu/COW-Spring-4) 리포지토리에 pr 작성 - 미션 구현 pr 링크 첨부 + - pr 타이틀: [#주차]객체지향 코드 연습(깃헙 아이디) + - ex. [2주차] 객체지향 코드 연습(TaetaetaE01) + - 미션 구현에서 기록한 md파일은 [COW-Spring-4](https://github.com/COW-edu/COW-Spring-4) 리포지토리에 pr 작성 - 미션 구현 pr 링크 첨부 - **해당 리포지토리에만 Pull Request만 보내고 [COW-Spring-4](https://github.com/COW-edu/COW-Spring-4) 리포지토리에 과제를 제출하지 않으면 최종 제출하지 않은 것으로 처리되니 주의한다.** diff --git a/docs/README.md b/docs/README.md index 8515766c..a06d5c97 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,46 +1,35 @@ -기능구현 목록 -Model +# Lotto 프로젝트 -Lotto -로또 번호를 저장하고, 번호의 유효성을 검증 +이 프로젝트는 로또 번호를 관리하고, 구매 및 당첨 결과를 처리하는 애플리케이션입니다. 사용자는 로또를 구매하고, 당첨 번호와 보너스 번호를 입력하여 결과를 확인할 수 있습니다. -WinningNumbers -RepostoryImpl에서 사용하기 위해 당첨 번호와 보너스 번호를 임시 저장 +## 기능 구현 목록 -LottoResult -로또 결과를 관리하고, 당첨된 로또의 개수 및 수익률을 계산 +### Model -Repository +- **Lotto**: 로또 번호를 저장하고, 번호의 유효성을 검증합니다. -LottoRepository -로또 구매 및 당첨 번호 저장과 관련된 메서드 정의 +- **WinningNumbers**: RepositoryImpl에서 사용하기 위해 당첨 번호와 보너스 번호를 임시 저장합니다. -LottoRepositoryImpl -LottoRepository의 구현체로, 로또 및 당첨 번호를 메모리 내에서 저장하고 관리 +- **LottoResult**: 로또 결과를 관리하고, 당첨된 로또의 개수 및 수익률을 계산합니다. -Service +### Repository -LottoService -로또 구매, 당첨 번호 입력, 결과 확인 및 출력과 관련된 비즈니스 로직을 정의 +- **LottoRepository**: 로또 구매 및 당첨 번호 저장과 관련된 메서드를 정의합니다. -LottoServiceImpl -LottoService의 구현체로, 로또 구매 및 결과 확인 로직을 구현. 저장소와 상호작용하여 데이터를 관리 +- **LottoRepositoryImpl**: LottoRepository의 구현체로, 로또 및 당첨 번호를 메모리 내에서 저장하고 관리합니다. -View +### Service -InputView -사용자로부터 입력을 받는 역할을 수행. 구입 금액, 당첨 번호, 보너스 번호 등을 입력받음 +- **LottoService**: 로또 구매, 당첨 번호 입력, 결과 확인 및 출력과 관련된 비즈니스 로직을 정의합니다. -OutputView -출력 메시지를 담당. 로또 구매 결과 및 오류 메시지를 출력하는 기능을 제공. +- **LottoServiceImpl**: LottoService의 구현체로, 로또 구매 및 결과 확인 로직을 구현하며, 저장소와 상호작용하여 데이터를 관리합니다. -Controller +### View -LottoController -View와 Service간의 중재 역할. 프로그램의 흐름을 관리하고 각 입력에 따라 적절한 서비스를 호출 +- **InputView**: 사용자로부터 입력을 받는 역할을 수행하며, 구입 금액, 당첨 번호, 보너스 번호 등을 입력받습니다. -AppConfig -애플리케이션의 구성 정보를 관리. 각 클래스의 인스턴스를 생성하고 의존성 주입을 담당 +- **OutputView**: 출력 메시지를 담당하며, 로또 구매 결과 및 오류 메시지를 출력하는 기능을 제공합니다. -Application -프로그램의 진입점. main 메서드를 포함하고, 애플리케이션을 초기화하여 실행 +### Controller + +- **LottoController**: View와 Service 간의 중재 역할을 수행하며, 프로그램의 흐름을 관리하고 각 입력에 따라 적절한 From 516dd840e7c222ed4894465b195ffdafb02904af Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Thu, 10 Oct 2024 13:15:23 +0900 Subject: [PATCH 43/46] =?UTF-8?q?feat:=20readme=20=ED=8C=8C=EC=9D=BC=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index a06d5c97..13281822 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,6 +1,6 @@ # Lotto 프로젝트 -이 프로젝트는 로또 번호를 관리하고, 구매 및 당첨 결과를 처리하는 애플리케이션입니다. 사용자는 로또를 구매하고, 당첨 번호와 보너스 번호를 입력하여 결과를 확인할 수 있습니다. +-------------------------------------------------------------------------------- ## 기능 구현 목록 From d9d8837590c71951b38a83146223f012aee19f6d Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Thu, 10 Oct 2024 17:22:06 +0900 Subject: [PATCH 44/46] =?UTF-8?q?feat:=20=EC=98=A4=ED=83=80=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/service/LottoServiceImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/lotto/service/LottoServiceImpl.java b/src/main/java/lotto/service/LottoServiceImpl.java index 2bfdb27c..a5156782 100644 --- a/src/main/java/lotto/service/LottoServiceImpl.java +++ b/src/main/java/lotto/service/LottoServiceImpl.java @@ -12,7 +12,7 @@ public class LottoServiceImpl implements LottoService { - private static final int LOOTO_AMOUNT = 1000; + private static final int LOTTO_AMOUNT = 1000; private final LottoRepository lottoRepository; private final LottoResult lottoResult; @@ -27,7 +27,7 @@ public LottoServiceImpl(LottoRepository lottoRepository, LottoResult lottoResult public void purchaseLottos(int amount) { Lotto.validatePurchaseAmount(amount); - int numberOfLotto = amount / LOOTO_AMOUNT; + int numberOfLotto = amount / LOTTO_AMOUNT; IntStream.range(0, numberOfLotto).forEach(i -> { saveLottoNums(Lotto.createRandomLotto()); }); @@ -66,7 +66,7 @@ public void checkAndPrintResults() { } lottoResult.printResult(); - double yield = lottoResult.calculateYield(purchasedLottos.size() * LOOTO_AMOUNT); + double yield = lottoResult.calculateYield(purchasedLottos.size() * LOTTO_AMOUNT); System.out.printf("총 수익률은 %.2f%%입니다.\n", yield); } From 98a560cbfb9aa4dc2b61c768b1ea8d63f77f6074 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Thu, 10 Oct 2024 17:22:18 +0900 Subject: [PATCH 45/46] =?UTF-8?q?feat:=20=EB=82=B4=EC=9A=A9=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 --- docs/README.md | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/docs/README.md b/docs/README.md index 13281822..2b56561b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -6,30 +6,38 @@ ### Model -- **Lotto**: 로또 번호를 저장하고, 번호의 유효성을 검증합니다. +- **Lotto**: 로또 번호를 저장하고, 번호의 유효성을 검증한다. -- **WinningNumbers**: RepositoryImpl에서 사용하기 위해 당첨 번호와 보너스 번호를 임시 저장합니다. +- **WinningNumbers**: RepositoryImpl에서 사용하기 위해 당첨 번호와 보너스 번호를 임시 저장한다. -- **LottoResult**: 로또 결과를 관리하고, 당첨된 로또의 개수 및 수익률을 계산합니다. +- **LottoResult**: 로또 결과를 관리하고, 당첨된 로또의 개수 및 수익률을 계산한다. ### Repository -- **LottoRepository**: 로또 구매 및 당첨 번호 저장과 관련된 메서드를 정의합니다. +- **LottoRepository**: 로또 구매 및 당첨 번호 저장과 관련된 메서드를 정의한다. -- **LottoRepositoryImpl**: LottoRepository의 구현체로, 로또 및 당첨 번호를 메모리 내에서 저장하고 관리합니다. +- **LottoRepositoryImpl**: LottoRepository의 구현체로, 로또 및 당첨 번호를 메모리 내에서 저장하고 관리한다. ### Service -- **LottoService**: 로또 구매, 당첨 번호 입력, 결과 확인 및 출력과 관련된 비즈니스 로직을 정의합니다. +- **LottoService**: 로또 구매, 당첨 번호 입력, 결과 확인 및 출력과 관련된 비즈니스 로직을 정의한다. -- **LottoServiceImpl**: LottoService의 구현체로, 로또 구매 및 결과 확인 로직을 구현하며, 저장소와 상호작용하여 데이터를 관리합니다. +- **LottoServiceImpl**: LottoService의 구현체로, 로또 구매 및 결과 확인 로직을 구현하며, 저장소와 상호작용하여 데이터를 관리한다. ### View -- **InputView**: 사용자로부터 입력을 받는 역할을 수행하며, 구입 금액, 당첨 번호, 보너스 번호 등을 입력받습니다. +- **InputView**: 사용자로부터 입력을 받는 역할을 수행하며, 구입 금액, 당첨 번호, 보너스 번호 등을 입력받는다. -- **OutputView**: 출력 메시지를 담당하며, 로또 구매 결과 및 오류 메시지를 출력하는 기능을 제공합니다. +- **OutputView**: 출력 메시지를 담당하며, 로또 구매 결과 및 오류 메시지를 출력하는 기능을 제공한다. +- +- **ErrorMessage**: 각종 오류 메시지를 enum으로 관리한다. 사용자가 잘못된 입력을 했을 때 적절한 오류 메시지를 출력하여 문제를 안내한다. ### Controller -- **LottoController**: View와 Service 간의 중재 역할을 수행하며, 프로그램의 흐름을 관리하고 각 입력에 따라 적절한 +- **LottoController**: View와 Service 간의 중재 역할을 수행하며, 프로그램의 흐름을 관리하고 각 입력에 따라 적절한 서비스를 호출한다. + +- **AppConfig**: 애플리케이션의 구성 정보를 관리하며, 각 클래스의 인스턴스를 생성하고 의존성 주입을 담당한다. + +- **Application**: 프로그램의 진입점으로, main 메서드를 포함하고 애플리케이션을 초기화하여 실행한다. + + From ae0a4ffd5567789224fe026d923db4453f448fa9 Mon Sep 17 00:00:00 2001 From: Jungsukwoo Date: Thu, 10 Oct 2024 17:24:23 +0900 Subject: [PATCH 46/46] =?UTF-8?q?feat:=20=ED=8C=8C=EC=9D=BC=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 2b56561b..38188c28 100644 --- a/docs/README.md +++ b/docs/README.md @@ -29,15 +29,19 @@ - **InputView**: 사용자로부터 입력을 받는 역할을 수행하며, 구입 금액, 당첨 번호, 보너스 번호 등을 입력받는다. - **OutputView**: 출력 메시지를 담당하며, 로또 구매 결과 및 오류 메시지를 출력하는 기능을 제공한다. -- + - **ErrorMessage**: 각종 오류 메시지를 enum으로 관리한다. 사용자가 잘못된 입력을 했을 때 적절한 오류 메시지를 출력하여 문제를 안내한다. ### Controller - **LottoController**: View와 Service 간의 중재 역할을 수행하며, 프로그램의 흐름을 관리하고 각 입력에 따라 적절한 서비스를 호출한다. +### AppConfig + - **AppConfig**: 애플리케이션의 구성 정보를 관리하며, 각 클래스의 인스턴스를 생성하고 의존성 주입을 담당한다. +### Application + - **Application**: 프로그램의 진입점으로, main 메서드를 포함하고 애플리케이션을 초기화하여 실행한다.