Waiting Queue Simulation

  • (2 Pages)
  • +
  • 1
  • 2

23 Replies - 1406 Views - Last Post: 02 April 2013 - 06:39 PM Rate Topic: -----

#16 SpiderD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 30-March 13

Re: Waiting Queue Simulation

Posted 02 April 2013 - 11:03 AM

Nice the whole thing is working Im on the last part which the user input.

Lets say that the user can input the number of cashiers. For this Im using the Scanner methods. Which is:
Scanner input = new Scanner (System.in);   
System.out.println("Enter you sentence man!!!!");



If there are 2 cashier it mean the whole processing will run twice fast, if there are 3 cashier then processing customer will run 3x faster. What ive been trying is to put the whole while loop inside a if statement but Its not working for me is there a another way to run things fast based on the user input ?
Was This Post Helpful? 0
  • +
  • -

#17 SpiderD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 30-March 13

Re: Waiting Queue Simulation

Posted 02 April 2013 - 11:21 AM

Nice the whole thing is working Im on the last part which the user input.

Lets say that the user can input the number of cashiers. For this Im using the Scanner methods. Which is:
Scanner input = new Scanner (System.in);
System.out.println("Enter the number of cashiers HERE");   
String userinput = input.nextLine()



If there are 2 cashier it mean the whole processing will run twice fast, if there are 3 cashier then processing customer will run 3x faster. What ive been trying is to put the whole while loop inside a if statement but Its not working for me is there a another way to run things fast based on the user input ?
[/quote]
Was This Post Helpful? 0
  • +
  • -

#18 SpiderD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 30-March 13

Re: Waiting Queue Simulation

Posted 02 April 2013 - 11:32 AM

Nice the whole thing is working Im on the last part which the user input.

Lets say that the user can input the number of cashiers. For this Im using the Scanner methods. Which is:
Scanner input = new Scanner (System.in);
System.out.println("Enter the number of cashiers HERE");   
String userinput = input.nextLine()



If there are 2 cashier it mean the whole processing will run twice fast, if there are 3 cashier then processing customer will run 3x faster. What ive been trying is to put the whole while loop inside a if statement but Its not working for me is there a another way to run things fast based on the user input ?


Also I understand that im using a array string list and picking a random customer from the list and putting it into the queue. When I check the queue its outputting this:
Customer@21346812, Customer@779c86c5, Customer@45542cdc, Customer@194d4313, Customer@1f6ea15f, Customer@18247418, Customer@141e00a



Shouldn't it be putting into the queue Customer@"watevea the customer name is" instead of the random numbers and letters.
And then later on in the code where we are outputting the cus.name I tested it if i remove the .name it shows the random numbers and letters. I check the
this.name = name;
but dont understandly competly how its converting the random number and letter into the corresponding customer names.

View PostSpiderD, on 02 April 2013 - 11:30 AM, said:

Nice the whole thing is working Im on the last part which the user input.

Lets say that the user can input the number of cashiers. For this Im using the Scanner methods. Which is:
Scanner input = new Scanner (System.in);
System.out.println("Enter the number of cashiers HERE");   
String userinput = input.nextLine()



If there are 2 cashier it mean the whole processing will run twice fast, if there are 3 cashier then processing customer will run 3x faster. What ive been trying is to put the whole while loop inside a if statement but Its not working for me is there a another way to run things fast based on the user input ?


Also I understand that im using a array string list and picking a random customer from the list and putting it into the queue. When I check the queue its outputting this:
Customer@21346812, Customer@779c86c5, Customer@45542cdc, Customer@194d4313, Customer@1f6ea15f, Customer@18247418, Customer@141e00a



Shouldn't it be putting into the queue Customer@"watevea the customer name is" instead of the random numbers and letters.
And then later on in the code where we are outputting the cus.name I tested it if i remove the .name it shows the random numbers and letters. I check the
this.name = name;
but dont understandly competly how its converting the random number and letter into the corresponding customer names, can you explain this please ?


Nice the whole thing is working Im on the last part which the user input.

Lets say that the user can input the number of cashiers. For this Im using the Scanner methods. Which is:
Scanner input = new Scanner (System.in);
System.out.println("Enter the number of cashiers HERE");   
String userinput = input.nextLine()



If there are 2 cashier it mean the whole processing will run twice fast, if there are 3 cashier then processing customer will run 3x faster. What ive been trying is to put the whole while loop inside a if statement but Its not working for me is there a another way to run things fast based on the user input ?


Also I understand that im using a array string list and picking a random customer from the list and putting it into the queue. When I check the queue its outputting this:
Customer@21346812, Customer@779c86c5, Customer@45542cdc, Customer@194d4313, Customer@1f6ea15f, Customer@18247418, Customer@141e00a



Shouldn't it be putting into the queue Customer@"watevea the customer name is" instead of the random numbers and letters.
And then later on in the code where we are outputting the cus.name I tested it if i remove the .name it shows the random numbers and letters. I check the
this.name = name;
but dont understandly competly how its converting the random number and letter into the corresponding customer names.

[quote name='SpiderD' date='02 April 2013 - 11:30 AM' timestamp='1364927416' post='1830387']
Nice the whole thing is working Im on the last part which the user input.

