HereIsOrderForDelivery(String restaurantName, Map<String, Integer> inventory, double billAmount){
bills.add(new Bill(restaurantName, billAmount, inventory));
}
HereIsPayment(double amount, String restaurantName){
Bill b = bills.find(restaurantName);
b.amountPaid = amount;
b.event = receivedPayment;
}
ChangeVerified(String restaurantName){
Bill b = bills.find(restaurantName);
cash += b.amountMarketGets;
b.event = changeVerified;
}
IOweYou(double amount, String name){
Bill b = bills.find(name);
cash += b.amountMarketGets;
b.event = acknowledgedDebt;
}
CheckForRedeliveries(){ //called by a timer
Bill b = bills.find(b.s == waitingToRedeliver);
//if the restaurant of b is NOT open,
return;
else
b.event = checkRedeliveryOn;
}
List<Bill> bills;
enum DeliveryEvent {deliveryRequested, arrivedAtLocation, receivedPayment, changeVerified, acknowledgedDebt, arrivedAtMarket, checkRedeliveryOn, checkRedeliveryOff};
enum DeliveryState {newBill, enRoute, waitingForPayment, calculatingChange, oweMoney, waitingForVerification, goingBackToMarket};
AgentState state;
enum AgentState {doingNothing, makingDelivery};
class Bill{
String restaurantName;
Map<String, Integer> itemsBought;
CustomerState s;
double amountCharged, amountPaid, amountOwed, amountMarketGets;
MainCook cook;
MainCashier cashier;
DeliveryState s;
DeliveryEvent event;
}
if E b in bills such that b.s = newBill && b.event = deliveryRequested && state = doingNothing
DeliverOrder(b);
if E b in bills such that b.s = waitingForPayment && b.event = receivedPayment
CalculateChange(b);
if E b in bills such that b.s = waitingForVerification && b.event = changeVerified
ReturnToMarket(b);
state = doingNothing;
if E b in bills such that b.s = oweMoney && b.event = receivedPayment
CalculateChange(b);
if E b in bills such that b.s = oweMoney && b.event = acknowledgedDebt
ReturnToMarket(b);
state = doingNothing;
if E b in bills such that b.s = waitingToRedeliver && b.event = checkRedeliveryOn
DeliverOrder(b);
b.event = checkRedeliveryOff;
DeliverOrder(Bill b){
//gui call to go to location
//semaphore to wait for gui to complete
if restaurant is open,
//gui to go back home
b.s = waitingToRedeliver;
state = doingNothing;
//find proper cook and cashier from contact list, set to that bill's cook/cashier
b.cook.HereIsYourOrder(b.itemsBought);
b.cashier.HereIsMarketBill(b.itemsBought, b.amountCharged, this);
b.s = waitingForDelivery;
state = makingDelivery;
}
CalculateChange(Bill b){
if (b.amountPaid >= b.amountCharged) {
b.cashier.HereIsChange((mc.amountPaid - mc.amountCharged), this);
b.amountMarketGets = b.amountCharged;
b.s = waitingForVerification;
}
else {
b.amountMarketGets = b.amountPaid;
b.amountOwed = b.amountCharged - b.amountPaid;
b.cashier.NotEnoughMoney(b.amountOwed, b.amountPaid);
b.s = oweMoney;
}
}
ReturnToMarket(Bill b){
bills.remove(b);
//gui to go back to market
}