Skip to content

Instantly share code, notes, and snippets.

@MikeMnD
Last active November 14, 2019 15:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikeMnD/a40f2d5cd1df9bb96d9249e881f3e8be to your computer and use it in GitHub Desktop.
Save MikeMnD/a40f2d5cd1df9bb96d9249e881f3e8be to your computer and use it in GitHub Desktop.
package machine;
import java.util.Scanner;
public class CoffeeMachine {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("The coffee machine has:");
int availableWater = 1200;
int availableMIlk = 540;
int availableCoffee = 120;
int availableCups = 9;
int availableMoney = 550;
//espresso ingredients:
int espressoWater = 250, espressoBeans = 16;
//latte ingredients:
int latteWater = 350, latteMilk = 75, latteBeans = 20;
//cappuccino ingredients:
int cappuccinoWater = 200, cappuccinoMilk = 100, cappuccinoBeans = 12;
//prices:
int espressoPrice = 4, lattePrice = 7, cappuccinoPrice = 6;
System.out.println(availableWater + " of water");
System.out.println(availableMIlk + " of milk");
System.out.println(availableCoffee + " of coffee beans");
System.out.println(availableCups + " of disposable cups");
System.out.println(availableMoney + " of money");
System.out.println("Write action (buy, fill, take):");
String menuChoice = scanner.nextLine();
switch (menuChoice){
case "buy":
System.out.println("What do you want to buy? 1 - espresso, 2 - latte, 3 - cappuccino:");
int beverageChoice = scanner.nextInt();
switch (beverageChoice){
case 1:
availableWater -= espressoWater;
availableCoffee -= espressoBeans;
availableMoney += espressoPrice;
availableCups--;
break;
case 2:
availableWater -= latteWater;
availableCoffee -= latteBeans;
availableMIlk -= latteMilk;
availableMoney += lattePrice;
availableCups--;
break;
case 3:
availableWater -= cappuccinoWater;
availableCoffee -= cappuccinoBeans;
availableMIlk -= cappuccinoMilk;
availableMoney += cappuccinoPrice;
availableCups--;
break;
}
System.out.println("The coffee machine has:");
System.out.println(availableWater + " of water");
System.out.println(availableMIlk + " of milk");
System.out.println(availableCoffee + " of coffee beans");
System.out.println(availableCups + " of disposable cups");
System.out.println(availableMoney + " of money");
break;
case "fill":
System.out.println("Write how many ml of water do you want to add: ");
availableWater += scanner.nextInt();
System.out.println("Write how many ml of milk do you want to add: ");
availableMIlk += scanner.nextInt();
System.out.println("Write how many grams of coffee beans do you want ");
availableCoffee += scanner.nextInt();
System.out.println("Write how many disposable cups of coffee do you want to add: ");
availableCups += scanner.nextInt();
System.out.println("The coffee machine has:");
System.out.println(availableWater + " of water");
System.out.println(availableMIlk + " of milk");
System.out.println(availableCoffee + " of coffee beans");
System.out.println(availableCups + " of disposable cups");
System.out.println(availableMoney + " of money");
break;
case "take":
System.out.println("I gave you "+availableMoney);
availableMoney = 0;
System.out.println("The coffee machine has:");
System.out.println(availableWater + " of water");
System.out.println(availableMIlk + " of milk");
System.out.println(availableCoffee + " of coffee beans");
System.out.println(availableCups + " of disposable cups");
System.out.println(availableMoney + " of money");
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment