-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathManualLottoCount.java
More file actions
35 lines (27 loc) · 1022 Bytes
/
ManualLottoCount.java
File metadata and controls
35 lines (27 loc) · 1022 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package lotto;
public class ManualLottoCount {
private static final String ERROR_NEGATIVE_COUNT = "수동 로또 수량은 0 이상이어야 합니다.";
private static final String ERROR_EXCEED_PURCHASE = "수동 장수는 구입 가능한 수량을 초과할 수 없습니다.";
private final int count;
public ManualLottoCount(int count, int purchaseAmount) {
this(count, new PurchaseAmount(purchaseAmount));
}
public ManualLottoCount(int count, PurchaseAmount amount) {
validateNonNegativeCount(count);
validateNotExceedPurchaseAmount(count, amount);
this.count = count;
}
public int count() {
return count;
}
private static void validateNonNegativeCount(int count) {
if (count < 0) {
throw new IllegalArgumentException(ERROR_NEGATIVE_COUNT);
}
}
private static void validateNotExceedPurchaseAmount(int count, PurchaseAmount amount) {
if (amount.ticketCount() < count) {
throw new IllegalArgumentException(ERROR_EXCEED_PURCHASE);
}
}
}