-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
Copy pathDispenseState.java
37 lines (30 loc) · 1.23 KB
/
DispenseState.java
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;
public class DispenseState implements VendingMachineState {
private final VendingMachine vendingMachine;
public DispenseState(VendingMachine vendingMachine) {
this.vendingMachine = vendingMachine;
}
@Override
public void selectProduct(Product product) {
System.out.println("Product already selected. Please collect the dispensed product.");
}
@Override
public void insertCoin(Coin coin) {
System.out.println("Payment already made. Please collect the dispensed product.");
}
@Override
public void insertNote(Note note) {
System.out.println("Payment already made. Please collect the dispensed product.");
}
@Override
public void dispenseProduct() {
Product product = vendingMachine.getSelectedProduct();
vendingMachine.inventory.updateQuantity(product, vendingMachine.inventory.getQuantity(product) - 1);
System.out.println("Product dispensed: " + product.getName());
vendingMachine.setState(vendingMachine.getReturnChangeState()); // Change the state to ReturnChangeState
}
@Override
public void returnChange() {
System.out.println("Please collect the dispensed product first.");
}
}