package cafe; public class Cafe { public static boolean DEBUG = true; //public static final int MAX_RUNS = 20; public static final double MAX_RUNS = Double.POSITIVE_INFINITY; public static boolean noOutput = true; private int run; public static void main(String[] args) { System.out.println("Cafeteria Tray Model"); int total = 0; int numRuns = 1000; Cafe x; for (int i=0; i * forgetting, and a maximum number to remove */ public void removeItems() { int numToRemove; int maxRemoval = maxRemovable(); if (this.forget()) { numToRemove = (int)(droppage * maxRemoval); myTray.removeItems(numToRemove); } else { myTray.removeItems(maxRemoval); } } /** * Make the worker perform 5% less efficient */ public void slowdown() { efficiency *= (1-slowDownPercentage); } /** * Decides whether or not the worker is slacking off */ private boolean forget() { return ( Math.random() > forgetfulness ); } /** * Determines based on efficiency, how many items the worker can remove */ private int maxRemovable() { return (int)(MIN_REMOVABLE + (efficiency * (MAX_REMOVABLE - MIN_REMOVABLE + 1))); } /** * Forms a user-friendy string representation of a Worker */ public String toString() { return ("Worker #" + workerID + " with efficiency of " + ((int)((10000.0*efficiency))/100.0) + "% and droppage of " + ((int)((10000.0*droppage))/100.0) + "%"); } } class Tray { private static final int LOW_ITEMS = 0; private static final int HIGH_ITEMS = 5; private static int totalNumTrays; public static int throughput; private int numItems; private int trayID; /** * Creates a tray with a random number of items in it */ public Tray() { numItems = (int)(Math.random()*(HIGH_ITEMS-LOW_ITEMS)) + LOW_ITEMS; trayID = ++totalNumTrays; } /** * Creates a tray with a specific number of items in it */ public Tray(int i) { this(); setNumItems(i); } /** * Returns the number of items in a tray */ public int getNumItems() { return numItems; } /** * Sets the number of items in a tray */ public void setNumItems(int k) { if (k >= 0) numItems = k; else numItems = 0; } /** * Removes a certain number of items from a tray */ public void removeItems(int k) { if (k > numItems) { numItems = 0; throughput += numItems; } else { numItems -= k; throughput += k; } } /** * Returns true the tray is empty */ public boolean isEmpty() { return (numItems == 0); } /** * Forms a user-friendly representation of a tray object */ public String toString() { return("Tray #" + trayID + " has " + getNumItems() + " items on it."); } }