Answered You can hire a professional tutor to get the answer.
I have included the previous code below. Please make the necessary modifications to the existing LinkedQueue class and Driver class as instructed in...
I have included the previous code below. Please make the necessary modifications to the existing LinkedQueue class and Driver class as instructed in the instructions.
I have also provided the the new class that will be used in testing the modified class and driver (you don't need to do anything to this).
Here is the LinkedQueue class:
public class LinkedQueue{
// declare variables
private Customer first, last;
int totalCustomersTillNow = 0;
int currentSize = 0;
public LinkedQueue() {
first = last = null;
}
public boolean isEmpty() {
return first == null;
}
public void enqueue(Customer c) {
// Adds Customer c to the back of the queue
if (isEmpty()) {
first = c;
} else {
last.setNext(c);
}
// last should always reference the new object
last = c;
currentSize++;
}
public Customer dequeue() {
// Removes and return the first Customer in the queue
if (isEmpty()) {
return null;
}
// Store a temp reference to the object we want to remove
Customer temp = first;
// Set first to reference the current first object's next reference
// (which is the current second object in the list)
first = first.getNext();
// if the queue is now empty, set last to null
if (isEmpty()) {
last = null;
}
currentSize--;
return temp;
}
public Customer atFront() {
if (isEmpty()) {
return null;
}
return first;
}
// Getter for total customers
public int getTotalCustomersTillNow() {
return totalCustomersTillNow;
}
// Getter for current queue size
public int getCurrentSize() {
return currentSize;
}
}
Here is the driver for the above class:
import java.util.Random;
/**Program: Driver ~ DriverClass
* Author:
* Date:
* Summary: store simulation takes place.
*/
public class Driver{
public static void main(String[] args) {
// Create a linked queue
LinkedQueue line = new LinkedQueue();
// Create a customer object
Customer myCustomer = null;
int maxCustomers = 0;
for (int i = 0; i < 60; i++) {
int num = new Random().nextInt(4) + 1;
// 25% chance of new customer
if (num == 1) {
// Add a new customer to the queue if newCustomer equals 1
line.enqueue(new Customer());
// Display a message to the user that a new customer has been
// added
System.out.println("New Customer added. Queue length is: "
+ line.getCurrentSize());
if (maxCustomers < line.getCurrentSize()) {
maxCustomers = line.getCurrentSize();
}
if(myCustomer == null) {
myCustomer = line.atFront();
System.out.println("Picking new customer: ");
}
}
if (myCustomer != null) {
// Decrease the service time if the customer isn't null
myCustomer.decServiceTime();
if (myCustomer.getServiceTime() == 0) {
// Dequeue the line if the service time is 0
line.dequeue();
// Display a message to the user that a customer was
// serviced and removed
System.out.println("Customer serviced and removed form the queue. Queue length is now: "
+ line.getCurrentSize());
myCustomer = null;
if(line.getCurrentSize() > 0) {
myCustomer = line.atFront();
System.out.println("Picking new customer: ");
}
}
}
System.out.println("-------------------------------------");
}
System.out.println("The total number of customers is: " + line.getTotalCustomersTillNow());
System.out.println("The total maximum number of customers in the queue is: " + maxCustomers);
}
}
Here is the new class that was provided and will be used in testing the modified class and driver (you don't need to do anything to this):
/*
Program: CustomerQueue ~ PriorityCustomer Class
Professor:
Date:
Summary: Creates a Customer object to be used in the line queue. Holds the serviceTime for each customer.
Functionality:
Constructor: Random ServiceTime (1-5)
Public Methods: getServiceTime, newMinute
*/
import java.util.Random;
public class PriorityCustomer {
private int serviceTime; // ServiceTime for this Customer
private int priority; // Priority for this Customer
/// Constructor
public PriorityCustomer() {
serviceTime = new Random().nextInt(5) + 1; // Randomly assign required service time 1-5
priority = new Random().nextInt(5) + 1; // Randomly assign priority 1-5
}
public int getPriority(){
return priority;
}
/// Getter for ServiceTime
public int getServiceTime() {
return serviceTime;
}
/// Decrement ServiceTime by 1
public void decServiceTime() {
serviceTime--;
}
}
Here are the instructions for modifying the LinkedQueue and DriverClass:
Instructions
For your second programming assignment, modify your first programming assignment to store your Customer objects in a priority queue instead of a regular queue.
An updated PriorityCustomer class is provided for you (download from Canvas). You must use that class, without alternations, for the creation of your PriorityCustomer 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 PriorityQueue class that will represent the data structure for holding your Customer objects. In your PriorityQueue class, you will create the actual heap that will act as the priority queue. You must use an array representation of a heap. No ArrayLists or linked structures! The second class you will need to create is a driver where your store simulation will take place.
Customers with a priority value higher than other existing customers should be placed in front of them. This is simulated by utilizing a Max Heap to implement your priority queue. The only exception to this is for the customer in the front of the line (the one currently being serviced). If a new customer is added to the line with a higher priority than the front customer, the new customer should not be put in front of the customer being serviced - only those that are also waiting in line. The store simulation with regards to the service time of customers, probability that new customers show up, and program output will be the same as it was for the first program.
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