-
Notifications
You must be signed in to change notification settings - Fork 351
Expand file tree
/
Copy pathInputAmount.java
More file actions
37 lines (29 loc) · 1.04 KB
/
Copy pathInputAmount.java
File metadata and controls
37 lines (29 loc) · 1.04 KB
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
36
37
package vendingmachine.domain;
import vendingmachine.constants.Constants;
public class InputAmount {
private static final int MIN_INPUT_AMOUNT = 10;
private static final int INPUT_AMOUNT_UNIT = 10;
private int amount;
public InputAmount(int amount) {
validate(amount);
this.amount = amount;
}
private void validate(int amount) {
if (amount < MIN_INPUT_AMOUNT) {
throw new IllegalArgumentException(
String.format("%s 투입 금액은 %d원 이상이어야 합니다.",
Constants.ERROR_PREFIX.getValue(), MIN_INPUT_AMOUNT));
}
if (amount % INPUT_AMOUNT_UNIT != 0) {
throw new IllegalArgumentException(
String.format("%s 투입 금액은 %d원 단위만 가능합니다.",
Constants.ERROR_PREFIX.getValue(), INPUT_AMOUNT_UNIT));
}
}
public void decrease(int amount) {
this.amount -= amount;
}
public int getAmount() {
return amount;
}
}