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

Using Java to create Java class files! I am having trouble creating two other cl

ID: 673597 • Letter: U

Question

Using Java to create Java class files!

I am having trouble creating two other classes that can use/access the given below Customer class below (that CANNOT be modified). I need to create a Driver class to run the simulation and create a Queue linked list class (not using JAVAs predefined ways) to represent the data structure. Mainly the Driver class will access the Queue class and Customer class, but I am unsure of how to create the Queue class and the Driver class.

Write a program that simulates customers waiting in line at a grocery store. Your program must use a Queue to represent the customer objects waiting in line.
A Customer class is provided for you below. You must use that class, without alternations, for the creation of your Customer objects. You must analyze the class and use the provided methods to achieve the desired functionality of the program. You will also need to create two additional classes. The first will be a Linked List Queue that will represent the data structure for holding your Customer objects. The second is a driver where your store simulation will take place.
The program (driver) should simulate 60 minutes of activity at the store. Each iteration of your program should represent one minute. At each iteration (minute), your program should do the following:
•   Check to see if new customers are added to the queue. There is a 25% chance that new customers show up (need to be added to the queue) every minute. This does not mean you should add a customer every four iterations, but rather each iteration should have its own 25% chance.
•   Update the customer object currently being serviced (if one exists). This will be the customer object at the front of the queue. If the customer has been completely serviced, remove them from the queue.
During execution, your program should output the following information:
•   When a new customer is added to the queue, output, “New customer added! Queue length is now X” where X is the size of the queue after the new customer has been added.
•   When a customer has been completely serviced, output, “Customer serviced and removed from the queue. Quest length is now X” where X is the size of the queue after the customer has been removed.
•   At the end of each iteration (minute), output, “---------------------------------------------------“ to visually identify the passing of time.
When your simulation ends, your program should also output the following information:
   Total number of customers serviced
   Maximum line length during the simulation

THE CLASS BELOW CANNOT BE MODIFIED!

The Customer class is as follows:

import java.util.Random;      

public class Customer {
  
   private int serviceTime;                // ServiceTime for this Customer
private Customer next;
  
   /// Constructor
   public Customer() {                                      
       serviceTime = new Random().nextInt(5) + 1;   // Randomly assign required service time 1-5
next = null;
   }

// Getter for next Customer in list
public Customer getNext(){
return next;
}

// Setter for next reference
public void setNext(Customer c){
next = c;
}
  
   /// Getter for ServiceTime
   public int getServiceTime() {                          
       return serviceTime;
   }
  
   /// Decrement ServiceTime by 1
   public void decServiceTime() {      
       serviceTime--;
   }
}

Explanation / Answer

/program model 1/
package grocerystore;
import java.util.ArrayList;
import java.util.Random;
public class GroceryStore
{
private static ArrayList<Integer> line = new ArrayList();
private static Random r = new Random();
public static void addCustomer()
{
int timeToServe = r.nextInt(56) + 20;
line.add(timeToServe);
}
public static void removeCustomer()
{
line.remove(0);
}
public static int sum(ArrayList<Integer> a)
{
int sum = 0;
for (int i = 0; i < a.size(); i++)
{
sum += a.get(i);
}
return sum;
}
public static void main(String[] args)
{
int waitTime = 0;
int duration = 10000;
for (int i = 0; i < duration; i++)
{
double newCust = r.nextDouble();
if (newCust < .02)
{
addCustomer();
}
try
{
for (int j = 0; j < line.get(0); j++)
{
waitTime = waitTime + sum(line);
}
}
catch (IndexOutOfBoundsException e)
{
}
if (line.isEmpty())
{
}
else
{
removeCustomer();
}
}
System.out.println(waitTime/duration);
}
}


/program model 2/
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class LineWait
{
public static void main(String[ ] args)
{
final int LINETIME = 100 + (int)(Math.random() * ((400) + 1));
final double ARRIVALPROB = (Math.random() * ((.1) + 1));
final int TOTALTIME = 6000;
lineSimulate(LINETIME, ARRIVALPROB, TOTALTIME);
}
public static void lineSimulate(int lineTime, double arrivalProb, int totalTime)
{
Queue<Integer> arrivalTimes = new LinkedList<Integer>( );
Queue<Integer> arrivalTimes2 = new LinkedList<Integer>( );
Queue<Integer> arrivalTimes3 = new LinkedList<Integer>( );
Queue<Integer> arrivalTimes4 = new LinkedList<Integer>( );
Queue<Integer> arrivalTimes5 = new LinkedList<Integer>( );
int next;
BooleanSource arrival = new BooleanSource(arrivalProb);
Line number = new Line(lineTime);
Line number2 = new Line(lineTime);
Line number3 = new Line(lineTime);
Line number4 = new Line(lineTime);
Line number5 = new Line(lineTime);
Averager waitTimes = new Averager( );
Averager waitTimes2 = new Averager();
Averager waitTimes3 = new Averager();
Averager waitTimes4 = new Averager();
Averager waitTimes5 = new Averager();
int currentSecond;
System.out.println("Seconds to wait in line " + lineTime);
System.out.print("Probability of customer arrival during a second: ");
System.out.println(arrivalProb);
System.out.println("Total simulation seconds: " + totalTime);
if (lineTime <= 0 || arrivalProb < 0 || arrivalProb > 1 || totalTime < 0)
throw new IllegalArgumentException("Values out of range");
for (currentSecond = 0; currentSecond < totalTime; currentSecond++)
{
if (arrival.query( ))
{
//if(number.isBusy() && number2.isBusy() && number3.isBusy() && number4.isBusy() && number5.isBusy() )
//{
if(arrivalTimes.size() > arrivalTimes2.size() && arrivalTimes.size() > arrivalTimes3.size() && arrivalTimes.size() > arrivalTimes4.size() && arrivalTimes.size() > arrivalTimes5.size())
{
arrivalTimes.add(currentSecond);
System.out.println("Test");
}
else if(arrivalTimes2.size() > arrivalTimes.size() && arrivalTimes2.size() > arrivalTimes3.size() && arrivalTimes2.size() > arrivalTimes4.size() && arrivalTimes2.size() > arrivalTimes5.size())
{
arrivalTimes2.add(currentSecond);
System.out.println("Test");
}
else if(arrivalTimes3.size() > arrivalTimes.size() && arrivalTimes3.size() > arrivalTimes2.size() && arrivalTimes3.size() > arrivalTimes4.size() && arrivalTimes3.size() > arrivalTimes5.size())
{
arrivalTimes3.add(currentSecond);
System.out.println("Test");
}
else if(arrivalTimes4.size() > arrivalTimes.size() && arrivalTimes4.size() > arrivalTimes3.size() && arrivalTimes4.size() > arrivalTimes2.size() && arrivalTimes4.size() > arrivalTimes5.size())
{
arrivalTimes4.add(currentSecond);
System.out.println("Test");
}
else{arrivalTimes5.add(currentSecond);}
//
}
}
if ((!number.isBusy( )) && (!arrivalTimes.isEmpty( )))
{
next = arrivalTimes.remove( );
waitTimes.addNumber(currentSecond - next);
number.startMoving( );
}
if ((!number2.isBusy( )) && (!arrivalTimes2.isEmpty( )))
{
next = arrivalTimes2.remove( );
waitTimes2.addNumber(currentSecond - next);
number2.startMoving( );
}
if ((!number3.isBusy( )) && (!arrivalTimes**2**.isEmpty( )))
{
next = arrivalTimes2.remove( );
waitTimes3.addNumber(currentSecond - next);
number3.startMoving( );
}
if ((!number4.isBusy( )) && (!arrivalTimes**2**.isEmpty( )))
{
next = arrivalTimes2.remove( );
waitTimes4.addNumber(currentSecond - next);
number4.startMoving( );
}
if ((!number5.isBusy( )) && (!arrivalTimes**2**.isEmpty( )))
{
next = arrivalTimes2.remove( );
waitTimes5.addNumber(currentSecond - next);
number5.startMoving( );
}
number.reduceRemainingTime( );
number2.reduceRemainingTime( );
number3.reduceRemainingTime( ):
number4.reduceRemainingTime( );
number5.reduceRemainingTime( );
}   
System.out.println(" Customers served Line1: " + waitTimes.howManyNumbers( ));
if (waitTimes.howManyNumbers( ) > 0)
System.out.println("Average wait Line1: " + waitTimes.average( ) + " sec");
System.out.println(" Customers served Line2: " + waitTimes2.howManyNumbers( ));
if (waitTimes.howManyNumbers( ) > 0)
System.out.println("Average wait Line2: " + waitTimes2.average( ) + " sec");
System.out.println(" Customers served Line3: " + waitTimes3.howManyNumbers( ));
if (waitTimes.howManyNumbers( ) > 0)
System.out.println("Average wait Line3: " + waitTimes3.average( ) + " sec");
System.out.println(" Customers served Line4: " + waitTimes4.howManyNumbers( ));
if (waitTimes.howManyNumbers( ) > 0)
System.out.println("Average wait Line4: " + waitTimes4.average( ) + " sec");
System.out.println(" Customers served Line5: " + waitTimes5.howManyNumbers( ));
if (waitTimes.howManyNumbers( ) > 0)
System.out.println("Average wait Line5: " + waitTimes5.average( ) + " sec");
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote