Question: input for roundRobin scheduler: quantum = 1 A 0 3 B 2 6 C 4 4 D 6 5 E 8 2 expected output: A

input for roundRobin scheduler: quantum=1
A 03
B 26
C 44
D 65
E 82
expected output: A A B A B C B D C B E D C B E D C B D D
output generated: A A B A B C D B C D E B C D E B C D B D
void RRScheduler(ArrayList processNames, ArrayList arrivalTime,
ArrayList serviceTime, int quantum){
int n = processNames.size();
int[] remainingTime = new int[n]; // Remaining time for each process
int[] completionTime = new int[n]; // Completion time for each process
// int[] turnAroundTime = new int[n]; // Turnaround time for each process
// int[] waitingTime = new int[n]; // Waiting time for each process
// Initialize remaining time with the service times
for (int i =0; i < n; i++){
remainingTime[i]= serviceTime.get(i);
}
int currentTime =0; // Current time
int completedProcesses =0; // Count of completed processes
// Keep iterating until all processes are completed
while (completedProcesses < n){
boolean anyProcessExecuted = false; // Flag to track if any process executed in this time unit
for (int i =0; i < n; i++){
if (arrivalTime.get(i)<= currentTime && remainingTime[i]>0){// Process can be started
anyProcessExecuted = true; // Set the flag to true indicating at least one process executed
int executionTime = Math.min(quantum, remainingTime[i]); // Determine execution time for the process
remainingTime[i]-= executionTime; // Update remaining time
for (int j =0; j < executionTime; j++){// Print execution timeline
System.out.print(processNames.get(i)+"");
}
currentTime += executionTime; // Update current time
if (remainingTime[i]==0){// Process completed
completionTime[i]= currentTime; // Set completion time
completedProcesses++; // Increment completed processes count
}
}
}
// If no process executed in this time unit, move the current time forward
if (!anyProcessExecuted){
currentTime++;
}
}
what did I do wrong?

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 Programming Questions!