Messages
GoGetInventory(){
//set inventoryToOrder to a default list, as backup
}
GoGetInventory(Map<String, Integer> inventoryNeeded){
inventoryToOrder = inventoryNeeded;
event = toldToGetInventory;
}
FollowMe(Employee e, int x, int y){
stationX = x;
stationY = y;
employee = e;
event = followEmployee;
}
MayITakeYourOrder(Employee e){
event = askedForOrder;
}
HereIsYourOrder(Map<String, Integer> inventoryFulfilled, double amount){
bill = new Bill(inventoryFulfilled, amount);
event = gotOrderAndBill;
}
HereIsYourChange(double amountChange, double amountCharged){
bill.changeReceived = amountChange;
event = gotChange;
}
//non-norms
NotEnoughCash(double oweCash){
cashOwed = oweCash;
myCash += 100; //so he can for sure pay next time
IOweMarket = true;
event = gotChange;
}
HereIsBill(double amount){ //from cashier
bill.charge = amount;
event = gotNewBill;
}
HereIsFinalBill(double amount){
bill.charge = amount;
bill.nonNegotiable = true;
event = gotNewBill;
}
Data
Greeter host;
Employee employee;
MarketCashier cashier;
MarketMenu marketMenu;
int stationX, stationY;
double myCash, cashOwed;
boolean IOweMarket = false;
Map<String, Integer> inventoryToOrder;
Bill bill;
enum BillState {unpaid, paid};
enum AgentState {DoingNothing, WaitingInMarket, WaitingForEmployee, GoingToStation, Ordering, OrderProcessing, WaitingForOrder, GoingToCashier, Paying, WaitingForChange, Leaving, WaitingForRecalculation};
enum AgentEvent {none, toldToGetInventory, toldToWaitForEmployee, followEmployee, atStation, askedForOrder, gotOrderAndBill, atCashierAgent, gotNewBill, gotChange, doneLeaving};
class Bill {
Map<String, Integer> inventoryFulfilled;
double charge, amountPaid, amountOwed, changeReceived;
BillState s;
boolean nonNegotiable = false;
}
Scheduler
if state = DoingNothing && event = toldToGetInventory
state = WaitingInMarket;
GoToMarket();
if state = WaitingInMarket && event = followEmployee
state = GoingToStation;
GoToEmployeeStation();
if state = GoingToStation && event = askedForOrder
state = OrderProcessing;
PlaceOrder();
if state = OrderProcessing && event = gotOrderAndBill
state = GoingToCashier;
GoToCashier();
if state = GoingToCashier && event = atCashierAgent
state = Paying;
PayBill();
if state = Paying && event = gotNewBill
state = WaitingForChange;
PayBill();
if state = Paying && event = gotChange
LeaveMarket();
if state = WaitingForChange && event = gotChange //for non-norms
LeaveMarket();
if state = Leaving && event = doneLeaving
state = DoingNothing;
//no action
Actions
GoToMarket(){
//gui to go to waiting area
host.INeedInventory(this, gui.waitingRoomX, gui.waitingRoomY);
}
GoToEmployeeStation(){
//gui to go to station
}
PlaceOrder(){
employee.HereIsMyOrder(this, inventoryToOrder);
}
GoToCashier(){
//gui to go to cashier
}
PayBill(){
if (IOweMarket){
if (myCash >= cashOwed){
cashier.HereIsMoneyIOwe(this, cashOwed);
myCash -= cashOwed;
cashOwed = 0;
IOweMarket = false;
} else {
//print statement that you can't pay
}
}
if (bill.nonNegotiable){
if (myCash >= bill.charge){
cashier.HereIsPayment(bill.charge, this);
//set myCash and other bill variables
} else {
cashier.HereIsPayment(myCash, this);
myCash = 0;
return;
}
}
else {
double expected = 0;
for (E Map entry) expected = ...; //find the expected sum
if (expected >= bill.charge){
if (myCash >= bill.charge){
cashier.HereIsPayment(bill.charge, this);
myCash -= bill.charge;
bill.amountPaid = bill.charge;
return;
}else {
cashier.HereIsPayment(myCash, this);
myCash -= 0;
bill.amountPaid = bill.charge;
return;
}
}else {
cashier.PleaseRecalculateBill(this);
}
}
}
LeaveMarket(){
if (bill.changeReceived < (bill.amountPaid - bill.charge))
cashier.PleaseRecalculateBill(this, bill.amountPaid - bill.charge);
state = WaitingForChange;
return;
cashier.ChangeVerified(this);
employee.DoneAndLeaving(this);
//gui to leave market
state = leaving;
bill = null;
}