Saturday, April 11, 2015

Parameter help?
































I am creating a program to simulate a store. I have several methods listed below that imitate a customer arriving to the store, and a customer departing the store. I have a simulate method that simulates the entire store day. In my simulate() method under in the departure part, I cannot figure out how to call the number of the cashier for the parameter. I call the customerDeparts() method line 111, 112 and need two parameters, num of cashier, and currentTime. Any ideas on how to call the value of the cashier? Thanks.
















































Java Code:





































/********************************************
* Customer to cashier
* @param number of cashier
********************************************/
private void customerToCashier (int num){

//Move first customer to cashier
if(inLine.size() > 0){
cashiers[num] = inLine.remove(0);
}

//Update customers served
customersServed ++;

//Update total wait time
waitTime += currentTime - cashiers[num].getArrivalTime();

//Future time for departure
double futureTime = currentTime + futureEventTime(serviceTime);

//Create new departure event + add to priority queue
GVevent next = new GVevent(GVevent.DEPARTURE, futureTime, num);
myEvents.add(next);

}

/********************************************
* Customer Arrives
* @param time of customer getting in line
********************************************/
public void customerArrives (double t){

//Update current time
currentTime = t;

//Create new customer, add to line
Customer c = new Customer(t);
inLine.add(c);

//Check for if longest line
if(inLine.size() > longestLine){
longestLine = inLine.size();
longestTime = currentTime;
}

//Move first customer in line to available cashier
int i = cashierAvailable();
if(i >= 0){
customerToCashier(i);
}

//Generate future time
double n = futureEventTime(arrivalTime);

//Check time to make sure not after closing, add to queue
if(n < CLOSE){
GVevent next = new GVevent(GVevent.ARRIVAL, t);
myEvents.add(next);
}
}

/********************************************
* Customer Departs
* @param num of cashier available
* @param time
********************************************/
public void customerDeparts (int num, double t){

//Update current time
currentTime = t;

//Retrieve customer from cashier[num]
customerToCashier(num);

//Check to see if cashier gets new customer
if(inLine.size() > 0){
cashiers[num] = inLine.remove(0);
}else{
cashiers[num] = null;
}

}

/********************************************
* Simulation of store
********************************************/
public void simulate(){

//Reset Parameter
currentTime = OPEN;
customersServed = 0;
myEvents = new PriorityQueue <GVevent> ();

//First Arrival
GVevent a = new GVevent(GVevent.ARRIVAL, currentTime);
myEvents.add(a);

//Continue as long as there are events
while(!myEvents.isEmpty()){

//Get next event, update time
a = myEvents.poll();
currentTime = a.getTime();

//Customer arrives
if(a.isArrival()){
customerArrives(currentTime);
}

//Customer Departs
if(a.isDeparture()){
customerDeparts(, currentTime);
}
}

//Print Results
calcResults();
}


































































No comments:

Post a Comment