ComputeBill(Map<String, Integer> inventory, Customer c, Employee e){
Bill b = new Bill(inventory, c, computing, e);
bills.add(b);
}
ComputeBill(Map<String, Integer> inventory, String name, Employee e){
Bill b = new Bill(inventory, name, computing, e);
bills.add(b);
}
HereIsPayment(double amount, Customer cust){
Bill b = bills.find(cust);
b.amountPaid = amount;
b.s = calculatingChange;
}
PleaseRecalculateBill(Customer cust){
Bill b = bills.find(cust);
b.s = recomputingBill;
}
ChangeVerified(Customer cust){
Bill b = bills.find(cust);
cash += b.amountMarketGets;
bills.remove(b);
}
PleaseRecalculateChange(Customer cust, double amount){
Bill b = bills.find(cust);
b.recalculatedChange = amount;
b.s = recalculatingChange;
}
HereIsMoneyIOwe(Customer c, double amount){
availableMoney += amount;
}
MarketMenu marketMenu;
List<Bill> bills;
List<EmployeeAgent> employees;
double cash;
enum BillState {computing, waitingForPayment, recomputingBill, calculatingChange, oweMoney, paid};
class Bill{
Map<String, Integer> itemsBought;
double amountCharged, newAmountCharged, amountPaid, amountOwed, recalculatedChange, amountMarketGets;
CustomerAgent c;
String restaurantName;
BillState s;
EmployeeAgent e;
}
if E b in bills such that b.s = recalculatingChange
RecomputeChange(b);
if E b in bills such that b.s = recomputingBill
RecomputeBill(b);
if E b in bills such that b.s = calculatingChange
CalculateChange(b);
if E b in bills such that b.s = computing
ComputeBill(b);
ComputeBill(Bill b){
for (E entry in b.itemsBought){
for (E Item i in marketMenu.menuItems)
if (i.getItem() = entry.getKey())
b.amountCharged += i.getPrice()*entry.getValue();
}
if (b.c == null){
b.e.HereIsBill(b.restaurantName, b.amountCharged);
bills.remove(b);
}
else {
b.e.HereIsBill(b.c, b.amountCharged);
b.s = waitingForPayment;
}
}
CalculateChange(Bill b){
if (b.amountPaid >= b.amountCharged) {
b.c.HereIsYourChange((b.amountPaid - b.amountCharged), b.amountCharged);
b.amountMarketGets = b.amountCharged;
b.s = paid;
}
else {
b.c.NotEnoughCash(b.amountCharged - b.amountPaid);
b.amountOwed = b.amountCharged - b.amountPaid;
b.amountMarketGets = b.amountPaid;
b.s = oweMoney;
}
}
RecomputeChange(Bill b){
b.c.HereIsYourChange(b.recalculatedChange, b.amountCharged);
b.amountMarketGets = b.amountPaid - b.recalculatedChange;
b.s = paid;
}
RecomputeBill(Bill b){
for (E entry in b.itemsBought){
for (E Item i in marketMenu.menuItems)
if (i.getItem() = entry.getKey())
b.newAmountCharged += i.getPrice()*entry.getValue();
}
if (b.newAmountCharged < b.amountCharged){
b.amountCharged = b.newAmountCharged;
//if customer,
b.c.HereIsBill(b.amountCharged);
}
else if (b.newAmountCharged > b.amountCharged){
//if customer,
b.c.HereIsBill(b.amountCharged);
}
else if (b.newAmountCharged = b.amountCharged){
//if customer,
b.c.HereIsFinalBill(b.amountCharged);
}
b.s = waitingForPayment;
}