From 45d2af7714c92fc86d8de3bef20ca4d65b0bc213 Mon Sep 17 00:00:00 2001 From: EunSeop Date: Mon, 16 Sep 2024 16:03:39 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[Feat]=20=EB=A1=9C=EB=98=90=20=EA=B5=AC?= =?UTF-8?q?=EB=A7=A4=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/BuyingLotto.java | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/main/java/lotto/BuyingLotto.java diff --git a/src/main/java/lotto/BuyingLotto.java b/src/main/java/lotto/BuyingLotto.java new file mode 100644 index 0000000000..c306217310 --- /dev/null +++ b/src/main/java/lotto/BuyingLotto.java @@ -0,0 +1,39 @@ +package lotto; + +import camp.nextstep.edu.missionutils.Console; + +public class BuyingLotto { + static int lottoCount; + + public BuyingLotto() { + buyLotto(); + } + + private void buyLotto() { + boolean validInput = false; + + while (!validInput) { + try { + System.out.println("구입금액을 입력해 주세요."); + String input = Console.readLine(); + int money = Integer.parseInt(input); + validateInput(money); + lottoCount = money / 1000; + System.out.println(lottoCount + "개를 구매했습니다."); + validInput = true; + } catch (IllegalArgumentException e) { + System.out.println("[ERROR] 금액은 1000원 단위여야 합니다. 다시 입력해 주세요."); + } + } + } + + public int getLottoCount() { + return lottoCount; + } + + private void validateInput(int money) { + if (money % 1000 == 0) return; + throw new IllegalArgumentException(); + } + +} From 2d3032bd161d83911c8af89f9caf37e689f327d4 Mon Sep 17 00:00:00 2001 From: EunSeop Date: Mon, 16 Sep 2024 16:24:37 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[Feat]=20=EB=A1=9C=EB=98=90=20=EB=A7=8C?= =?UTF-8?q?=EB=93=A4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/lotto/LottoCreator.java | 26 +++++++++++++++++++ src/main/java/lotto/LottoNumberGenerator.java | 24 +++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/main/java/lotto/LottoCreator.java create mode 100644 src/main/java/lotto/LottoNumberGenerator.java diff --git a/src/main/java/lotto/LottoCreator.java b/src/main/java/lotto/LottoCreator.java new file mode 100644 index 0000000000..1ebe5e4e34 --- /dev/null +++ b/src/main/java/lotto/LottoCreator.java @@ -0,0 +1,26 @@ +package lotto; + +import camp.nextstep.edu.missionutils.Randoms; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +public class LottoCreator { + private List lottoList; + + public LottoCreator(int count) { + createLotto(count); + } + + private void createLotto(int count) { + lottoList = IntStream.range(0, count) + .mapToObj(i -> new Lotto(LottoNumberGenerator.generateLottoNumber())) + .collect(Collectors.toList()); + + } + + public List getLottoList() { + return lottoList; + } +} diff --git a/src/main/java/lotto/LottoNumberGenerator.java b/src/main/java/lotto/LottoNumberGenerator.java new file mode 100644 index 0000000000..c2c666c5dd --- /dev/null +++ b/src/main/java/lotto/LottoNumberGenerator.java @@ -0,0 +1,24 @@ +package lotto; + +import camp.nextstep.edu.missionutils.Randoms; + +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Random; + +public class LottoNumberGenerator { + private static final int MAX_NUM = 45; + private static final int MIN_NUM = 1; + private static final int COUNT = 6; + + private LottoNumberGenerator() { + throw new UnsupportedOperationException("Utility class"); + } + + public static List generateLottoNumber() { + List numbers = Randoms.pickUniqueNumbersInRange(MIN_NUM, MAX_NUM, COUNT); + Collections.sort(numbers); + return numbers; + } +}