-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinal.java
More file actions
145 lines (127 loc) · 4.41 KB
/
Final.java
File metadata and controls
145 lines (127 loc) · 4.41 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
137
138
139
140
141
142
143
144
145
import java.util.Scanner;
public class CoffeeMachine {
static int water = 400;
static int milk = 540;
static int coffee = 120;
static int numDispCups = 9;
static int moneyInMac = 550;
enum coffeeVariant {
espresso(250, 0, 16, 4),
latte(350, 75, 20, 7),
cappuccino(200, 100, 12, 6);
int reqWater;
int reqMilk;
int reqCoffee;
int cost;
coffeeVariant(int reqWater, int reqMilk, int reqCoffee, int cost) {
this.reqWater = reqWater;
this.reqMilk = reqMilk;
this.reqCoffee = reqCoffee;
this.cost = cost;
}
}
public static void displayIngredients(){
System.out.println();
System.out.println("The coffee machine has:");
System.out.println(water + " of water");
System.out.println(milk + " of milk");
System.out.println(coffee + " of coffee beans");
System.out.println(numDispCups + " of disposable cups");
if (moneyInMac == 0) {
System.out.println(moneyInMac + " of money");
} else {
System.out.println("$" + moneyInMac + " of money");
}
System.out.println();
}
public static void doBuy() {
Scanner scanner = new Scanner(System.in);
System.out.println();
System.out.println("What do you want to buy? 1 - espresso, 2 - latte, 3 - cappuccino:, back - to main menu:");
String coffeeType = scanner.next();
coffeeVariant user;
switch (coffeeType) {
case "1":
user = coffeeVariant.valueOf("espresso");
break;
case "2":
user = coffeeVariant.valueOf("latte");
break;
case "3":
user = coffeeVariant.valueOf("cappuccino");
break;
case "back":
return;
default:
System.out.println("Coffee variant not available.");
return;
}
if (water < user.reqWater){
System.out.println("Sorry, not enough water!");
return;
} else if (milk < user.reqMilk) {
System.out.println("Sorry, not enough milk!");
return;
} else if (coffee < user.reqCoffee) {
System.out.println("Sorry, not enough coffee!");
return;
} else if (numDispCups == 0) {
System.out.println("Sorry, not enough cups!");
return;
}
System.out.println("I have enough resources, making you a coffee!");
System.out.println();
water -= user.reqWater;
milk -= user.reqMilk;
coffee -= user.reqCoffee;
numDispCups--;
moneyInMac += user.cost;
}
public static void doFill() {
Scanner scanner = new Scanner(System.in);
System.out.println();
System.out.println("Write how many ml of water do you want to add:");
int newWater = scanner.nextInt();
System.out.println("Write how many ml of milk do you want to add:");
int newMilk = scanner.nextInt();
System.out.println("Write how many grams of coffee beans do you want to add:");
int newCoffee = scanner.nextInt();
System.out.println("Write how many disposable cups of coffee do you want to add:");
int newCups = scanner.nextInt();
water += newWater;
milk += newMilk;
coffee += newCoffee;
numDispCups += newCups;
}
public static void doTake() {
System.out.println();
System.out.println("I gave you $" + moneyInMac);
moneyInMac = 0;
}
public static void processCommand(String command) {
switch (command) {
case "buy":
doBuy();
break;
case "fill":
doFill();
break;
case "take":
doTake();
break;
case "remaining":
displayIngredients();
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Write action (buy, fill, take):");
String command = scanner.next();
while (!command.equals("exit")) {
processCommand(command);
System.out.println();
System.out.println("Write action (buy, fill, take):");
command = scanner.next();
}
}
}