Repository navigation
Expand file tree
/
Copy pathCoffeeMachine2.java
More file actions
50 lines (39 loc) · 1.7 KB
/
Copy pathCoffeeMachine2.java
File metadata and controls
50 lines (39 loc) · 1.7 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
package machine;
import java.util.Scanner;
class Cup{
static final int WATER = 200;
static final int MILK = 50;
static final int BEANS = 15;
public static int getPossibleCups(int currentWater, int currentMilk, int currentBeans){
int cupsFromWater = currentWater / WATER;
int cupsFromMilk = currentMilk / MILK;
int cupsFromBeans = currentBeans / BEANS;
int possibleCups = Math.min(cupsFromWater, Math.min(cupsFromMilk, cupsFromBeans));
return possibleCups;
}
}
public class CoffeeMachine2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Write how many ml of water the coffee machine has:");
int currentWater = sc.nextInt();
System.out.println("Write how many ml of milk the coffee machine has:");
int currentMilk = sc.nextInt();
System.out.println("Write how many grams of coffee beans the coffee machine has:");
int currentBeans = sc.nextInt();
System.out.println("Write how many cups of coffee you will need:");
int cups = sc.nextInt();
//Cup cup = new Cup();
int possibleCups = Cup.getPossibleCups(currentWater, currentMilk, currentBeans);
if(possibleCups == cups){
System.out.println("Yes, I can make that amount of coffee");
}
else if(possibleCups > cups){
System.out.println("Yes, I can make that amount of coffee (and even " + (possibleCups-cups) + " more than that)");
}
else{
System.out.println("No, I can make only " + possibleCups + " cup(s) of coffee");
}
sc.close();
}
}