-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoffee.java
More file actions
93 lines (83 loc) · 2.59 KB
/
Coffee.java
File metadata and controls
93 lines (83 loc) · 2.59 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
public class Coffee {
private int water;
private int milk;
private int coffeeBeans;
private int cups;
private int money;
public Coffee(int water, int milk, int coffeeBeans, int cups, int money ){
this.water = water;
this.milk = milk;
this.coffeeBeans = coffeeBeans;
this.cups = cups;
this.money = money;
}
public Coffee(int water, int milk, int coffeeBeans , int money){
this.water = water;
this.milk = milk;
this.coffeeBeans = coffeeBeans;
this.money = money;
}
public void llenarCafetera(int water, int milk,int coffeeBeans, int cups){
this.water += water;
this.milk += milk;
this.coffeeBeans += coffeeBeans;
this.cups += cups;
}
public void prepararCafe(Coffee coffee){
if(verificarIngredientes(coffee)){
System.out.println("Estoy preparando tu cafe");
this.water -= coffee.water;
this.milk -= coffee.milk;
this.coffeeBeans += coffee.coffeeBeans;
this.cups -= 1;
this.money += coffee.money;
}
}
public boolean verificarIngredientes(Coffee coffee){
if(this.water - coffee.water < 0 ){
System.out.println("Disculpa, no hay agua suficiente para prepara cafe");
return false;
}
if(this.milk - coffee.milk < 0 ){
System.out.println("Disculpa, no hay leche suficiente para preparar cafe");
return false;
}
if(this.coffeeBeans - coffee.coffeeBeans < 0 ){
System.out.println("Disculpa, no hay granos de café suficiente para preparar cafe");
return false;
}
if(this.cups == 0 ){
System.out.println("Disculpa, no hay vasos suficientes para preparar cafe");
return false;
}
return true;
}
public void takeMoney(){
System.out.println("Estas retirando : " + money + " euros ");
this.money = 0;
}
@Override
public String toString() {
return "\nLa maquina de cafe tiene :\n" +
water + " ml de agua\n" +
milk + " ml de leche\n " +
coffeeBeans + " g granos de cafe\n " +
cups + " vasos\n " +
money + " euros\n ";
}
}
class Espresso extends Coffee{
public Espresso(){
super(250, 0, 16, 4);
}
}
class Latte extends Coffee{
public Latte(){
super(350, 75, 20 ,7);
}
}
class Cappuccino extends Coffee{
public Cappuccino(){
super(200, 100, 12, 6);
}
}