Lets say that the user can input the number of cashiers. For this Im using the Scanner methods. Which is:
Scanner input = new Scanner (System.in);
System.out.println("Enter the number of cashiers HERE");   
String userinput = input.nextLine()



If there are 2 cashier it mean the whole processing will run twice fast, if there are 3 cashier then processing customer will run 3x faster. What ive been trying is to put the whole while loop inside a if statement but Its not working for me is there a another way to run things fast based on the user input ?


Also I understand that im using a array string list and picking a random customer from the list and putting it into the queue. When I check the queue its outputting this:
Customer@21346812, Customer@779c86c5, Customer@45542cdc, Customer@194d4313, Customer@1f6ea15f, Customer@18247418, Customer@141e00a



Shouldn't it be putting into the queue Customer@"watevea the customer name is" instead of the random numbers and letters.
And then later on in the code where we are outputting the cus.name I tested it if i remove the .name it shows the random numbers and letters. I check the
this.name = name;
but dont understandly competly how its converting the random number and letter into the corresponding customer names, can you explain this please ?

Nice the whole thing is working Im on the last part which the user input.

Lets say that the user can input the number of cashiers. For this Im using the Scanner methods. Which is:
Scanner input = new Scanner (System.in);
System.out.println("Enter the number of cashiers HERE");   
String userinput = input.nextLine()



If there are 2 cashier it mean the whole processing will run twice fast, if there are 3 cashier then processing customer will run 3x faster. What ive been trying is to put the whole while loop inside a if statement but Its not working for me is there a another way to run things fast based on the user input ?


Also I understand that im using a array string list and picking a random customer from the list and putting it into the queue. When I check the queue its outputting this:
Customer@21346812, Customer@779c86c5, Customer@45542cdc, Customer@194d4313, Customer@1f6ea15f, Customer@18247418, Customer@141e00a



Shouldn't it be putting into the queue Customer@"watevea the customer name is" instead of the random numbers and letters.
And then later on in the code where we are outputting the cus.name I tested it if i remove the .name it shows the random numbers and letters. I check the
this.name = name;
but dont understand competly how its converting the random number and letter into the corresponding customer names can you explain this please ?
Was This Post Helpful? 0
  • +
  • -

#19 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: Waiting Queue Simulation

Posted 02 April 2013 - 01:36 PM

Quote

Also I understand that im using a array string list and picking a random customer from the list and putting it into the queue. When I check the queue its outputting this:
Customer@21346812, Customer@779c86c5, Customer@45542cdc, Customer@194d4313, Customer@1f6ea15f, Customer@18247418, Customer@141e00a 



These are the memory address of your Customer object
Add to your Customer class a toString() method which is invoke when a String representation of a Customer object is required

    public String toString() {
      return name;
    }


or if you want full details:
    public String toString() {
      return name + " queued at: " + time;
    }


Was This Post Helpful? 0
  • +
  • -

#20 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2205
  • View blog
  • Posts: 5,239
  • Joined: 10-September 10

Re: Waiting Queue Simulation

Posted 02 April 2013 - 01:44 PM

It'd be interesting to see the OP's current code.
Was This Post Helpful? 0
  • +
  • -

#21 SpiderD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 30-March 13

Re: Waiting Queue Simulation

Posted 02 April 2013 - 02:12 PM

View PostGregBrannon, on 02 April 2013 - 01:44 PM, said:

It'd be interesting to see the OP's current code.


Im just trying to figure out how to take the user input of cashiers to make the processing run faster.
Was This Post Helpful? 0
  • +
  • -

#22 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2205
  • View blog
  • Posts: 5,239
  • Joined: 10-September 10

Re: Waiting Queue Simulation

Posted 02 April 2013 - 02:28 PM

So what have you coded to get the user's input and what questions do you have about that code? Post the code with any errors or questions you have. Someone will help you figure it out, but you have to be a contributing partner in the figuring-it-out process.
Was This Post Helpful? 0
  • +
  • -

#23 SpiderD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 30-March 13

Re: Waiting Queue Simulation

Posted 02 April 2013 - 05:09 PM

Oki ive done it here what I simply did how silly I am:

This is the user input part
Scanner input = new Scanner (System.in);
System.out.println("Enter the number of cashiers available HERE: ");
int cashier = input.nextInt();



And in the loop where the piece of code that works out the sleep time I added division of the the cashier userinput:
int wait = ran.nextInt(2) + 1;
try 
{
Thread.sleep((wait * 1000)/ cashier);
}


If the user input what ever number I simply state to divide the wait interval value of the user input hence simulating that there are more then one cashier working at the same time so everything get processed faster.

However lets say there are 2 cashier the code is still outputting 1 by 1 each customer processed. How do I make it remove from the queue nth of customer corresponding tot eh user neth number of cashier and then make it output nth of removed customer from the queue at the same time.
Was This Post Helpful? 0
  • +
  • -

#24 SpiderD  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 30-March 13

Re: Waiting Queue Simulation

Posted 02 April 2013 - 06:39 PM

I have another problem Im trying to add catch letter exception for the
int cashier = input.nextInt();

but if I use any try or if statement the
Thread.sleep((wait * 1000)/ cashier);

get any error because the
int cashier = input.nextInt()
is within its own curly brackets.

How do I add a exception value without my cashier value in the sleep syntax becoming invalid.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2