Question: Part D: Modify your implementation for part B so that each teller has a separate queue. When customers arrive, they enter the shortest queue (and

Part D:

Modify your implementation for part B so that each teller has a separate queue. When customers arrive, they enter the shortest queue (and stay in that one, never switching queues). Run both versions of the algorithm for an identical set of 100 customers with the same arrival and transaction times. Compare the average wait time for the two methods. Which seems to be better?

Queue.java/////

public class Queue { public int head; public int tail; public int size; public int[] Q; public Queue(int size) { this.head = 1; this.tail = 1; this.Q = new int[size]; } public boolean isEmpty() { if(this.tail == this.head) return true; return false; } public boolean isFull() { if(this.head == this.tail+1) return true; return false; } public void enqueue(int x) { if(isFull()) { System.out.println("Queue Overflow"); } else { this.Q[this.tail] = x; if(this.tail == this.size) this.tail = 1; else this.tail = this.tail+1; } } public int dequeue() { if(isEmpty()) { System.out.println("Underflow"); return -1000; } else { int x = this.Q[this.head]; if(this.head == this.size) { this.head = 1; } else { this.head = this.head+1; } return x; } } public void display() { int i; for(i=this.head; i

Bank.java

import java.util.Random; public class Bank { public static void main(String[] args) { Queue q = new Queue(101); //100 cumtomers int sum =0; //total time taken by all 100 cutomers Random rand = new Random(); for(int i=1;i<=100;i++){ int tellers = rand.nextInt(3-1) +1; //this is used for selecting random available teller (1-3) switch(tellers){ case 1: q.enqueue(i); //customer enter in a queue int entryTime1 = rand.nextInt(5-1) + 1; //random integer between 1 to 5 int processTime1 = rand.nextInt(5-1) + 1; //random integer between 1 to 5 q.dequeue(); //customer leaves the queue sum = sum + (entryTime1 + processTime1); break; case 2: q.enqueue(i); //customer enter in a queue int entryTime2 = rand.nextInt(5-1) + 1; //random integer between 1 to 5 int processTime2 = rand.nextInt(5-1) + 1; //random integer between 1 to 5 q.dequeue(); //customer leaves the queue sum = sum + (entryTime2 + processTime2); break; case 3: q.enqueue(i); //customer enter in a queue int entryTime3 = rand.nextInt(5-1) + 1; //random integer between 1 to 5 int processTime3 = rand.nextInt(5-1) + 1; //random integer between 1 to 5 q.dequeue(); //customer leaves the queue sum = sum + (entryTime3 + processTime3); } } System.out.println(sum/100); //avarage waiting time } } 

Queue.java is the Queue implementation. Bank.java is what we did in part B this is Part B

Use your queue implementation to simulate a bank with 3 tellers and one line. The time between arrival of customers is a random integer between 1 and 5. When a customer arrives, the customer gets in line. When any of the three tellers is available, the first customer in line goes to that teller. The time to process that customers transaction is another random integer between 1 and 5. When the transaction is completed, the customer leaves. Run the simulation for 100 customers. Report the average time the customer waits in the queue

Part B is already done you just have to do the initial question that was asked so this Part D

Modify your implementation for part B so that each teller has a separate queue. When customers arrive, they enter the shortest queue (and stay in that one, never switching queues). Run both versions of the algorithm for an identical set of 100 customers with the same arrival and transaction times. Compare the average wait time for the two methods. Which seems to be better?

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!