Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting items to remove from queue in a do while loop
    primarykey
    data
    text
    <pre><code> public class Queue { public static void main(String[] args) { Queue&lt;Integer&gt; myQueue = new LinkedList&lt;Integer&gt;(); Random generator = new Random(); int totalTime = 60; int lineSize=0; int serviceTime; int currentPatronTimeLeft=50; int timeKeeper; int newPatron; int totalCheckedOut=0; do { //for new customer 25%of the time serviceTime = generator.nextInt(5) + 1; newPatron = generator.nextInt(4) + 1; //nested if else to control the adding and removing of items based on service time and the 25% stat if(newPatron == 1) { myQueue.add( new Integer(serviceTime)); System.out.println("a new customer has been added to line"); lineSize++; System.out.println("The Queue size is now: "+ lineSize); currentPatronTimeLeft = myQueue.peek(); } else if(currentPatronTimeLeft == 0 &amp;&amp; lineSize != 0) { myQueue.poll(); lineSize--; System.out.println("A customer has been removed from the queue"); totalCheckedOut++; System.out.println("The Queue size is now: "+ lineSize); } else if (lineSize != 0) { currentPatronTimeLeft =myQueue.peek(); } currentPatronTimeLeft--; totalTime--; System.out.println(); System.out.println("---------------------------------------------------"); }while(totalTime != 0); System.out.println(); } </code></pre> <p>}</p> <p>I am having trouble getting my program to remove people from the queue after they have should have completed their serviceTime. any help would be greatly appreciated. the program produces an output somewhat like this</p> <pre><code>--------------------------------------------------- --------------------------------------------------- a new customer has been added to line The Queue size is now: 1 --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- a new customer has been added to line The Queue size is now: 2 --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- a new customer has been added to line The Queue size is now: 3 --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- a new customer has been added to line The Queue size is now: 4 --------------------------------------------------- --------------------------------------------------- a new customer has been added to line The Queue size is now: 5 --------------------------------------------------- a new customer has been added to line The Queue size is now: 6 --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- a new customer has been added to line The Queue size is now: 7 --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- a new customer has been added to line The Queue size is now: 8 --------------------------------------------------- --------------------------------------------------- a new customer has been added to line The Queue size is now: 9 --------------------------------------------------- a new customer has been added to line The Queue size is now: 10 --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- a new customer has been added to line The Queue size is now: 11 --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- a new customer has been added to line The Queue size is now: 12 --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- a new customer has been added to line The Queue size is now: 13 --------------------------------------------------- a new customer has been added to line The Queue size is now: 14 --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- --------------------------------------------------- </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload