-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProductSelected.java
41 lines (35 loc) · 1.06 KB
/
ProductSelected.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
38
39
40
41
package behavioral.state;
/**
* ----------
* Step 4
* ----------
* Represents the "ProductSelected" state of the vending machine.
*/
class ProductSelected implements State {
private final VendingMachine vendingMachine; // Reference to the vending machine
/**
* Constructs the "ProductSelected" state.
*
* @param vendingMachine The vending machine this state belongs to
*/
public ProductSelected(VendingMachine vendingMachine) {
this.vendingMachine = vendingMachine;
}
@Override
public String getName() {
// Name of the state
return "Product Selected";
}
@Override
public void insertMoney() {
System.out.println("Please select a product - money already inserted.");
}
@Override
public void selectProduct() {
this.vendingMachine.setState(new DispensingProduct(this.vendingMachine)); // Transition to "DispensingProduct" state
}
@Override
public void dispenseProduct() {
System.out.println("Please select a product before dispensing.");
}
}