March 30th, 2013, 01:05 PM
Waiting Queue Simulation
Hi everyone Ive got this homework to complete basically I need to make a waiting queue simulation with Java by using the Queue, LinkedList methods. The points are:
There is only 1 queue.
Consisting of 10 customers arriving at random intervals which u can label them.
Customers time in queue will be measured.
The user should input how many cashiers is.(More cashiers means faster process of customers).
I need to output the different stages of the queue and each customer time in the queue.
So far this is what Im able to get by the way im using Eclipse:
public class Station
public static Queue<String> Customer = new LinkedList<String> ();
public static void main(String args)
System.out.println("Enter the number of Cashiers here: ");
Scanner userinput = new Scanner(System.in);
String cashier = userinput.nextLine(); System.out.println(Customer.size());
March 30th, 2013, 03:46 PM
Please edit the post and fix the formatting of the code. It's line ends are missing.
March 30th, 2013, 05:01 PM
Sorry about that there you go.
March 30th, 2013, 05:16 PM
What do you need now?
BTW java naming standards recommend variable names start with a lowercase letter: customer vs Customer
March 30th, 2013, 05:50 PM
I know that you can use the method to remove the first object in the queue. However what Im trying to do is the user inputs the number of cashiers available to process each object and 10 objects in total.
I need to output each object from queue and the time it took to enter and exit the queue.
But I dont understand how to implement this ?
If the user inputs 2 cashiers that means two objects can be removed at once, and if the input was 3 cashiers then 3 object removed at once and so on.
The 2nd thing is how do I implement the time it took for each object enter the queue and exit the queue.
All this needs to outputted using System.out.print();
March 30th, 2013, 06:12 PM
To run a simulation, you need to generate a sequence of events that will take place at some time in the future. There can be several events that occur at the same time.
For example using a random number generator there could be scheduled the arrival of two customers in 15 minutes from now. Another event could be a customer exiting a checkout line in 5 minutes. All these events would be put in a queue ordered by the soonest event first.
These concepts should have been discussed in the course lectures.
March 30th, 2013, 06:26 PM
Oki so if i set up a random number generator with the customer numbers (1,2,3,4,5,6,7,8,9,10) customers arriving at different times within 1 minutes max.
And then when the random number is generated send it into the new queue object to be processed. However how do I set up the cashiers which the user can input how many cashiers exist ?
Then after that how do I record the time it take for each customer to get processed ?
March 30th, 2013, 07:11 PM
There is lots of design work to do before writing any code.
Each customer needs:
a random "time to process" value to control how long it takes for a clerk to process him once he enters a check out station.
The time he entered the queue waiting for a clerk.
March 30th, 2013, 07:16 PM
Can you help me with the design please, so far I ive made this random 10 character letter.
final String customers = "ABCDEFGHIJHLMNOPQRSTXYWZ";
final int N = customers.length();
Random r = new Random();
for (int i = 0; i < 10; i++)
March 30th, 2013, 07:32 PM
Start making a list of the steps and ideas for the design. Don't write code until the design is done.
March 30th, 2013, 07:57 PM
x number of cashier based on what the user inputs.
Every customer but have a time on how long they spent waiting in the queue.
waiting time = (time exit the queue) - (time entered the queue)
Every customers will be labeled with letters between A-Z and a random time between 0 sec - 30 sec will be given to that random letter.
Which is the (time entered the queue).
So far thats what I can sum up.
March 30th, 2013, 08:17 PM
processing time at the cashier station
moving a customer to a cashier station from the waiting queue when a cashier is available
What is the 0-30sec value given to a random letter?
March 30th, 2013, 09:14 PM
0 sec - 3 sec stuff was about before the random letter is generated I would give the letters a time before they enter the queue.
However your method is better to process the time at the cashier station.
I have the random letter generator, I have the empty queue to put in the 10 letters representing the customers.
But I no idea how to implement the cashier station to process the customer and record the time.
March 31st, 2013, 05:56 AM
What about the customer arrival rate? How long between customers arriving at the queue?
March 31st, 2013, 12:29 PM
can i set the arrival rate between customers at 20 seconds I dont want the program running too long