diff --git a/CoffeeMachine.java b/CoffeeMachine.java index e53d184..73ea27e 100644 --- a/CoffeeMachine.java +++ b/CoffeeMachine.java @@ -1,153 +1,164 @@ -//package machine; -// -//import java.util.Scanner; -// -//public class CoffeeMachine { -// public static void main(String[] args) { -// Scanner scanner = new Scanner(System.in); -// -// int count = 0; -// -// while (true) { -// -// System.out.println("Write Action (buy, fill, take, remaining, exit)"); -// String action = scanner.nextLine(); -// -// count += 1; -// -// if (action.equals("buy")) { -// if (count > 1) { -// System.out.println("What do you want to buy? 1 - espresso, 2 - latte, 3 - cappuccino, back-to main menu"); -// } else { -// System.out.println("What do you want to buy? 1 - espresso, 2 - latte, 3 - cappuccino:"); -// } -// String orderOption = scanner.nextLine(); -// Buy(orderOption); -// } else if (action.equals("fill")) { -// System.out.println("Write how many ml of water you want to add:"); -// int waterRequired = scanner.nextInt(); -// System.out.println("Write how many ml of milk you want to add:"); -// int milkRequired = scanner.nextInt(); -// System.out.println("Write how many g of coffee beans you want to add:"); -// int coffeeRequired = scanner.nextInt(); -// System.out.println("Write how many disposable cups you want to add:"); -// int cupsRequired = scanner.nextInt(); -// fill(waterRequired, milkRequired, coffeeRequired, cupsRequired); -// } else if (action.equals("remaining")) { -// remaining(); -// } else if (action.equals("exit")) { -// break; -// } else if (action.equals("take")) { -// take(); -// } else if (action.equals("Back")) { -// continue; -// } else { -// continue; -// } -// } -// -// } -// -// static int intialAmountOfWater = 400; -// static int intialAmountofMilk = 540; -// static int intialAmountofCoffeBeans = 120; -// static int intialAmountOfCups = 9; -// static int intialAmountOfMoney = 550; -// -// public static void Buy(String CoffeeType) { -// if (CoffeeType.equals("1")) { -// checkEspresso(); -// } else if (CoffeeType.equals("2")) { -// checkLatte(); -// } else if (CoffeeType.equals("3")) { -// checkCappunicino(); -// } else { -// System.out.println("Invalid input. Enter a number"); -// } -// } -// -// public static void fill(int water, int milk, int coffee, int cups) { -// intialAmountOfWater += water; -// intialAmountofMilk += milk; -// intialAmountofCoffeBeans += coffee; -// intialAmountOfCups += cups; -// intialAmountOfMoney += 0; -// } -// -// public static void take() { -// System.out.println("I gave you " + (intialAmountOfMoney)); -// intialAmountOfMoney -= intialAmountOfMoney; -// } -// -// public static void remaining() { -// System.out.println("This coffee machine has:"); -// System.out.println((intialAmountOfWater) + " ml of water"); -// System.out.println((intialAmountofMilk) + " ml of milk"); -// System.out.println((intialAmountofCoffeBeans) + " g of coffee beans"); -// System.out.println((intialAmountOfCups) + " disposable cups"); -// System.out.println("$" + (intialAmountOfMoney) + " of money"); -// } -// -// public static void checkEspresso() { -// if (intialAmountOfWater < 250) { -// System.out.println("Sorry, not enough water!"); -// } else if (intialAmountofCoffeBeans < 16) { -// System.out.println("Sorry, not enough coffee!"); -// } else { -// System.out.println("I have enough resources, making you a coffee"); -// intialAmountOfWater -= 250; -// intialAmountofCoffeBeans -= 16; -// intialAmountOfCups -= 1; -// intialAmountOfMoney += 4; -// } -// } -// -// public static void checkLatte() { -// if (intialAmountOfWater < 350) { -// System.out.println("Sorry, not enough water!"); -// } else if (intialAmountofMilk < 75) { -// System.out.println("Sorry, not enough milk!"); -// } else if (intialAmountofCoffeBeans < 20) { -// System.out.println("Sorry, not enough coffee!"); -// } else { -// System.out.println("I have enough resources, making you a coffee"); -// intialAmountOfWater -= 350; -// intialAmountofMilk -= 75; -// intialAmountofCoffeBeans -= 20; -// intialAmountOfCups -= 1; -// intialAmountOfMoney += 7; -// } -// } -// -// public static void checkCappunicino() { -// if (intialAmountOfWater < 350) { -// System.out.println("Sorry, not enough water!"); -// } else if (intialAmountofMilk < 75) { -// System.out.println("Sorry, not enough milk!"); -// } else if (intialAmountofCoffeBeans < 20) { -// System.out.println("Sorry, not enough coffee!"); -// } else { -// System.out.println("I have enough resources, making you a coffee"); -// intialAmountOfWater -= 200; -// intialAmountofMilk -= 100; -// intialAmountofCoffeBeans -= 12; -// intialAmountOfCups -= 1; -// intialAmountOfMoney += 6; -// } -// } -// -// -//} -// - package machine; import java.util.Scanner; public class CoffeeMachine { + private static final Scanner scanner = new Scanner(System.in); + private static int water = 400; + private static int milk = 540; + private static int coffeeBeans = 120; + private static int cups = 9; + private static int money = 550; + + public static void printResources() { + System.out.println("The coffee machine has"); + System.out.println(water + " ml of water"); + System.out.println(milk + " ml of milk"); + System.out.println(coffeeBeans + " g of coffee beans"); + System.out.println(cups + " disposable cups"); + System.out.println("$" + money + " of money"); + System.out.println(); + } + + public static void buyCappuccino() { + processDrink(200, 100, 12, 6); + } + + public static void buyLatte() { + processDrink(350, 75, 20, 7); + } + + public static void buyEspresso() { + processDrink(250, 0, 16, 4); + } + + public static void processDrink(int waterPerCup, int milkPerCup, int coffeeBeansPerCup, int moneyTaken) { + + if (water < waterPerCup) { + System.out.println("Sorry, not enough water!"); + } else if (milk < milkPerCup) { + System.out.println("Sorry, not enough milk!"); + } else if (coffeeBeans < coffeeBeansPerCup) { + System.out.println("Sorry, not enough coffee beans!"); + } else if (cups < 1) { + System.out.println("Sorry, not enough disposable cups!"); + } else { + water -= waterPerCup; + milk -= milkPerCup; + coffeeBeans -= coffeeBeansPerCup; + money += moneyTaken; + cups--; + System.out.println("I have enough resources, making you a coffee!"); + } + + System.out.println(); + } + + public static void Buy(String coffeeType) { + switch (coffeeType) { + case "1": + buyEspresso(); + break; + case "2": + buyLatte(); + break; + case "3": + buyCappuccino(); + break; + case "back": + return; + default: + break; + } + } + + public static void fillResources() { + int waterAdded = getWater(); + int milkAdded = getMilk(); + int coffeeAdded = getCoffee(); + int cupsAdded = getCups(); + + water += waterAdded; + milk += milkAdded; + coffeeBeans += coffeeAdded; + cups += cupsAdded; + + System.out.println(); + + } + + public static void takeMoney() { + System.out.println("I gave you $" + money); + money = 0; + + System.out.println(); + } + + public static String getCoffeeType() { + System.out.println("What do you want to buy? 1 - espresso, 2 - latte, 3 - cappuccino, back - to main menu:"); + return scanner.nextLine(); + } + + public static int getWater() { + System.out.println("Write how many ml of water you want to add: "); + return Integer.parseInt(scanner.nextLine()); + } + + public static int getMilk() { + System.out.println("Write how many ml of milk you want to add: "); + return Integer.parseInt(scanner.nextLine()); + } + + public static int getCoffee() { + System.out.println("Write how many grams of coffee beans you want to add:"); + return Integer.parseInt(scanner.nextLine()); + } + + public static int getCups() { + System.out.println("Write how many disposable cups you want to add: "); + return Integer.parseInt(scanner.nextLine()); + } + + public static String mainMenu() { + System.out.println("Write action (buy, fill, take, remaining, exit):"); + return scanner.nextLine(); + } + + + public static void main(String[] args) { + + while (true) { + + String action = mainMenu(); + + System.out.println(); + + switch (action) { + case "buy": + String coffeeType = getCoffeeType(); + Buy(coffeeType); + break; + case "fill": + fillResources(); + break; + case "take": + takeMoney(); + break; + case "remaining": + printResources(); + break; + case "exit": + System.exit(0); + break; + default: + break; + } + } + } } +