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

I am having trouble adapting the given Customer class to two other classes. I ne

ID: 673358 • Letter: I

Question

I am having trouble adapting the given Customer class to two other classes. 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.

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 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

import java.util.Random;       

10

11

public class PriorityCustomer {

12

     

13

    private int serviceTime;                // ServiceTime for this Customer

14

   private int priority;               // Priority for this Customer

15

     

16

    /// Constructor

17

    public PriorityCustomer() {                                    

18

        serviceTime = new Random().nextInt(5) + 1; // Randomly assign required service time 1-5

19

      priority = new Random().nextInt(5) + 1;   // Randomly assign priority 1-5

20

    }

21

    

22

   public int getPriority(){

23

      return priority;

24

   }

25

     

26

    /// Getter for ServiceTime

27

    public int getServiceTime() {                          

28

        return serviceTime;

29

    }

30

     

31

    /// Decrement ServiceTime by 1

32

    public void decServiceTime() {     

33

        serviceTime--;

34

    }

35

}

import java.util.Random;