Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 4 of 4 FirstFirst ... 234
Results 76 to 79 of 79

Thread: Queue Simulation

  1. #76
    Member
    Join Date
    Apr 2013
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Queue Simulation

    Norm can you check this ive got two System.currentTimeMillis() for the arrival_time and exit_time but how do state that the arrival_time corresponds to the add customer System.currentTimeMillis() and the wait_time corresponds to the remove customer System.currentTimeMillis() ?
    public class Customer
    	{
    		int id;
    		long arrival_time = System.currentTimeMillis();
    		long exit_time = System.currentTimeMillis();
    		String cashier;
    		long wait_time = exit_time - arrival_time;
     
    		public String toString() 
    		{
    			return "Customer id="+id + " arvTm="+arrival_time;
    	    }
    	}

                                 try 
    				{
    					Thread.sleep(wait * 1);
    					line.add(new Station());
    					System.currentTimeMillis();
    					System.out.println(line);
    				}
    for (int i = 0; i < max_customers; i++)
    		if (cashiers != null)
    		{
    			cashiers[0] = line.poll();
    			System.currentTimeMillis();
    			System.out.println(line);
    		}

  2. #77
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Queue Simulation

    Don't call the System.currentTimeMillis() method in the constructor for the exit time. The exit time should be set when the customer object exits the wait queue by setting exit_time to System.currentTimeMillis().
    Setting arrival_time in the constructor is only needed for the case where the customer is added to the wait queue. The first customers into the model could go directly to the cashier and not wait in the wait queue.

    Calling System.currentTimeMillis() without saving the value it returns makes no sense.

    This is very silly: * 1
    If you don't understand my answer, don't ignore it, ask a question.

  3. #78
    Member
    Join Date
    Apr 2013
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Queue Simulation

    The *1 I can change later i just put that there to test everything quickly. So your saying that I should remove the System.currentTimeMillis() ? And yes or are right about no wait_time exist for the first customer however I still need to output the wait_time even for the first customer which would be 0.

    So I known how to call the System.currentTimeMillis(); but how do I save the value and return it to the arrival_time and exit_time ? And Ive tested what would be outputted from the toString() and its this
    Customer id=0 arvTm=1365195765216
    how come the customer ID is 0 and the are not numbered and the arvTm is coming up with random numbers.

  4. #79
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Queue Simulation

    how come the customer ID is 0 and the are not numbered and the arvTm is coming up with random numbers.
    The initial value of an int is 0. If it is not assigned a different value, its value will stay at 0.

    Read the API doc for the currentTimeMillis() method to see what value it returns.

    how do I save the value
    Use an assignment statement.
    If you don't understand my answer, don't ignore it, ask a question.

Page 4 of 4 FirstFirst ... 234

Similar Threads

  1. Multi-queue simulation theory
    By Herah in forum Object Oriented Programming
    Replies: 4
    Last Post: April 4th, 2013, 10:38 PM
  2. Cash Register Simulation Help
    By Gont in forum Object Oriented Programming
    Replies: 1
    Last Post: September 22nd, 2012, 06:58 PM
  3. create a simulation
    By aecosis in forum Java IDEs
    Replies: 3
    Last Post: June 12th, 2012, 08:55 AM
  4. Blackjack simulation program help
    By senorfletch in forum Java Theory & Questions
    Replies: 2
    Last Post: April 5th, 2011, 09:22 AM
  5. [SOLVED] Dice Rolling Simulation
    By SnarkKnuckle in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 12th, 2011, 06:51 PM