-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathVendingMachine.java
21 lines (18 loc) · 977 Bytes
/
VendingMachine.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package office;
import payment.ElectronicPayment;
public class VendingMachine {
public String buy(Product product, ElectronicPayment payment) {
String response = "\n[MACHINE] You have selected «" + product.getName().toUpperCase()
+ "». Please, pay through our highly secure online system.\n";
if (Boolean.TRUE.equals(payment.isChargeable(product.getPrice()))) {
response += payment.charge(product.getPrice(), "«Vending machine's " + product.getName() + "»");
response += String.format("%n[MACHINE] Payment of %.2f € received. Enjoy your %s!"
, product.getPrice(), product.getName());
} else {
response = String.format("%n[MACHINE] Unable to charge %.2f €. Please, check your founds " +
"and make sure your electronic payment method is enabled."
, product.getPrice());
}
return response + "\n";
}
}