Question: Use the Average Waiting Time program to determine a reasonable number of queues to use if there are 1000 customers and: a) The inner-arrival time

Use the Average Waiting Time program to determine a reasonable number of queues to use if there are 1000 customers and:

a) The inner-arrival time is 5 and the service time is 5

b) The inner-arrival time is 1 and the service time is 5

c) The inner-arrival time ranges from 0 to 20, and the service time ranges from 20 to 100

d) The inner-arrival time ranges from 0 to 2, and the service time ranges from 20 to 100

In each case, descripe how you arrived at your result

//--------------------------------------------------------------------------- // ArrayUnbndQueue.java by Dale/Joyce/Weems Chapter 5 // // Implements UnboundedQueueInterface with an array to hold queue elements. // // Two constructors are provided; one that creates a queue of a default // original capacity and one that allows the calling program to specify the // original capacity. // // If an enqueue is attempted when there is no room available in the array, a // new array is created, with capacity incremented by the original capacity. //---------------------------------------------------------------------------

package ch05.queues;

public class ArrayUnbndQueue implements UnboundedQueueInterface { protected final int DEFCAP = 100; // default capacity protected T[] queue; // array that holds queue elements protected int origCap; // original capacity protected int numElements = 0; // number of elements in the queue protected int front = 0; // index of front of queue protected int rear; // index of rear of queue

public ArrayUnbndQueue() { queue = (T[]) new Object[DEFCAP]; rear = DEFCAP - 1; origCap = DEFCAP; }

public ArrayUnbndQueue(int origCap) { queue = (T[]) new Object[origCap]; rear = origCap - 1; this.origCap = origCap; }

private void enlarge() // Increments the capacity of the queue by an amount // equal to the original capacity. { // create the larger array T[] larger = (T[]) new Object[queue.length + origCap]; // copy the contents from the smaller array into the larger array int currSmaller = front; for (int currLarger = 0; currLarger < numElements; currLarger++) { larger[currLarger] = queue[currSmaller]; currSmaller = (currSmaller + 1) % queue.length; } // update instance variables queue = larger; front = 0; rear = numElements - 1; }

public void enqueue(T element) // Adds element to the rear of this queue. { if (numElements == queue.length) enlarge();

rear = (rear + 1) % queue.length; queue[rear] = element; numElements = numElements + 1; }

public T dequeue() // Throws QueueUnderflowException if this queue is empty; // otherwise, removes front element from this queue and returns it. { if (isEmpty()) throw new QueueUnderflowException("Dequeue attempted on empty queue."); else { T toReturn = queue[front]; queue[front] = null; front = (front + 1) % queue.length; numElements = numElements - 1; return toReturn; } }

public boolean isEmpty() // Returns true if this queue is empty; otherwise, returns false { return (numElements == 0); } }

//---------------------------------------------------------------------------- // UnboundedQueueInterface.java by Dale/Joyce/Weems Chapter 5 // // Interface for a class that implements a queue of T with no bound // on the size of the queue. A queue is a "first in, first out" structure. //----------------------------------------------------------------------------

package ch05.queues;

public interface UnboundedQueueInterface extends QueueInterface

{ void enqueue(T element); // Adds element to the rear of this queue. }

//---------------------------------------------------------------------------- // QueueInterface.java by Dale/Joyce/Weems Chapter 5 // // Interface for a class that implements a queue of T. // A queue is a "first in, first out" structure. //----------------------------------------------------------------------------

package ch05.queues;

public interface QueueInterface

{ T dequeue() throws QueueUnderflowException; // Throws QueueUnderflowException if this queue is empty; // otherwise, removes front element from this queue and returns it.

boolean isEmpty(); // Returns true if this queue is empty; otherwise, returns false. }

AWT model

public class GlassQueue extends ArrayUnbndQueue

public class ArrayUnbndQueue implements UnboundedQueueInterface

public interface UnboundedQueueInterface extends QueueInterface

{

void enqueue(T element);

//Adds element to the rear of this quee.

}

public interface QueueInterface

{

T dequeue() throws QueueUnderflowException;

//Throws QueueUnderflowException if this queue is empty;

//otherwise, removes front element from this queue and returns it

boolean isEmpty();

//Returns true if this queue is empty; otherwise, return false

}

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!