| 4 | import BehaviouralDesignPatterns.StateDesignPattern.VendingMachineStates.States; |
| 5 | |
| 6 | public class Main { |
| 7 | |
| 8 | public static void main(String args[]){ |
| 9 | |
| 10 | VendingMachine vendingMachine = new VendingMachine(); |
| 11 | try { |
| 12 | |
| 13 | System.out.println("|"); |
| 14 | System.out.println("filling up the inventory"); |
| 15 | System.out.println("|"); |
| 16 | |
| 17 | fillUpInventory(vendingMachine); |
| 18 | displayInventory(vendingMachine); |
| 19 | |
| 20 | System.out.println("|"); |
| 21 | System.out.println("clicking on InsertCoinButton"); |
| 22 | System.out.println("|"); |
| 23 | |
| 24 | States vendingState = vendingMachine.getVendingMachineState(); |
| 25 | vendingState.clickOnInsertCoinButton(vendingMachine); |
| 26 | |
| 27 | vendingState = vendingMachine.getVendingMachineState(); |
| 28 | vendingState.insertCoin(vendingMachine, Coin.NICKEL); |
| 29 | vendingState.insertCoin(vendingMachine, Coin.QUARTER); |
| 30 | // vendingState.insertCoin(vendingMachine, Coin.NICKEL); |
| 31 | |
| 32 | System.out.println("|"); |
| 33 | System.out.println("clicking on ProductSelectionButton"); |
| 34 | System.out.println("|"); |
| 35 | vendingState.clickOnStartProductSelectionButton(vendingMachine); |
| 36 | |
| 37 | vendingState = vendingMachine.getVendingMachineState(); |
| 38 | vendingState.chooseProduct(vendingMachine, 102); |
| 39 | |
| 40 | displayInventory(vendingMachine); |
| 41 | |
| 42 | } |
| 43 | catch (Exception e){ |
| 44 | displayInventory(vendingMachine); |
| 45 | } |
| 46 | |
| 47 | |
| 48 | } |
| 49 | |
| 50 | private static void fillUpInventory(VendingMachine vendingMachine){ |
| 51 | Inventory inventory = vendingMachine.getInventory(); |
| 52 | ItemShelf[] slots = inventory.getItemShelves(); |
| 53 | for (int i = 0; i < slots.length; i++) { |
| 54 | Item newItem = new Item(); |
| 55 | if(i >=0 && i<3) { |
| 56 | newItem.setType(ItemType.COKE); |
| 57 | newItem.setPrice(12); |
| 58 | }else if(i >=3 && i<5){ |
| 59 | newItem.setType(ItemType.PEPSI); |
| 60 | newItem.setPrice(9); |
| 61 | }else if(i >=5 && i<7){ |
| 62 | newItem.setType(ItemType.JUICE); |
| 63 | newItem.setPrice(13); |
nothing calls this directly
no outgoing calls
no test coverage detected