Question: Refer to Chapters 7 & 8 our textbook, implement a Queue ADT using arrayed based, linked list, or the standard Java class Vector. The choice

Refer to Chapters 7 & 8 our textbook, implement a Queue ADT using arrayed based, linked list, or the standard Java class Vector. The choice is yours complete one implementation.

Review Project 2 You should be able to implement a generic queue that will satisfy this assignment as well as a portion of the project.

Test your implementation using a test driver, such as the Waiting Time simulation (Chapter 7). You can consider WaitLine as a utility class.

Complete a small write-up to highlight your learning experience.

Compress your working folder and write-up; submit compressed file back to the assignment link on Blackboard.

A few comments about this lab

  • I would only consider using the class Vector to implement my queue, if I have mastered the array-based or linked implements you are here to learn to build an ADT
  • You will need to implement a new custom emptyQueueException
  • The provided interface is fine, no need to modify it
  • you should throws the custom exception in your dequeue() method
  • The provided WaitLine class is a utility class

Given // WaitLine.java

public class WaitLine

{

private QueueInterface line;

private int numberOfArrivals;

private int numberServed;

private int totalTimeWaited;

public WaitLine()

{

line = new LinkedQueue<>();

reset();

} // end default constructor

/** Simulates a waiting line with one serving agent.

@param duration The number of simulated minutes.

@param arrivalProbability A real number between 0 and 1, and the

probability that a customer arrives at

a given time

@param maxTransactionTime The longest transaction time for a

customer */

public void simulate(int duration, double arrivalProbability,

int maxTransactionTime)

{

int transactionTimeLeft = 0;

for (int clock = 0; clock < duration; clock++)

{

if (Math.random() < arrivalProbability)

{

numberOfArrivals++;

int transactionTime = (int)(Math.random() * maxTransactionTime + 1);

Customer nextArrival = new Customer(clock, transactionTime,

numberOfArrivals);

line.enqueue(nextArrival);

System.out.println("Customer " + numberOfArrivals +

" enters line at time " + clock +

". Transaction time is " + transactionTime);

} // end if

if (transactionTimeLeft > 0)

transactionTimeLeft--;

else if (!line.isEmpty())

{

Customer nextCustomer = line.dequeue();

transactionTimeLeft = nextCustomer.getTransactionTime() - 1;

int timeWaited = clock - nextCustomer.getArrivalTime();

totalTimeWaited = totalTimeWaited + timeWaited;

numberServed++;

System.out.println("Customer " + nextCustomer.getCustomerNumber() +

" begins service at time " + clock +

". Time waited is " + timeWaited);

} // end if

} // end for

} // end simulate

/** Displays summary results of the simulation. */

public void displayResults()

{

System.out.println();

System.out.println("Number served = " + numberServed);

System.out.println("Total time waited = " + totalTimeWaited);

double averageTimeWaited = ((double)totalTimeWaited) / numberServed;

System.out.println("Average time waited = " + averageTimeWaited);

int leftInLine = numberOfArrivals - numberServed;

System.out.println("Number left in line = " + leftInLine);

} // end displayResults

/** Initializes the simulation. */

public final void reset()

{

line.clear();

numberOfArrivals = 0;

numberServed = 0;

totalTimeWaited = 0;

} // end reset

} // end WaitLine

Given // Queueinterface.java

public interface QueueInterface

{

/** Adds a new entry to the back of this queue.

@param newEntry An object to be added. */

public void enqueue(T newEntry);

/** Removes and returns the entry at the front of this queue.

@return The object at the front of the queue.

@throws EmptyQueueException if the queue is empty before the operation. */

public T dequeue();

/** Retrieves the entry at the front of this queue.

@return The object at the front of the queue.

@throws EmptyQueueException if the queue is empty. */

public T getFront();

/** Detects whether this queue is empty.

@return True if the queue is empty, or false otherwise. */

public boolean isEmpty();

/** Removes all entries from this queue. */

public void clear();

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!