Question: Please fix if (time

Please fix "if (time

import java.util.LinkedList;

import java.util.Queue;

import java.util.Random;

public class MM1Queue {

private static final double LAMBDA = 10; // arrival rate

private static final double RHO = MU / LAMBDA; // traffic intensity

private static final int NUM_CUSTOMERS = 10000;

private static final double MU = 8; // service rate

public static void main(String[] args) {

Queue queue = new LinkedList<>();

Random random = new Random();

double totalWaitTime = 0;

double totalIdleTime = 0;

double time = 0;

int customersServed = 0;

// Trace the first 30 customers

System.out.println("Clock Time\tFuture Events\tDelayed List");

int traceCustomers = 0;

while (customersServed < NUM_CUSTOMERS) {

// Check if there's an arrival

if (time < NUM_CUSTOMERS / LAMBDA) {

queue.offer(time + (1 / LAMBDA) * random.nextDouble());

time = queue.peek();

}

// Check if the server is idle

if (!queue.isEmpty()) {

double arrivalTime = queue.poll();

totalWaitTime += time - arrivalTime;

time += (1 / MU) * random.nextDouble();

customersServed++;

} else {

totalIdleTime += (NUM_CUSTOMERS / LAMBDA - time);

time = NUM_CUSTOMERS / LAMBDA;

}

// Trace the first 30 customers

if (traceCustomers < 30) {

System.out.println(String.format("%.2f\t\t%.2f\t\t%d", time, time + (1 / MU), queue.size()));

traceCustomers++;

}

}

System.out.println(" Average queue length: " + (totalWaitTime / NUM_CUSTOMERS));

System.out.println("Average server idle time: " + (totalIdleTime / NUM_CUSTOMERS));

}

}

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!