From 45d2af7714c92fc86d8de3bef20ca4d65b0bc213 Mon Sep 17 00:00:00 2001 From: EunSeop Date: Mon, 16 Sep 2024 16:03:39 +0900 Subject: [PATCH] =?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(); + } + +}