Hi im trying to simulate a waiting queue by using Java. What my program must consist of:
- The user input nth number of cashiers
- There minimum of 10 customers will arrive in the queue in random intervals.
- When a cashier is free the the next customer is line will be processed.
- The program must output each stage of the queue as well as the time each customer spent in the queue.
- Oki so what I have so is a empty queue object, a random string list generator which sends the strings to the queue.
However what problems im having is the random string generator is picking duplicates in the loop, how do I fix this ? Also how do I make it send the customers to the queue in intervals of 0.5 sec and I need to record the time they enter the queue and leave the queue so then I can output the time spent in the queue. Im stuck dont know what to do now ?
public static Queue<String> line = new LinkedList<String> (); public static void main(String[] args) { String[] list = {"a", "b", "c", "e", "f", "g", "h", "i", "j", "k", }; int customer = list.length; for (int x = 0; x < customer; x++ ) { int cus = (int) (Math.random() * customer); line.add(list[cus]); } }