forked from Kitch05/Vending-Machine-with-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpecialMachine.java
More file actions
63 lines (56 loc) · 1.76 KB
/
Copy pathSpecialMachine.java
File metadata and controls
63 lines (56 loc) · 1.76 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
import java.util.ArrayList;
public class SpecialMachine extends VendingMachine{
private ArrayList<Item> customOrder;
/**
* Class constructor
*/
public SpecialMachine() {
super();
this.customOrder = new ArrayList<Item>();
}
/**
* Adds an item into the custom order inventory.
* @param addComponent item to be added
*/
public void customizeOrder(Item addComponent) {
this.customOrder.add(addComponent);
}
/**
* Finds the first instance of the item and removes it from the custom order inventory
* @param itemName name of the item to be removed
*/
public void removeComponent(String itemName) {
int flag = 0;
for (int i = 0; i < customOrder.size() && flag == 0; i++) {
if(customOrder.get(i).getName().equals(itemName)) {
this.customOrder.remove(customOrder.get(i));
flag = 1;
}
}
}
/**
* Wipes the inventory clean of any item
*/
public void cancelOrder() {
this.customOrder.clear();
}
/**
* Returns the custom order inventory
* @return an array list
*/
public ArrayList<Item> getCustomOrder() {
return this.customOrder;
}
/**
* Purchases the individual components of the order and clears the inventory.
* Adds a bread to the order as this is meant to make the order a burger.
*/
public void purchaseOrder() {
for (Item component : this.customOrder) {
if(!(component instanceof Bread))
purchaseItem(component.getName(), getTotalInserted());
}
cancelOrder();
getTransactions().add(new Bread());
}
}