Page 1 of 3 123 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    20
    Rep Power
    0

    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:
    Code:
    import java.util.LinkedList; 
    import java.util.Queue;
     import java.util.Scanner; 
    
    public class Station 
    { 
    public static Queue<String> Customer = new LinkedList<String> ();
    
    public static void main(String[] args) 
    { 
    Customer.add("A"); 
    Customer.add("B");
    Customer.add("C"); 
    Customer.add("D"); 
    Customer.add("F"); 
    Customer.add("G"); 
    Customer.add("H"); 
    Customer.add("I"); 
    Customer.add("J"); 
    Customer.add("K");
    
    Customer.size();
    Customer.peek(); 
    
    System.out.println("Enter the number of Cashiers here: "); 
    Scanner userinput = new Scanner(System.in); 
    String cashier = userinput.nextLine(); System.out.println(Customer.size()); 
    } 
    }
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    Please edit the post and fix the formatting of the code. It's line ends are missing.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    20
    Rep Power
    0
    Sorry about that there you go.
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    What do you need now?

    BTW java naming standards recommend variable names start with a lowercase letter: customer vs Customer
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    20
    Rep Power
    0
    I know that you can use the
    Code:
    .remove();
    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();
  10. #6
  11. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    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.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    20
    Rep Power
    0
    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 ?
  14. #8
  15. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    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.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    20
    Rep Power
    0
    Can you help me with the design please, so far I ive made this random 10 character letter.

    Code:
    final String customers = "ABCDEFGHIJHLMNOPQRSTXYWZ";
    final int N = customers.length(); 
    Random r = new Random(); 
    for (int i = 0; i < 10; i++) 
    { 
    System.out.print(customers.charAt(r.nextInt(N))); 
    }
  18. #10
  19. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    Start making a list of the steps and ideas for the design. Don't write code until the design is done.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    20
    Rep Power
    0
    10 Customer

    1 Queue

    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.
    Which is:

    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.
  22. #12
  23. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    How about
    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?
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    20
    Rep Power
    0
    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.
  26. #14
  27. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,696
    Rep Power
    347
    What about the customer arrival rate? How long between customers arriving at the queue?
  28. #15
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    20
    Rep Power
    0
    can i set the arrival rate between customers at 20 seconds I dont want the program running too long
Page 1 of 3 123 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo