Repository navigation
Expand file tree
/
Copy pathCoffeeMachine3.java
More file actions
113 lines (89 loc) · 3.53 KB
/
Copy pathCoffeeMachine3.java
File metadata and controls
113 lines (89 loc) · 3.53 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
package machine;
import java.util.Scanner;
public class CoffeeMachine3 {
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);
display();
System.out.println("Write action (1.buy, 2.fill, 3.take) : ");
byte choice = sc.nextByte();
switch(choice){
case 1 :{
buy();
break;
}
case 2 :{
fill();
break;
}
case 3 : {
take();
break;
}
default : System.out.println("Invalid Input!");
}
display();
sc.close();
}
public static void buy(){
Scanner scbuy = new Scanner(System.in);
System.out.println("What do you want to buy? (1.espresso, 2.latte, 3.cappuccino) :");
byte type = scbuy.nextByte();
scbuy.close();
switch(type){
case 1 :{
availableWater -= 200;
availableBeans -= 16;
availableMoney += 4;
availableDisposalCups--;
break;
}
case 2 :{
availableWater -= 350;
availableMilk -= 25;
availableBeans -= 20;
availableMoney += 7;
availableDisposalCups--;
break;
}
case 3 :{
availableWater -= 200;
availableMilk -= 100;
availableBeans -= 12;
availableMoney += 6;
availableDisposalCups--;
break;
}
}
}
public static void fill(){
Scanner scfill = new Scanner(System.in);
System.out.println("Write how many ml of water you want to add : ");
availableWater += scfill.nextInt();
System.out.println("Write how many ml of milk you want to add : ");
availableMilk += scfill.nextInt();
System.out.println("Write how many grams of coffee beans you want to add :");
availableBeans += scfill.nextInt();
System.out.println("Write how many disposable cups you want to add :");
availableDisposalCups += scfill.nextInt();
scfill.close();
}
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("---------------------------------------------------------------------------------------------");
}
}