Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 9cef04192e
Fetching contributors…

Cannot retrieve contributors at this time

87 lines (72 sloc) 2.191 kb
import edu.ucdavis.jr.*;
import java.util.*;
import java.util.ArrayList;
public class Customer extends Person {
public Customer(int id, Beverage fd, Table ft)
{
super("Customer " + id);
drinksLeft = Global.startNumberOfOrders;
favoriteDrink = fd;
favoriteTable = ft;
}
private int drinksLeft;
private Beverage favoriteDrink;
private Table favoriteTable;
protected boolean shouldGoHome()
{
return knowsItsClosed() || drinksLeft <= 0;
}
protected void oneIteration()
{
inni void tellLastCallOrClosing()
{
numCalls++;
}
[] else
{
say("Ordering " + favoriteDrink);
MyTime t0 = Global.clock.getTime();
boolean succesful = Global.orderingChannel(favoriteDrink);
addOrderingWaitingTime(Global.clock.getTime().compareTo(t0));
if(succesful)
{
drinksLeft--;
startDrinking();
say("Putting down " + favoriteDrink.getBeverageWare() + " on " + favoriteTable);
call favoriteTable.addBeverageWare(favoriteDrink.getBeverageWare());
}
}
}
private void startDrinking()
{
op void drinkFinished();
MyTime mt = new MyTime(favoriteDrink.getDrinkingTime());
say("Will finnish in " + mt);
Global.clock.setAlarm(drinkFinished, mt);
while(true)
{
inni void drinkFinished()
{
break;
}
[] void tellLastCallOrClosing()
{
numCalls++;
if(favoriteDrink == Global.beer && numCalls == 1 && drinksLeft > 0)
{
say("I drank up fast due to last call!");
break;
}
}
}
}
private static List<Integer> waitTimes = new ArrayList<Integer>();
private static synchronized void addOrderingWaitingTime(Integer time)
{
waitTimes.add(time);
}
public static List<Integer> getWaitTimes()
{
return waitTimes;
}
}
Jump to Line
Something went wrong with that request. Please try again.