class Bidder { usage lin{Bidder; Q1} where Q1 = lin{run; end}; int myPid; int myPrice; Auctioneer[Q1] a; boolean done; void Bidder(Auctioneer[Q1] auctioneer, int pid, int price) { a = auctioneer; pid = pid; myPrice = price; myPid = -1; done = false; } void run() { Bidding b; b = a.bidding("psp"); b.register(myPid); if(b.getPrice() <= myPrice) { b.bid(myPrice); } else { done = true; b.done(); } } } class Bidding { usage lin{Bidding; Q1} where Q1 = lin{canRegister; Q1 + register; Q2} Q2 = lin{canRegister; Q2 + getPrice; Q3} Q3 = lin{canRegister; Q3 + done; end + bid; end}; Auction[Q1] a; int myBidder; int price; boolean done; boolean init; void Bidding(Auction[Q1] auction) { a = auction; price = -1; myBidder = -1; init = true; done = false; } boolean canRegister() { init; } void done() { unit; } void bid(int price) { a.bid(myBidder, price); } int getPrice() { if(price == -1) { price = a.getInitialPrice(); } price; } void register(int bidder) { myBidder = bidder; } } class Selling { usage lin{Selling; Q1} where Q1 = lin{canRegister; Q1 + sold; } Q3 = lin{canRegister; Q3 + done; end} Q2 = lin{canRegister; Q2 + getPrice; end}; Auction[Q1] a; int finalPrice; boolean done; boolean init; boolean sold; void Selling(Auction[Q1] auction) { a = auction; finalPrice = -1; init = true; sold = false; done = false; } boolean canRegister() { init; } void done() { unit; } int getPrice() { finalPrice; } boolean sold() { finalPrice = a.getMaxBid(); sold = finalPrice >= a.getInitialPrice(); sold; } } class Auction { usage lin{Auction; Q1} where Q1 = un{getBidder; Q1 + getMaxBid; Q1 + getInitialPrice; Q1 + bid; Q1 + auctionOpen; Q1}; string itemName; int initPrice; int maxBid; int bidder; void Auction(string item, int price) { itemName = item; initPrice = price; maxBid = 0; bidder = -1; canBid = true; } int getBidder() { bidder; } int getMaxBid() { maxBid; } int getInitialPrice() { initPrice; } void bid(int pid, int bid) { if(maxBid <= bid) { bidder = pid; maxBid = bid; } } boolean auctionOpen() { canBid; } } class AuctionMap { Auction[Q1] a; void AuctionMap() { unit; } void get() { a; } void put(Auction[Q1] auction) { a = auction; } } class Seller { usage lin{Seller; Q1} where Q1 = lin{run; end}; string myItem; int myPrice; Auctioneer[Q1] a; void Seller(Auctioneer[Q1] auctioneer, string item, int price) { a = auctioneer; myItem = item; myPrice = price; } boolean lowerPrice() { boolean lower; if(myPrice > 80) { myPrice = 80; lower = true; } lower; } void run() { Selling s; s = a.selling(myItem, myPrice); printStr("waiting... "); if(s.sold()) { printStr("made "); printInt(s.getPrice()); printStr(" euros!\n"); } else { s.done(); if(lowerPrice()) { run(); } } } } class Auctioneer { usage lin{Auctioneer; Q1} where Q1 = un{bidding; Q1 + selling; Q1}; AuctionMap map; void Auctioneer() { map = new AuctionMap(); } Bidding[Q1] bidding(string item) { Bidding b; b = new Bidding(map.get()); b; } Selling[Q1] selling(string item, int initPrice) { Auction a; a = new Auction(item, initPrice); map.put(a); Selling s; s = new Selling(); s; } }