Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.19 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4.  
  5. public class CoffeeMachine {
  6.     static public void checkNeed(int b, int w, int m, int s, int mo) {
  7.         if (water >= w && beans >= b && milk >= m && cups >= s) {
  8.             water = water - w;
  9.             beans = beans - b;
  10.             milk = milk - m;
  11.             cups = cups - s;
  12.             money = money + mo;
  13.             System.out.println("I have enough resources, making you a coffee!");
  14.         } else {
  15.             System.out.print("Sorry, not enough");
  16.             if (water < w) {
  17.                 System.out.print(" water");
  18.             } else if (milk < m) {
  19.                 System.out.println(" milk");
  20.             } else if (beans < b) {
  21.                 System.out.println(" beans");
  22.             } else if (cups < s) {
  23.                 System.out.println(" cups");
  24.             }
  25.             System.out.println("!");
  26.         }
  27.  
  28.  
  29.     }
  30.  
  31.     static public void writeInfo() {
  32.         System.out.println("The coffee machine has:");
  33.         System.out.println(water + " of waters");
  34.         System.out.println(milk + " of milk");
  35.         System.out.println(beans + " of beans");
  36.         System.out.println(cups + " of cups");
  37.         System.out.println(money + " of money");
  38.     }
  39.  
  40.     static int water = 1200;
  41.     static int milk = 540;
  42.     static int beans = 120;
  43.     static int cups = 9;
  44.     static int money = 550;
  45.  
  46.     public static void main(String[] args) {
  47.  
  48.  
  49.         Scanner scanner = new Scanner(System.in);
  50.  
  51.  
  52.         String n = "";
  53.         do {
  54.             System.out.println("Write action (buy, fill, take, remaining, action): \n");
  55.             n = scanner.next();
  56.  
  57.  
  58.             if (n.equals("buy")) {
  59.                 System.out.println("What do you want to buy? 1 - espresso, 2 - latte, 3 - cappuccino, back - to main menu: \n");
  60.  
  61.  
  62.                 String ch = scanner.next();
  63.                 if (ch == "1") {
  64.                     checkNeed(16, 250, 0, 1, 4);
  65.  
  66.                 } else if (ch == "2") {
  67.                     checkNeed(20, 350, 75, 1, 7);
  68.  
  69.  
  70.                 } else if (ch == "3") {
  71.                     checkNeed(12, 200, 100, 1, 6);
  72.  
  73.                 } else if (ch == "back") {
  74.  
  75.                 }
  76.             } else if (n.equals("fill")) {
  77.                 System.out.println("Write how many ml of water do you want to add: ");
  78.                 int wat = scanner.nextInt();
  79.                 water = water + wat;
  80.                 System.out.println("Write how many ml of milk do you want to add: ");
  81.                 int mil = scanner.nextInt();
  82.                 milk = milk + mil;
  83.                 System.out.println("Write how many grams of coffee beans do you want to add: ");
  84.                 int bean = scanner.nextInt();
  85.                 beans = beans + bean;
  86.                 System.out.println("Write how many disposable cups of coffee do you want to add: ");
  87.                 int cup = scanner.nextInt();
  88.                 cups = cups + cup;
  89.  
  90.             } else if (n.equals("take")) {
  91.                 System.out.println("I gave you $" + money);
  92.                 money = 0;
  93.  
  94.             } else if (n.equals("remaining")) {
  95.                 writeInfo();
  96.             }
  97.         } while (!n.equals("exit"));
  98.  
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement