MCPcopy Create free account
hub / github.com/Anchals24/Low-Level-Design / IdleState

Class IdleState

StateDesignPattern/VendingMachineStates/IdleState.java:10–61  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8import java.util.List;
9
10public class IdleState implements States{
11
12 public IdleState(){
13 System.out.println("Currently Vending machine is in Idle State");
14 }
15
16 public IdleState(VendingMachine machine){
17 System.out.println("Currently Vending machine is in Idle State");
18 //query
19 machine.setCoinList(new ArrayList<>());
20
21 }
22
23 @Override
24 public void clickOnInsertCoinButton(VendingMachine machine) throws Exception {
25 machine.setVendingMachineState(new HasMoneyState());
26 }
27
28 @Override
29 public void insertCoin(VendingMachine machine, Coin coin) throws Exception{
30 throw new Exception("you can not insert Coin in idle state");
31
32 }
33
34 @Override
35 public void clickOnStartProductSelectionButton(VendingMachine machine) throws Exception {
36 throw new Exception("first you need to click on insert coin button");
37
38 }
39
40 @Override
41 public void chooseProduct(VendingMachine machine, int codeNumber) throws Exception{
42 throw new Exception("you can not choose a product in idle state");
43
44 }
45
46 @Override
47 public int getChange(int returnChangeMoney) throws Exception{
48 throw new Exception("you can not get the change in idle state");
49 }
50
51 @Override
52 public Item dispenseProduct(VendingMachine machine, int codeNumber) throws Exception{
53 throw new Exception("you can not dispense the product in idle state");
54 }
55
56 @Override
57 public List<Coin> refundFullMoney(VendingMachine machine) throws Exception{
58 throw new Exception("Money can't get refunded in the idle state");
59 }
60
61}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected