Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

this is a single line que in java. please translate the bottom pseudocode. Creat

ID: 3764881 • Letter: T

Question

this is a single line que in java. please translate the bottom pseudocode.

Create a package called singleline in which you will write a program class called SimulateSingleline.java that, as the name suggests, simulates a single-singleline singleline. Do so by implementing the algorithm below. Total wait time = 0 number of customers = 0 line free = true time until line free = 0 create a new queue (linked list of integers) for second from 0 to 3600 Generate a random integer between 0 and 100 If the number is less than or equal to 2 // A customer has arrived! Increment number of customers Put that customer's arrival time into the queue end if If the line is free then If the queue is not empty then Dequeue that person's arrival time wait time = current time - arrival time Add the wait time to the total wait time Set time until line free to 60 end if else decrement time until line free end if end print average wait time (total wait time / number of customers) print number of customers still waiting in the queue Your program may consist of just the main method but other ways to do this are fine. Use the LinkedList class in Java to implement the queue. Use the instance methods void add (Integer e), which adds an integer to the end of the queue, and Integer remove (). which removes the integer from the front of the queue. When done correctly, the package singleline will contain the file SimulateSingleline. java. Zip the singleline folder

Explanation / Answer

/*NOTE : Create a folder with name "singleline"

put java file in singleline folder. filename should be SimulateSinglrline.java */

package singleline;

import java.util.LinkedList;
import java.util.Random;

class SimulateSingleline
{
   public static void main(String args[])
   {
       // Total wait time = 0
       int total_wait_time = 0;
       // number of customers = 0
       int num_of_cust = 0;
       // line free = true
       boolean line_free = true;
       // time until line free = 0;
       int time_until_line_free = 0;
      
       // creating linked list of Integers
       LinkedList<Integer> queue = new LinkedList<Integer>();
       // creating object of Random
       Random randomGenerator = new Random();
       // for second from 0 to 3600
       for (int current_time = 0; current_time <= 3600; current_time++)
       {
           // Generate a random integer between 0 and 100
           int randomInt = randomGenerator.nextInt(100);
           // if the number is less than or equal to 2
           if(randomInt<=2)
           {
               // A customer has arrived
               // increment number of customers
               num_of_cust++;
               // Add customers arrival to end of queue
               queue.addLast(current_time);
           }
           // if the line is free then
           if(line_free)
           {
               // if the queue is not empty then
               if(queue.size() !=0)
               {
                   // get arrival time of first customer
                   int arrival_time = queue.removeFirst();
                   // calculate wait time of the customer
                   int wait_time = current_time - arrival_time;
                   // Add wait time to the total wait time
                   total_wait_time += wait_time;
                   // set time until line free to 60
                   time_until_line_free = 60;
                   // set line free to false
                   line_free = false;
               }
           }
           else
           {
               // id line is not free then decrement timer
               time_until_line_free--;
               // when timer reaches 0 then
               if(time_until_line_free == 0)
               {
                   // set line free to true
                   line_free = true;
               }
           }
       }
       // print average wait time
       System.out.println("Average wait time is "+total_wait_time/num_of_cust);
       // print number of customers still in queue
       System.out.println("Number of customers still waiting in the queue : "+queue.size());
   }
}