Skip to content

Instantly share code, notes, and snippets.

@azzumw
Created February 7, 2021 14:50
Show Gist options
  • Save azzumw/21532d5d6e61a49cf9b680fc0b6f14eb to your computer and use it in GitHub Desktop.
Save azzumw/21532d5d6e61a49cf9b680fc0b6f14eb to your computer and use it in GitHub Desktop.
Menu PrcessMenuOption method
private void processMenuOption(int optionEntered){
VendingMachine vm = VendingMachine.getInstance();
switch (optionEntered){
case 1: System.out.println("Current Products Available");
setMenuOptions(vm.getProducts());
int optionSelected = displayMenu();
vm.purchaseProduct(vm.getProducts().get(optionSelected-1),in);
//re-display Main Menu
setMenuOptions(itemArrayList);
processMenuOption(displayMenu());
break;
case 2: vm.addProduct(new Product("Dummy",4.00,1));
System.out.println(ProductInventory.getProductInventory().get(ProductInventory.getProductInventory().size()-1).getName());break;
case 3:
case 4: System.exit(0);
default:System.out.println("default");
}
}
@azzumw
Copy link
Author

azzumw commented Feb 7, 2021

@adil - this is the getInstance Method in VendingMachine:

static VendingMachine getInstance(){
if(vm == null){
synchronized (VendingMachine.class){
vm = new VendingMachine();
}
}
return vm;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment