forked from weihang123123/res1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoffeeMaker.java
112 lines (100 loc) · 2.97 KB
/
CoffeeMaker.java
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
package edu.ncsu.csc326.coffeemaker;
import edu.ncsu.csc326.coffeemaker.exceptions.InventoryException;
/**
* @author Sarah Heckman
*/
public class CoffeeMaker {
/** Array of recipes in coffee maker. */
private static RecipeBook recipeBook;
/** Inventory of the coffee maker. */
private static Inventory inventory;
/*
* Constructor for the coffee maker
*
*/
public CoffeeMaker() {
recipeBook = new RecipeBook();
rb1 = new RecipeBook();//here
rb2 = new RecipeBook();//and here
inventory = new Inventory();
}
/**
* Returns true if the recipe is added to the
* list of recipes in the CoffeeMaker and false
* otherwise.
* @param r
* @return boolean
*/
public boolean addRecipe(Recipe r) {
return recipeBook.addRecipe(r);
}
/**
* Returns the name of the successfully deleted recipe
* or null if the recipe cannot be deleted.
* @param recipeToDelete
* @return String
*/
public String deleteRecipe(int recipeToDelete) {
return recipeBook.deleteRecipe(recipeToDelete);
}
/**
* Returns the name of the successfully edited recipe
* or null if the recipe cannot be edited.
* @param recipeToEdit
* @param r
* @return String
*/
public String editRecipe(int recipeToEdit, Recipe r) {
return recipeBook.editRecipe(recipeToEdit, r);
}
/**
* Returns true if inventory was successfully added.
* @param amtCoffee
* @param amtMilk
* @param amtSugar
* @param amtChocolate
* @return boolean
*/
public synchronized void addInventory(String amtCoffee, String amtMilk, String amtSugar, String amtChocolate) throws InventoryException {
inventory.addCoffee(amtCoffee);
inventory.addMilk(amtMilk);
inventory.addSugar(amtSugar);
inventory.addChocolate(amtChocolate);
}
/**
* Returns the inventory of the coffee maker
* @return Inventory
*/
public synchronized String checkInventory() {
return inventory.toString();
}
/**
* Returns the change of a user's beverage purchase, or.
* the user's money if the beverage cannot be made
* @param r
* @param amtPaid
* @return int
*/
public synchronized int makeCoffee(int recipeToPurchase, int amtPaid) {
int change = 0;
if (getRecipes()[recipeToPurchase] == null) {
change = amtPaid;
} else if (getRecipes()[recipeToPurchase].getPrice() <= amtPaid) {
if (inventory.useIngredients(getRecipes()[recipeToPurchase])) {
change = amtPaid - getRecipes()[recipeToPurchase].getPrice();
} else {
change = amtPaid;
}
} else {
change = amtPaid;
}
return change;
}
/**
* Returns the list of Recipes in the RecipeBook.
* @return Recipe []
*/
public synchronized Recipe[] getRecipes() {
return recipeBook.getRecipes();
}
}