Going back to the grocery line queue. At the end of the program, it will output how many total customers I serviced, and it is supposed to output my maximum line length during the simulation.
I think its obvious that I will use an "if" statement, but how do you determine your max queue length?
import java.util.LinkedList;
import java.util.Queue;
import java.util.Random;
public class GroceryStoreCopy {
public static void main(String[] args) {
int newCust;
int serviceTime = 0;
int totalCust = 0;
int maxQ = 0;
Queue<Integer>custQ = new LinkedList();
for(int i = 60; i >= 0; i--){//60 minutes of activity
Random r = new Random();
newCust = r.nextInt(4) + 1;//25% random number will be 1, if random number equals 1, add cust to q
Random time = new Random();
serviceTime = time.nextInt(5) + 1;
serviceTime--;
if(newCust == 1){
custQ.add(1);//if customer has been added to line, add cust to q
System.out.println("\nNew customer has been added!, New queue length is now " + custQ.size());
totalCust += newCust;
if(serviceTime == 0){
custQ.remove();
System.out.println("\nCustomer serviced and removed from queue. New queue length is now " + custQ.size());
}
}
}
for(int i = 1; i<= 60; i++){
System.out.print("-");//shows the elapsed time
}
System.out.println("\nTotal number of customers serviced: " + totalCust);
System.out.println("Maximum line length during the simulation: " + maxQ);
}
}
Any suggestions on creating a Customer class with serviceTime? and just call it from the loop