Using the Java code provided ONLY, answer the following question: Modify your implementation 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

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
 
Time remaining:
00:09:24

Computer Science

Using the Java code provided ONLY, answer the following question:

Modify your implementation 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?

ONLY modify the following code provided:

import java.util.Random;

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             System.out.println(this.Q[i]);
            if(i == this.size) {
                i = 0;
            }
        }
    }

    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
}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY