I am trying to figure out the best way to approach this.....
I am creating a grocery line simulation using a queue, and I know that I will want to create a Customer class that has the information for serviceTime.
I am weak on creating classes, what I want to happen is everytime the program iterates, it will check to see if a new customer has been added to the queue, if so it will output ("New customer added! Queue length is now...: ");
I believe I am good on that part of the program, but how do I implement the time decrementer?
Each time a new customer is at the beginning of the queue, a random number from 1 - 5 is generated and this will be their serviceTime, at the end of their serviceTime they will be removed from the queue wiith the output("customer serviced and removed from queue, queue length is now...");
at the end, I want to calculate the number of customers serviced, and the max length of the queue,
This is what I have so far...
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;
Queue<Integer>custQ = new LinkedList();
for(int i = 1; i <= 60; i++){
System.out.print("-");//shows the elapsed time
Random time = new Random();
serviceTime = time.nextInt(5) + 1;
Random r = new Random();
newCust = r.nextInt(4) + 1;//25% chance new customer will be added to q every minute
if(newCust == 1){
custQ.add(1);//if customer has been added to line, add cust to q
}
}
System.out.println("\nCustomer " + custQ.peek() + " your service time is: " + serviceTime + " minutes. New queue size is: " + custQ.size());
}
}
I know this isnt much, but i reaallyy need help