Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/main/java/lotto/BuyingLotto.java
Original file line number Diff line number Diff line change
@@ -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();
}

}