Class Simulation1

java.lang.Object
  |
  +--Simulation
        |
        +--Simulation1

public class Simulation1
extends Simulation

A class which defines a specific lunch simulation seating scheme. This class completes the class outlined in Simulation. The parties will be seated at tables which are the same size as their party.


Field Summary
private  Queue[] waiting
          An array of queues to hold all of the parties that are waiting to be seated.
 
Fields inherited from class Simulation
MAX_PARTY_SIZE, MIN_PARTY_SIZE, PARTY_SIZES, schedule, stats, TABLE_COUNTS, tablesTaken, timer
 
Constructor Summary
Simulation1(long seed1, long seed2)
          Creates a new instance of the simulation.
 
Method Summary
protected  void addToQueue(Party p)
          If a table is not available for the party, the party will be added to a queue.
protected  int findTable(Party p)
          Attempts to find a table for the specified party.
protected  void freeTable(int tableSize)
          Frees a table of a specific size.
 
Methods inherited from class Simulation
addArrivals, arrivalTime, eatingTime, isFree, processArrival, processDeparture, processEvent, runSimulation, seatAtTable
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

waiting

private Queue[] waiting
An array of queues to hold all of the parties that are waiting to be seated. A party in the queue at index i will be of size i.
Constructor Detail

Simulation1

public Simulation1(long seed1,
                   long seed2)
Creates a new instance of the simulation. Also initializes array of queues, and initializes the EventTimer with the specified seeds.
Parameters:
seed1 - a seed to initialize the EventTimer
seed2 - a seed to initialize the EventTimer
Method Detail

findTable

protected int findTable(Party p)
Attempts to find a table for the specified party. Checks to see if a table for this party is available. The table must be the same size as the party. If there is no table available, -1 is returned.
Parameters:
p - the party to be seated
Returns:
the size of the table the party will be seated at; -1 if there is no table available
Overrides:
findTable in class Simulation

addToQueue

protected void addToQueue(Party p)
If a table is not available for the party, the party will be added to a queue. They will be added to a queue which contains other parties with size equal to the specified party's size.
Overrides:
addToQueue in class Simulation

freeTable

protected void freeTable(int tableSize)
Frees a table of a specific size. If there are other parties waiting for a table of the same size, the party which has been waiting the longest will be seated at the newly freed table.
Parameters:
tableSize - the size of the table to be freed
Overrides:
freeTable in class Simulation