CMPT270 Intersession 2017 Assignment #3 Queue Analysis of the Tim Horton\'s Line
ID: 3844357 • Letter: C
Question
CMPT270 Intersession 2017 Assignment #3 Queue Analysis of the Tim Horton's Lineup for Coffe As mentioned in class, there are usually two ways in which customers are lined up for access to a number of service windows. Typically in a bank, there is one queue line for everyone and a number of windows. When a window becomes free, the next person at the head of the queue leaves the queue and proceeds to the window. People coming into the bank simply join the single queue at the tail of the queue At Tim's in Geology, we have the other approach to providing service. Every service window has its own queue. Typically when a person comes up to the lines, they choose the shortest line to join and then stay in that line. It can frustrate some people to see the longer line actually move faster and sometimes people will line hop (i.e. when the other line is shorter than the queue in front of me) So which is the best approach? In this assignment we are going to try and determine that. Here are the parameters for the simulation For both simulations you are to do the following: Run the simulation for 6 hours A new customer group arrives every 1 minute t 58 seconds e. as little as 2 seconds apart and as much as 1 min 50 seconds apart A group will consist of 1 to 6 customers following this distribution o 1 person 30% o 2 people-40% 3 people -20% o 4 people -5% o 5 people -3% o 6 people -2% Each person in the group joins the queue single file but we can use the same join time for each member of the group Average serving time for a customer is 2 minutes t 65 seconds. For each simulation below, report on the following: Maximum number of customers served Average number of customers served per window per hour Average wait time in the queue for each customer Maximum wait time in the queue Average queue length for each queue Maximum queue length for each queue Simulation #1 Simulate a scenario with two server windows and two queues. When a group of customers arrive each individual in the group will choose the same queue, but the first individual will choose the shortest queueExplanation / Answer
//Customer.java
public class Customer {private int timeJoindQueue = 0;private int timeToWindow = 0;private int timeToLeave = 0;private int customerNumber = 0;int customerWaitingTime = 0;public void SetTimeJoinQ(int inTime){timeJoindQueue = inTime;}public void SetTimeToWindow(int inTime){timeToWindow = inTime;}public void setTimeToLeave(int inTime){timeToLeave = inTime;}public void setCustomerNumber(int inNum){customerNumber = inNum;}public int getTimeJoindQueue() {return timeJoindQueue;}public int getTimeToWindow(){return timeToWindow;}public int getTimeToLeave(){return timeToLeave;}public int getNum() {return customerNumber;}}
//CustomerNode.java
import linearstructures.LinkedList;public class CustomerNode extends LinkedList{Customer info;CustomerNode nextList;public void Join(Customer inInfo) {// Join(info): info becomes the end of the QUEUE the last item inserted
this.insertInfo(inInfo);}public void insertInfo(Customer inInfo) {if (this.amEmpty){CustomerNode tempLList = new CustomerNode(); // insert info here and add a new empty atendinfo=inInfo;nextList=tempLList;amEmpty=false;}else { this.nextList.insertInfo(this.info);
this.info = inInfo;}}public Customer Leave() {// info <-- Leave(): if the queue is empty nothing is returned//if the queue is not empty the last item in the list is returned and removed from the queue
if (this.isEmpty()) { return null;}
// if last item in list return and remove else leave from rest of queue
Customer tempCustomer;
if (this.nextList.isEmpty()) {
tempCustomer = this.info;
this.deleteInfo(tempCustomer);}
else {
// get from later in list
tempCustomer = this.nextList.Leave();}
return tempCustomer; }
public void deleteInfo(Customer outInfo) {if (this.amEmpty)return;
// check if this is the info to delete
if (this.info != outInfo) { // System.out.println("Didn't match so looking further down list"); this.nextList.deleteInfo(outInfo); return;
}
// found it so delete it
if (this.nextList.isEmpty()) {
this.nextList = null;
this.info = null;
amEmpty = true;
// System.out.println("Deleting from last element");
}
else {
this.info = this.nextList.info; // copy next info to current
this.nextList.deleteInfo(this.info);
// System.out.println("Shifted info forward and deleting down rest of list");
}
}
public String traverseList()
{
// add current content to list returned by the rest of the list
if (this.isEmpty())
return "";
if (this.nextList.isEmpty())
return "Number:"+this.info.getNum()+" Time Join Queue:"+this.info.getTimeJoindQueue();
return "Number:"+this.info.getNum()+" Time Join Queue:"+this.info.getTimeJoindQueue()+", "+this.nextList.traverseList();
}
public static void main(String[] args)
{
CustomerNode aCustomerNode = new CustomerNode();
Customer temp;
temp = new Customer();
temp.setCustomerNumber(85);
aCustomerNode.Join(temp);
temp = new Customer();
temp.setCustomerNumber(433);
aCustomerNode.Join(temp);
temp = new Customer();
temp.setCustomerNumber(957);
aCustomerNode.Join(temp);
System.out.println(aCustomerNode.traverseList());
System.out.println(aCustomerNode.Leave().getNum());
System.out.println(aCustomerNode.traverseList());
System.out.println(aCustomerNode.Leave().getNum());
System.out.println(aCustomerNode.traverseList());
}
}
//CustomerQ.java
public class CustomerQ
{
CustomerNode head= null;
int length = 0;
int maxlength = 0;
CustomerQ nextCustomerQ = null;
public void join(Customer inInfo)
{
if (head == null) //check if head is empty?
{
CustomerNode tempCustomerNode = new CustomerNode(); //if empty, build a new.
head = tempCustomerNode;
}
//insert customer inInfo into the queue.
head.Join(inInfo);
length = length+1;
if (length>maxlength) //add the queue length.
{
maxlength = length;
}
}
public Customer leave(Customer outInfo)
{
if (length>0)
{
length = length -1;
return head.Leave();
}
else
{
System.out.println("the Queue is empty!");
return null;
}
}
public int getLength(){
return length;
}
public int getMaxLength(){
return maxlength;
}
}
//DoorKeeper.java
import java.util.Random;
public class DoorKeeper
{
CustomerQ firstQ= null;
CustomerQ shortestQ = null;
int DoorClock= 0;
int customerCounter= 0;
EventQ theEventList = null;
//TODO throw event need to be done.
//post: change firstQ if there is no queue in room,
// shortestQ will be checked , may be changed.
// DoorClock will go 1 minute ± 50 seconds.
// new group customers will be created and throw into queue.
public void CustomerComeIn()
{
//create new group of customers.
int customerNumber;
double randomSeed;
randomSeed = Math.random();
if (randomSeed>=0 && randomSeed<= 0.3) {
customerNumber = 1;
} else if (randomSeed>0.3 && randomSeed<= 0.7) {
customerNumber = 2;
} else if (randomSeed>0.7 && randomSeed<= 0.9) {
customerNumber = 3;
} else if (randomSeed>0.9 && randomSeed<= 0.95) {
customerNumber = 4;
} else if (randomSeed>0.95 && randomSeed<= 0.98){
customerNumber = 5;
} else{
customerNumber = 6;
}
//for test
//System.out.println(customerNumber+" ");
checkShortestQ();// and it can build new queue if there is no queue.
//join group into the queue.
for (int i = 0; i < customerNumber; i++)
{
Customer newCustomer = new Customer();//create a new customer;
customerCounter =customerCounter+1;// counter go for 1;
newCustomer.setCustomerNumber(customerCounter);
newCustomer.SetTimeJoinQ(DoorClock);//tell customer the time he or she come in.
shortestQ.join(newCustomer);// let them join the shortest queue.
Event newEvent = new Event("Customer "+newCustomer.getNum()+" walk in.",DoorClock);
theEventList.eventInsert(newEvent);
//create a new event about new customer,
//and add it into eventQ;
}
//A new customer group arrives every 1 minute ± 50 seconds
timePassedWhenCustomerComeIn();
}
//post: will check and may change the shorstestQ.
public void checkShortestQ()
{
if (null == firstQ) {//if there is no queue in the room
firstQ = new CustomerQ();//build one.
shortestQ = firstQ;
}else if (null == firstQ.nextCustomerQ) {//if only one queue in the room
shortestQ = firstQ;//it is the shortest.
}else if (null == shortestQ) {
shortestQ = firstQ;
} else {
CustomerQ travQ = firstQ;
while (travQ!=null) {//if there are still queues not been traversed
if (travQ.length < shortestQ.length) {//check length ,if shorter than our shortest q,
shortestQ = travQ;//update shortest q.
}
travQ = travQ.nextCustomerQ;
}
}
}
//post: will add time into DoorClock.
public void timePassedWhenCustomerComeIn()
{
//A new customer group arrives every 1 minute ± 50 seconds
DoorClock = DoorClock+passedtime();
}
public int passedtime()
{
final int MAX = 51; // Upper limit is exclusive
final int MIN = -50; // Lower limit is inclusive
int waitTime = randomTime(MIN, MAX);
waitTime += 60; // Adds 1 minute to +/- 50 seconds
return waitTime;
}
/**
public int randomTime(int MIN, int MAX)
{
Random rand = new Random();
int randTime = rand.nextInt(MAX - MIN) + MIN; // Generates random numbers between MIN and MAX
return randTime;
}
public static void main(String[] args)
{
//make a room with 2 queue.
DoorKeeper aDoorKeeper = new DoorKeeper();
EventQ theEventQ = new EventQ();
aDoorKeeper.theEventList = theEventQ;
aDoorKeeper.firstQ = new CustomerQ();
aDoorKeeper.firstQ.nextCustomerQ = new CustomerQ();
while(aDoorKeeper.DoorClock<21600)
{
aDoorKeeper.CustomerComeIn();
System.out.println(aDoorKeeper.DoorClock + " ");
}
//System.out.println(aDoorKeeper.firstQ.head.traverseList());
//System.out.println(aDoorKeeper.firstQ.nextCustomerQ.head.traverseList());
//System.out.println(theEventQ.head.traverseListFromStart());
}
}
//Event.java
public class Event {
String eventType = null;
int eventClockTime = 0;
public Event() {
eventType = null;
eventClockTime = 0;
}
//The constructor with parameters
Event(String inType,int inClockTime){
eventType = inType;
eventClockTime = inClockTime;
}
// public Event generateNextEvent(){
// return new Event();
// }
public String getEventType(){
return eventType;
}
public int getClockTime() {
return eventClockTime;
}
public String getPrintTime()
{
int Hour;
int Minute;
int Second;
int inTime = getClockTime();
Hour = inTime/3600;
Minute = (inTime - Hour*3600)/60;
Second = inTime - Hour*3600 - Minute*60;
return Hour+":"+Minute+":"+Second;
}
}
//EventNode.java
import linearstructures.OrdDllist;
public class EventNode extends OrdDllist
{
Event info;
EventNode prevDlist;
EventNode nextDlist;
// boolean amEmpty;
public EventNode()
{
super();
amEmpty = true;
info = null;
}
// public boolean isEmpty()
// {
// return (amEmpty);
// }
public String traverseList()
{
// add current content to list returned by the rest of the list
if (this.isEmpty())
{
return "";
}
if (this.nextDlist.isEmpty())
{
return this.info.getPrintTime()+" - "+this.info.getEventType()+" ";
}
return this.info.getPrintTime()+" - "+this.info.getEventType()+" "+this.nextDlist.traverseList();
}
public String traverseListFromStart()
{
if (!this.prevDlist.isEmpty())
{
return this.prevDlist.traverseListFromStart();
}
// add current content to list returned by the rest of the list
if (this.isEmpty())
{
return "";
}
if (this.nextDlist.isEmpty())
{
return this.info.getClockTime()+"-"+this.info.getEventType()+" ";
}
return this.info.getClockTime()+"-"+this.info.getEventType()+" "+this.nextDlist.traverseList();
}
public String traverseEventTime()
{
if (!this.prevDlist.isEmpty())
{
return this.prevDlist.traverseEventTime();
}
// add current content to list returned by the rest of the list
if (this.isEmpty())
{
return "";
}
if (this.nextDlist.isEmpty())
{
return this.info.getPrintTime()+" - "+this.info.getEventType()+" ";
}
return this.info.getPrintTime()+" - "+this.info.getEventType()+" "+this.nextDlist.traverseList();
}
public EventNode eventInsert(Event inEvent)
{
if (this.isEmpty())
{
info = inEvent;
// am I at right end?
if (nextDlist == null)
{
// right end empty insert
nextDlist = new EventNode();
nextDlist.prevDlist = this;
}
// am I at left end?
if (prevDlist == null)
{
// right end empty insert
prevDlist = new EventNode();
prevDlist.nextDlist = this;
}
amEmpty = false;
return (this);
}
// insert to left?
if (this.info.getClockTime() > (inEvent.getClockTime()))
{
return (this.prevDlist.eventInsert(inEvent));
}
// insert between us? Next list can not be empty...
if (!(this.nextDlist.isEmpty()))
{
if (this.nextDlist.info.getClockTime() > (inEvent.getClockTime()))
{
// insert between
EventNode tempDlist = new EventNode();
tempDlist.eventInsert(inEvent);
tempDlist.prevDlist = this;
tempDlist.nextDlist = this.nextDlist;
this.nextDlist.prevDlist = tempDlist;
this.nextDlist = tempDlist;
return (this);
}
}
// later in list
this.nextDlist.eventInsert(inEvent);
return(this);
}
public static void main(String[] args)
{
System.out.println("test start");
EventNode testEventNode = new EventNode();
Event tempEvent;
tempEvent = new Event("getting up", 225);
testEventNode.eventInsert(tempEvent);
tempEvent = new Event("have breakfast", 290);
testEventNode.eventInsert(tempEvent);
tempEvent = new Event("sleeping", 210);
testEventNode.eventInsert(tempEvent);
tempEvent = new Event("take cloth on", 250);
testEventNode.eventInsert(tempEvent);
System.out.println(testEventNode.traverseListFromStart());
}
}
//EventQ.java
public class EventQ
{
EventNode head = null;
int SIMUTIME = 0;
public void eventInsert(Event inEvent)
{
if (head==null)
{
head = new EventNode();
}
head.eventInsert(inEvent);
}
public int AverageQueueLengthPerHour()
{
if (head==null)
{
head = new EventNode();
}
EventNode travNode = this.head;
int qLengthAverage=0;
int qLengthThishour =0;
int temp = 0;
for(int i = 0; i < SIMUTIME/3600; i++) // Checks data every hour
{
int startTime = i*3600;
int endTime = (i+1)*3600;
int qLengthAddedThisHour = 0;
while(travNode.info.eventClockTime >=startTime &&travNode.info.eventClockTime <= endTime)
{
if(travNode.info.eventType.contains("k")) // Search for 'k' in 'walk' for customer arriving
{
qLengthAddedThisHour++; // Increment queue length when a new group of customers arrive
}
if(travNode.info.eventType.contains("d")) // Search for 'd' in 'window' for customer leaving
{
qLengthAddedThisHour--; // Decrement queue length when a customer leaves
}
travNode = travNode.nextDlist; // Check next event
}
//System.out.println(qLengthAddedThisHour);
qLengthThishour = qLengthThishour + qLengthAddedThisHour; // Add together queue lengths
temp = temp + qLengthThishour;
}
qLengthAverage = temp/6; // Divide total by simulation time to get average
return qLengthAverage;
}
}
//Simulation1.java
public class Simulation1
{
public static void main(String[] args)
{
final int SIMUTIME = 21600;
//make a room with 2 queue.
DoorKeeper aDoorKeeper = new DoorKeeper();
EventQ theEventQ = new EventQ();
theEventQ.SIMUTIME = SIMUTIME;
aDoorKeeper.theEventList = theEventQ;
aDoorKeeper.firstQ = new CustomerQ();
aDoorKeeper.firstQ.nextCustomerQ = new CustomerQ();
Window win1 = new Window();
win1.info = "1";
Window win2 = new Window();
win2.info = "2";
win1.nextWindow = win2;
win1.currentQ = aDoorKeeper.firstQ;
win2.currentQ = aDoorKeeper.firstQ.nextCustomerQ;
win1.theEventList = theEventQ;
win2.theEventList = theEventQ;
while(aDoorKeeper.DoorClock<SIMUTIME)
{
aDoorKeeper.CustomerComeIn();
}
while(win1.windowClock < SIMUTIME && win2.windowClock < SIMUTIME)
{
win1.nextCustomer();
win2.nextCustomer();
}
//System.out.println(aDoorKeeper.firstQ.head.traverseList());
//System.out.println(aDoorKeeper.firstQ.nextCustomerQ.head.traverseList());
System.out.println("Simulation #1 - 2 Windows 2 Queues");
System.out.println(theEventQ.head.traverseEventTime());
int MaxCustomerServed = win1.windowCounter + win2.windowCounter;
System.out.println("Maximum number of customers served: "+MaxCustomerServed );
System.out.println("Average number of customers severed by window 1: "+ win1.windowCounter/6 +" /hour.");
System.out.println("Average number of customers severed by window 2: "+ win2.windowCounter/6 +" /hour.");
int totalWaitingTime = win1.totalWaitingTime+win2.totalWaitingTime;
System.out.println("Average wait time in the queue for each customer is: "+ totalWaitingTime/MaxCustomerServed +" sec." );
System.out.println("Maximum waiting time for window 1: "+ win1.maxWaitingTime +" sec." );
System.out.println("Maximum waiting time for window 2: "+ win2.maxWaitingTime +" sec." );
System.out.println("Maximum queue length for window 1: "+ win1.currentQ.maxlength +" people." );
System.out.println("Maximum queue length for window 2: "+ win2.currentQ.maxlength +" people." );
System.out.println("Average queue length per hour is: "+ theEventQ.AverageQueueLengthPerHour() +" people." );
}
}
//Simulation2.java
public class Simulation2
{
public static void main(String[] args)
{
final int SIMUTIME = 21600;
//make a room with 1 queue.
DoorKeeper aDoorKeeper = new DoorKeeper();
EventQ theEventQ = new EventQ();
theEventQ.SIMUTIME = SIMUTIME;
aDoorKeeper.theEventList = theEventQ;
aDoorKeeper.firstQ = new CustomerQ();
Window win1 = new Window();
win1.info = "1";
Window win2 = new Window();
win2.info = "2";
win1.nextWindow = win2;
win1.currentQ = aDoorKeeper.firstQ;
win2.currentQ = aDoorKeeper.firstQ;
win1.theEventList = theEventQ;
win2.theEventList = theEventQ;
while(aDoorKeeper.DoorClock<21600)
{
aDoorKeeper.CustomerComeIn();
}
while(win1.windowClock < 21600)
{
win1.nextCustomer();
}
//System.out.println(aDoorKeeper.firstQ.head.traverseList());
//System.out.println(aDoorKeeper.firstQ.nextCustomerQ.head.traverseList());
System.out.println("Simulation #2 - 2 Windows 1 Queue");
System.out.println(theEventQ.head.traverseEventTime());
int MaxCustomerServed = win1.windowCounter + win2.windowCounter;
System.out.println("Maximum number of customers served: "+MaxCustomerServed );
System.out.println("Average number of customers severed by window 1: "+ win1.windowCounter/6 +" /hour.");
System.out.println("Average number of customers severed by window 2: "+ win2.windowCounter/6 +" /hour.");
int totalWaitingTime = win1.totalWaitingTime+win2.totalWaitingTime;
System.out.println("Average wait time in the queue for each customer is: "+ totalWaitingTime/MaxCustomerServed +" sec." );
System.out.println("Maximum waiting time for window 1: "+ win1.maxWaitingTime +" sec." );
System.out.println("Maximum waiting time for window 2: "+ win2.maxWaitingTime +" sec." );
System.out.println("Maximum queue length: "+ win1.currentQ.maxlength +" people." );
System.out.println("Average queue length per hour is: "+ theEventQ.AverageQueueLengthPerHour() +" people." );
}
}
//Window.java
import java.util.Random;
public class Window
{
String info= null;
Customer currentCustomer = null;
CustomerQ currentQ = null;
int windowClock = 0;
Window nextWindow = null;
int windowCounter = 0;
int totalWaitingTime = 0;
int maxWaitingTime = 0;
EventQ theEventList = null;
public void linkQ(CustomerQ AQ)
{
currentQ = AQ;
}
public void nextCustomer()
{
if(currentCustomer != null) // Check to see if there is a customer
{
DoJob(); // Find next customer
nextCustomer(); // Process next customer
}
else
{
Window firstOpenWindow = this;
if(currentQ.nextCustomerQ == null) // Only one queue (Simulation #2)
{
firstOpenWindow = findNextWindow(); // Sets next available window
firstOpenWindow.currentCustomer = firstOpenWindow.currentQ.leave(currentCustomer); // Remove customer from queue
if(firstOpenWindow.currentCustomer.getTimeJoindQueue() > windowClock)
{
windowClock = firstOpenWindow.currentCustomer.getTimeJoindQueue(); // Adjusts the clock to match the customer
}
firstOpenWindow.DoJob(); // Process the customer
}
else // More than one queue (Simulation #1)
{
currentCustomer = currentQ.leave(currentCustomer); // Remove customer from queue
if(firstOpenWindow.currentCustomer.getTimeJoindQueue() > windowClock)
{
windowClock = firstOpenWindow.currentCustomer.getTimeJoindQueue(); // Adjusts the clock to match the customer
}
firstOpenWindow.DoJob(); // Process the customer
}
}
}
public Window findNextWindow()
{
Window firstOpenWindow = this;
Window travWindow = this;
while(travWindow.nextWindow != null) // Traverse through all windows
{
// Checks to see if the next window clock is less than the current window clock
if(travWindow.windowClock < firstOpenWindow.windowClock)
{
firstOpenWindow = travWindow; // Sets window to one with lowest clock time
}
travWindow = travWindow.nextWindow; // Check next window
}
if(travWindow.windowClock < firstOpenWindow.windowClock)
{
// Checks to see if the last window clock is less than the current window clock
firstOpenWindow = travWindow;
}
return firstOpenWindow;
}
public void DoJob() {
if(null == currentCustomer) // Check to see if there is a customer
{
nextCustomer(); // Find next customer
DoJob(); // Process next customer
}
else
{
if(currentQ.nextCustomerQ == null) // Only one queue (Simulation #2)
{
if(currentCustomer.getTimeJoindQueue() > windowClock)
{
windowClock = currentCustomer.getTimeJoindQueue(); // Adjusts the clock to match the customer
}
currentCustomer.SetTimeToWindow(windowClock); // Sets time stamp for when customer reaches the window
Event newEvent = new Event("Customer " + currentCustomer.getNum() + " at the window"+ " (" + info + ")", windowClock);
theEventList.eventInsert(newEvent); // Inserts a new event when the customer reaches the window
windowClock += servingTime(); // Increments the clock time with the time it takes to serve a customer
currentCustomer.setTimeToLeave(windowClock); // Sets time stamp for when customer leaves the window
newEvent = new Event("Customer " + currentCustomer.getNum() + " leave.", windowClock);
theEventList.eventInsert(newEvent); // Inserts a new event when the customer is leaving
currentCustomer.customerWaitingTime = currentCustomer.getTimeToWindow() - currentCustomer.getTimeJoindQueue();
totalWaitingTime += currentCustomer.customerWaitingTime; // Records the total time waited by the customers
if(maxWaitingTime < currentCustomer.customerWaitingTime)
{
maxWaitingTime = currentCustomer.customerWaitingTime; // Records the max wait time for a customer in the queue
}
currentCustomer = null; // Remove the customer from the window
windowCounter++; // Counts the number of customers served
}
else// More than one queue (Simulation #1)
{
if(currentCustomer.getTimeJoindQueue() > windowClock)
{
windowClock = currentCustomer.getTimeJoindQueue(); // Adjusts the clock to match the customer
}
currentCustomer.SetTimeToWindow(windowClock); // Sets time stamp for when customer reaches the window
Event newEvent = new Event("Customer " + currentCustomer.getNum() + " at the window"+ " (" + info + ")", windowClock);
theEventList.eventInsert(newEvent); // Inserts a new event when the customer reaches the window
windowClock += servingTime(); // Increments the clock time with the time it takes to serve a customer
currentCustomer.setTimeToLeave(windowClock); // Sets time stamp for when customer leaves the window
newEvent = new Event("Customer " + currentCustomer.getNum() + " leave.", windowClock);
theEventList.eventInsert(newEvent); // Inserts a new event when the customer is leaving
currentCustomer.customerWaitingTime = currentCustomer.getTimeToWindow() - currentCustomer.getTimeJoindQueue();
totalWaitingTime += currentCustomer.customerWaitingTime; // Records the total time waited by the customers
if(maxWaitingTime < currentCustomer.customerWaitingTime)
{
maxWaitingTime = currentCustomer.customerWaitingTime; // Records the max wait time for a customer in the queue
}
currentCustomer = null; // Remove the customer from the window
windowCounter++; // Counts the number of customers served
}
}
}
public int servingTime()
{
final int MAX = 66; // Upper limit is exclusive
final int MIN = -65; // Lower limit is inclusive
int waitTime = randomTime(MIN, MAX);
waitTime += 120; // Adds 2 minutes to +/- 65 seconds
return waitTime;
}
public int randomTime(int MIN, int MAX)
{
Random rand = new Random();
int randTime = rand.nextInt(MAX - MIN) + MIN; // Generates random numbers between MIN and MAX
return randTime;
}
// public static void main(String[] args)
// {
// //make a room with 2 queue.
// DoorKeeper aDoorKeeper = new DoorKeeper();
// EventQ theEventQ = new EventQ();
// aDoorKeeper.theEventList = theEventQ;
// aDoorKeeper.firstQ = new CustomerQ();
// aDoorKeeper.firstQ.nextCustomerQ = new CustomerQ();
//
// Window win1 = new Window();
// win1.info = "1";
// Window win2 = new Window();
// win2.info = "2";
// win1.nextWindow = win2;
// win1.currentQ = aDoorKeeper.firstQ;
// win2.currentQ = aDoorKeeper.firstQ.nextCustomerQ;
// win1.theEventList = theEventQ;
// win2.theEventList = theEventQ;
//
// while(aDoorKeeper.DoorClock<21600)
// {
// aDoorKeeper.CustomerComeIn();
// }
// while(win1.windowClock < 21600 && win2.windowClock < 21600)
// {
// win1.nextCustomer();
// win2.nextCustomer();
// }
//
// //System.out.println(aDoorKeeper.firstQ.head.traverseList());
// //System.out.println(aDoorKeeper.firstQ.nextCustomerQ.head.traverseList());
// System.out.println(theEventQ.head.traverseListFromStart());
// }
public static void main(String[] args)
{
//make a room with 1 queue.
DoorKeeper aDoorKeeper = new DoorKeeper();
EventQ theEventQ = new EventQ();
aDoorKeeper.theEventList = theEventQ;
aDoorKeeper.firstQ = new CustomerQ();
Window win1 = new Window();
win1.info = "1";
Window win2 = new Window();
win2.info = "2";
win1.nextWindow = win2;
win1.currentQ = aDoorKeeper.firstQ;
win2.currentQ = aDoorKeeper.firstQ;
win1.theEventList = theEventQ;
win2.theEventList = theEventQ;
while(aDoorKeeper.DoorClock<21600){
aDoorKeeper.CustomerComeIn();
}
while(win1.windowClock < 21600)
{
win1.nextCustomer();
}
//System.out.println(aDoorKeeper.firstQ.head.traverseList());
//System.out.println(aDoorKeeper.firstQ.nextCustomerQ.head.traverseList());
System.out.println(theEventQ.head.traverseListFromStart());
}
}