-
Notifications
You must be signed in to change notification settings - Fork 351
Expand file tree
/
Copy pathCredit.java
More file actions
35 lines (27 loc) · 779 Bytes
/
Credit.java
File metadata and controls
35 lines (27 loc) · 779 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 vendingmachine.exception.VendingMachineException;
import vendingmachine.menu.Menu;
public class Credit {
private int money;
public Credit(int money){
validateMoney(money);
this.money = money;
}
private void validateMoney(int money) {
if(money < 100 || money % 10 != 0){
throw VendingMachineException.INVALID_MONEY_VALUE.makeException();
}
}
public boolean canPurchase(int price){
return money >= price;
}
public void purchase(Menu menu){
if(menu.getPrice() > money){
throw VendingMachineException.CANT_PURCHASE.makeException();
}
money -= menu.getPrice();
}
public int getMoney() {
return money;
}
}