-
Notifications
You must be signed in to change notification settings - Fork 351
Expand file tree
/
Copy pathMoney.java
More file actions
37 lines (29 loc) · 822 Bytes
/
Copy pathMoney.java
File metadata and controls
37 lines (29 loc) · 822 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
36
37
package vendingmachine;
import vendingmachine.message.ExceptionMessage;
public class Money {
private int amount;
public Money(int amount) {
validate(amount);
this.amount = amount;
}
private void validate(int amount) {
if (amount < 0) {
throw new IllegalArgumentException(ExceptionMessage.NUMBER_FORMAT);
}
}
public boolean isMoreOrEqualThen(int amount) {
return this.amount >= amount;
}
public boolean isLessThen(int amount) {
return this.amount < amount;
}
public void minus(int amount) {
if (this.amount - amount < 0) {
throw new IllegalArgumentException(ExceptionMessage.LACK_MONEY);
}
this.amount -= amount;
}
public int getAmount() {
return amount;
}
}