-
Notifications
You must be signed in to change notification settings - Fork 351
Expand file tree
/
Copy pathMachineAmount.java
More file actions
35 lines (26 loc) · 894 Bytes
/
MachineAmount.java
File metadata and controls
35 lines (26 loc) · 894 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 vendingmachine;
import utils.ErrorMessages;
public class MachineAmount {
private static final int MINIMUM_MONEY = 100;
private static final int DIVISIBLE_AMOUNT = 10;
private static final int ZERO = 0;
private final int money;
public MachineAmount(int money) {
validateMinimumAmount(money);
validateDivideByTen(money);
this.money = money;
}
public int getMoney() {
return money;
}
private void validateMinimumAmount(int amount) {
if (amount < MINIMUM_MONEY) {
throw new IllegalArgumentException(ErrorMessages.VALIDATE_MINIMUM_RANGE.getErrorMessage());
}
}
private void validateDivideByTen(int amount) {
if (amount % DIVISIBLE_AMOUNT != ZERO){
throw new IllegalArgumentException(ErrorMessages.VALIDATE_DIVIDE_BY_TEN.getErrorMessage());
}
}
}