-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaintenance.java
More file actions
54 lines (46 loc) · 1.81 KB
/
Copy pathMaintenance.java
File metadata and controls
54 lines (46 loc) · 1.81 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
import java.util.Map;
public class Maintenance {
private RegularVendingMachine vendingMachine;
public Maintenance(RegularVendingMachine vendingMachine) {
this.vendingMachine = vendingMachine;
}
public void restockItem(String itemSlot, int quantity) {
Item item = vendingMachine.getItem(itemSlot);
if (item != null) {
int startingCount = vendingMachine.getStartingInventory().getOrDefault(item, 0);
vendingMachine.getStartingInventory().put(item, startingCount + quantity);
System.out.println("Item restocked: " + item.getItemName());
System.out.println("Quantity: " + quantity);
} else {
System.out.println("Invalid item slot.");
}
}
public void setItemPrice(String itemSlot, double price) {
vendingMachine.setPrice(itemSlot, price);
System.out.println("Item Slot: " + itemSlot);
System.out.println("Price: " + price);
}
public void collectPaymentMaintenance() {
vendingMachine.collectPayment();
System.out.println("Payment collected.");
}
public void replenishChange() {
vendingMachine.replenishChange();
System.out.println("Change replenished.");
}
public void performMaintenance() {
restockItems();
collectPaymentMaintenance();
replenishChange();
}
private void restockItems() {
Map<Item, Integer> endingInventory = vendingMachine.getEndingInventory();
for (Map.Entry<Item, Integer> entry : endingInventory.entrySet()) {
Item item = entry.getKey();
int count = entry.getValue();
vendingMachine.getStartingInventory().put(item, count);
endingInventory.put(item, 0);
}
System.out.println("Items successfully restocked.");
}
}