-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoffeeMachine.java
More file actions
140 lines (122 loc) · 5.08 KB
/
CoffeeMachine.java
File metadata and controls
140 lines (122 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package machine;
import java.util.Scanner;
public class CoffeeMachine {
static int water = 400;
static int milk = 540;
static int beans = 120;
static int money = 550;
static int disCups = 9;
public static void main(String[] args) {
action();
}
public static void action () {
System.out.println("Write action (buy, fill, take, remaining, exit):");
Scanner sc=new Scanner(System.in);
String action=sc.next();
switch (action){
case "buy":
Buy();
break;
case "fill":
fill();
break;
case "take":
take();
break;
case "remaining":
remaining();
break;
case "exit":
exit();
break;
}
}
public static void Buy () {
System.out.println("What do you want to buy? 1 - espresso, 2 - latte, 3 - cappuccino, back - to main menu:");
Scanner scanner = new Scanner(System.in);
String str = scanner.nextLine();
switch (str) {
case "1":
if (water >= 250 && beans >= 16 && disCups > 0) {
System.out.println("I have enough resources, making you a coffee!");
water -= 250;
beans -= 16;
disCups -= 1;
money += 4;
} else if (water < 250) {
System.out.println("Sorry, not enough water !");
} else if (beans < 16) {
System.out.println("Sorry, not enough coffee beans !");
} else
System.out.println("Sorry, not enough disposable cups !");
break;
case "2":
if (water >= 350 && milk >= 75 && beans >= 20 && disCups > 0) {
System.out.println("I have enough resources, making you a coffee !");
water -= 350;
beans -= 20;
milk -= 75;
disCups -= 1;
money += 7;
} else if (water < 350) {
System.out.println("Sorry, not enough water !");
} else if (milk < 75) {
System.out.println("Sorry, not enough milk !");
} else if (beans < 20) {
System.out.println("Sorry, not enough coffee beans !");
} else
System.out.println("Sorry, not enough disposable cups !");
break;
case "3":
if (water >= 200 && milk >= 100 && beans >= 12 && disCups > 0) {
System.out.println("I have enough resources, making you a coffee !");
water -= 200;
beans -= 12;
milk -= 100;
disCups -= 1;
money += 6;
} else if (water < 200) {
System.out.println("Sorry, not enough water !");
} else if (milk < 100) {
System.out.println("Sorry, not enough milk !");
} else if (beans < 12) {
System.out.println("Sorry, not enough coffee beans !");
} else
System.out.println("Sorry, not enough disposable cups !");
break;
}
action();
}
public static void fill () {
Scanner add = new Scanner(System.in);
System.out.println("Write how many ml of water do you want to add:");
water += add.nextInt();
System.out.println("Write how many ml of milk do you want to add:");
milk += add.nextInt();
System.out.println("Write how many grams of coffee beans do you want to add:");
beans += add.nextInt();
System.out.println("Write how many disposable cups of coffee do you want to add:");
disCups += add.nextInt();
action();
}
public static void take () {
System.out.println("I gave you" + " " +"$"+ money);
money=0;
action();
}
public static void remaining () {
System.out.println("The coffee machine has:");
System.out.println(water + " " + "of water");
System.out.println(milk + " " + "of milk");
System.out.println(beans + " " + "of coffee beans");
System.out.println(disCups + " " + "of disposable cups");
if(money!=0) {
System.out.println("$" + money + " " + "of money");
}else
System.out.println(money+" "+"of money");
action();
}
public static void exit () {
System.exit(0);
}
}