Repository navigation
Expand file tree
/
Copy pathCoffeeMachine4.java
More file actions
168 lines (144 loc) · 6.97 KB
/
Copy pathCoffeeMachine4.java
File metadata and controls
168 lines (144 loc) · 6.97 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//package machine;
import java.util.Scanner;
public class CoffeeMachine4 {
static int availableMoney = 550;
static int availableWater = 400;
static int availableMilk = 540;
static int availableBeans = 120;
static int availableDisposalCups = 9;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(true){
System.out.println("Write action (1.buy, 2.fill, 3.take, 4.remaining, 5.exit) : ");
byte choice = sc.nextByte();
switch(choice){
case 1 :{
buy(sc);
break;
}
case 2 :{
fill(sc);
break;
}
case 3 : {
take();
break;
}
case 4 : {
display();
break;
}
case 5 : {
sc.close();
System.out.println("Thank you for visiting!");
System.out.println("---------------------------------------------------------------------------------------------");
return;
}
default : System.out.println("Invalid Input!");
}
}
}
public static void buy(Scanner sc){
System.out.println("What do you want to buy? (1.espresso, 2.latte, 3.cappuccino) :");
byte type = sc.nextByte();
switch(type){
case 1 :{
if((availableWater >= 200) && (availableBeans >= 16) && (availableDisposalCups >=1)){
System.out.println("I have enough resources, making you a coffee!");
availableWater -= 200;
availableBeans -= 16;
availableMoney += 4;
availableDisposalCups--;
}
else{
if(availableWater < 200){
System.out.println("Sorry, not enough water!");
}
if(availableBeans < 16){
System.out.println("Sorry, not enough coffee beans!");
}
if(availableDisposalCups < 1){
System.out.println("Sorry, not enough cups!");
}
}
break;
}
case 2 :{
if((availableWater >= 350) && (availableBeans >= 20) && (availableDisposalCups >=1) && (availableMilk >= 75)){
System.out.println("I have enough resources, making you a coffee!");
availableWater -= 350;
availableMilk -= 75;
availableBeans -= 20;
availableMoney += 7;
availableDisposalCups--;
}
else{
if(availableWater < 350){
System.out.println("Sorry, not enough water!");
}
if(availableBeans < 20){
System.out.println("Sorry, not enough coffee beans!");
}
if(availableDisposalCups < 1){
System.out.println("Sorry, not enough cups!");
}
if(availableMilk < 75){
System.out.println("Sorry, not enough milk!");
}
}
break;
}
case 3 :{
if((availableWater >= 200) && (availableBeans >= 12) && (availableDisposalCups >=1) && (availableMilk >= 100)){
System.out.println("I have enough resources, making you a coffee!");
availableWater -= 200;
availableMilk -= 100;
availableBeans -= 12;
availableMoney += 6;
availableDisposalCups--;
}
else{
if(availableWater < 200){
System.out.println("Sorry, not enough water!");
}
if(availableBeans < 12){
System.out.println("Sorry, not enough coffee beans!");
}
if(availableDisposalCups < 1){
System.out.println("Sorry, not enough cups!");
}
if(availableMilk < 100){
System.out.println("Sorry, not enough milk!");
}
}
break;
}
}
System.out.println("---------------------------------------------------------------------------------------------");
}
public static void fill(Scanner sc){
System.out.println("Write how many ml of water you want to add : ");
availableWater += sc.nextInt();
System.out.println("Write how many ml of milk you want to add : ");
availableMilk += sc.nextInt();
System.out.println("Write how many grams of coffee beans you want to add :");
availableBeans += sc.nextInt();
System.out.println("Write how many disposable cups you want to add :");
availableDisposalCups += sc.nextInt();
System.out.println("---------------------------------------------------------------------------------------------");
}
public static void take(){
System.out.println("I gave you $" + availableMoney);
availableMoney = 0;
}
public static void display(){
System.out.println("---------------------------------------------------------------------------------------------");
System.out.println("The coffee machine has:");
System.out.println(availableWater + " ml of water");
System.out.println(availableMilk + " ml of milk");
System.out.println(availableBeans + " g of coffee beans");
System.out.println(availableDisposalCups + " disposable cups");
System.out.println("$" + availableMoney + " of money");
System.out.println("---------------------------------------------------------------------------------------------");
}
}