Advertisement
uriahheep

Untitled

Jun 16th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.40 KB | None | 0 0
  1. package machine;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class CoffeeMachine {
  6.     int waterAmount;
  7.     int milkAmount;
  8.     int beansAmount;
  9.     int cupsAmount;
  10.     int money;
  11.  
  12.     public CoffeeMachine (int waterAmount, int milkAmount, int beansAmount, int cupsAmount, int money){
  13.         this.waterAmount = waterAmount;
  14.         this.milkAmount = milkAmount;
  15.         this.beansAmount = beansAmount;
  16.         this.cupsAmount = cupsAmount;
  17.         this.money = money;
  18.  
  19.     }
  20.  
  21.  
  22.     public static void main(String[] args) {
  23.         Scanner in = new Scanner(System.in);
  24.         CoffeeMachine machine = new CoffeeMachine(400, 540, 120, 9, 550);
  25.  
  26.         machine.systemCheck();
  27.         System.out.println("Write action (buy, fill, take): ");
  28.         String action = in.next();
  29.         switch (action) {
  30.             case "buy":
  31.                 machine.buyDrink();
  32.                 break;
  33.             case "fill":
  34.                 machine.fillMachine();
  35.                 break;
  36.             case "take":
  37.                 machine.getCash();
  38.                 break;
  39.             default:
  40.                 System.out.println("Wrong choice!");
  41.         }
  42.  
  43.         machine.systemCheck();
  44.  
  45.  
  46.     }
  47.  
  48.     public void systemCheck() {
  49.         System.out.println("The coffee machine has: ");
  50.         System.out.println(this.waterAmount + "of water");
  51.         System.out.println(this.milkAmount + "of milk");
  52.         System.out.println(this.beansAmount + "of beans");
  53.         System.out.println(this.cupsAmount + "of disposable cups");
  54.         System.out.println(this.money + "of money");
  55.     }
  56.  
  57.  
  58.     public void buyDrink() {
  59.         Scanner in = new Scanner(System.in);
  60.         System.out.println("What do you want to buy? 1 - espresso, 2 - latte, 3 - cappuccino: ");
  61.         int choice = in.nextInt();
  62.         switch (choice) {
  63.             case 1:
  64.                 if (this.waterAmount >= 250 && this.beansAmount >= 16 && this.cupsAmount > 0) {
  65.                     this.waterAmount = this.waterAmount - 250;
  66.                     this.beansAmount = this.beansAmount - 16;
  67.                     this.money = this.money + 4;
  68.                     this.cupsAmount = this.cupsAmount - 1;
  69.                 } else
  70.                     System.out.println("Not enough ingredients, fill the machine please");
  71.                 break;
  72.             case 2:
  73.                 if (this.waterAmount >= 350 && this.milkAmount >= 75 && this.beansAmount >= 20 && this.cupsAmount > 0) {
  74.                     this.waterAmount = this.waterAmount - 350;
  75.                     this.milkAmount = this.milkAmount - 75;
  76.                     this.beansAmount = this.beansAmount - 20;
  77.                     this.money = this.money + 7;
  78.                     this.cupsAmount = this.cupsAmount - 1;
  79.                 } else
  80.                     System.out.println("Not enough ingredients, fill the machine please");
  81.                 break;
  82.             case 3:
  83.                 if (this.waterAmount >= 200 && this.milkAmount >= 100 && this.beansAmount >= 12 && this.cupsAmount > 0) {
  84.                     this.waterAmount = this.waterAmount - 200;
  85.                     this.milkAmount = this.milkAmount - 100;
  86.                     this.money = this.money - 6;
  87.                     this.beansAmount = this.beansAmount - 12;
  88.                     this.cupsAmount = this.cupsAmount - 1;
  89.                 } else
  90.                     System.out.println("Not enough ingredients, fill the machine please");
  91.                 break;
  92.             default:
  93.                 System.out.println("Wrong choice!");
  94.  
  95.         }
  96.  
  97.     }
  98.  
  99.     public void fillMachine() {
  100.         Scanner in = new Scanner(System.in);
  101.         System.out.println("How many ml of water do you want to add: ");
  102.         int water = in.nextInt();
  103.         System.out.println("How many ml of milk do you want to add: ");
  104.         int milk = in.nextInt();
  105.         System.out.println("How many grams of coffee beans do you want to add: ");
  106.         int beans = in.nextInt();
  107.         System.out.println("How many disposable cups do you want to add: ");
  108.         int cups = in.nextInt();
  109.  
  110.  
  111.         this.waterAmount = this.waterAmount + water;
  112.         this.milkAmount = this.milkAmount + milk;
  113.         this.beansAmount = this.beansAmount + beans;
  114.         this.cupsAmount = this.cupsAmount + cups;
  115.  
  116.  
  117.     }
  118.  
  119.     public void getCash() {
  120.         System.out.println("I gave you " + this.money + " of money");
  121.         this.money = 0;
  122.  
  123.  
  124.     }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement