This repository has been archived by the owner on Nov 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
MarketConsumerRole
Matthew Pohlmann edited this page Jan 1, 2014
·
1 revision
####Description A MarketConsumer is a role taken by any PersonAgent who needs to order from a market.
####Class Signature
public class MarketConsumerRole extends Role implements MarketConsumerRole {}
####Data
String name;
List<MarketBill> marketBills;
enum MarketBillState {OUTSTANDING, PAID};
class MarketBill {
MarketManager manager;
float amount;
MarketBillState state;
}
####Scheduler
if Ǝ Order mb in marketBills ∋ mb.state == OrderState.OUTSTANDING then,
PayBill(mb);
return true;
####Messages
public void msgHereIsYourTotal(MarketManager manager, float amount) {
// Add the new bill to our list of bills
orders.add(new MarketBill(manager, amount, MarketBillState.OUTSTANDING));
stateChanged();
}
public void msgHereAreYourItems(List<Item> items) {
// Add the items to our inventory
/*
* We'll have to talk about how a Person has an "inventory" or something
*/
inventory.add(items);
stateChanged();
}
public void msgHereIsYourCar(Vehicle car) {
this.getPerson().setHasCar(true);
}
####Actions
private void PayBill(MarketBall mb) {
// Send our payment to the market manager
mb.manager.msgHereIsMyPayment(mb.amount);
// Mark the bill as paid
mb.state == MarketBillState.PAID;
// We're that much poorer
/*
* We'll have to talk about how a Person keeps track of money
*/
totalCash -= mb.amount;
}