diff --git a/src/main/java/lotto/BuyingLotto.java b/src/main/java/lotto/BuyingLotto.java new file mode 100644 index 00000000000..c306217310f --- /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(); + } + +} diff --git a/src/main/java/lotto/LottoCreator.java b/src/main/java/lotto/LottoCreator.java new file mode 100644 index 00000000000..1ebe5e4e348 --- /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 00000000000..c2c666c5ddc --- /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; + } +}