-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCashPayment.java
More file actions
28 lines (24 loc) · 894 Bytes
/
CashPayment.java
File metadata and controls
28 lines (24 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
package cafeteria;
class CashPayment implements Payment {
private double cashDrawerBalance;
public CashPayment(double cashDrawerBalance) {
this.cashDrawerBalance = cashDrawerBalance;
}
@Override
public boolean processPayment(Order order, double amountPaid) throws Exception {
if (amountPaid < 0) {
throw new Exception("Amount cannot be negative.");
}
if (amountPaid >= order.getTotalAmount()) {
double change = amountPaid - order.getTotalAmount();
cashDrawerBalance += order.getTotalAmount();
System.out.println("Payment successful through cash. Change to return: ETB " + change);
return true;
} else {
throw new Exception("Insufficient cash. Try again.");
}
}
public double getCashDrawerBalance() {
return cashDrawerBalance;
}
}