Question: can you generate the output like this for RR ? RR - 4 0 1 2 3 4 5 6 7 8 9 0 1

can you generate the output like this for RR?
RR-4012345678901234567890
A |*|*|*||||||||||||||||||
B |||.|*|*|*|*|.|.|.|.|.|.|.|.|*|*||||
C |||||.|.|.|*|*|*|*||||||||||
D |||||||.|.|.|.|.|*|*|*|*|.|.|.|.|*|
E |||||||||.|.|.|.|.|.|.|.|.|*|*||
import java.io.*;
import java.util.*;
public class SchedulerDriver {
void roundRobinScheduler(ArrayList processNames, ArrayList startTime, ArrayList duration,
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
ArrayList completedProcesses = new ArrayList<>(); // Track completed processes
// Initialize remaining time with the durations
for (int i =0; i < n; i++){
remainingTime[i]= duration.get(i);
}
int currentTime =0; // Current time
int index =0; // Index of the current process
// Keep iterating until all processes are completed
while (!completedProcesses.containsAll(processNames)){
if (remainingTime[index]>0){
// Process is not yet completed
if (remainingTime[index]> quantum){
// Process executes for the quantum
currentTime += quantum;
remainingTime[index]-= quantum;
} else {
// Process executes for the remaining time
currentTime += remainingTime[index];
remainingTime[index]=0;
completionTime[index]= currentTime;
completedProcesses.add(processNames.get(index));
}
}
// Move to the next process
index =(index +1)% n;
}
// Calculate turnaround time and waiting time for each process
for (int i =0; i < n; i++){
turnAroundTime[i]= completionTime[i]- startTime.get(i);
waitingTime[i]= turnAroundTime[i]- duration.get(i);
}
// Display results or perform further processing
System.out.println("Round Robin Scheduler Output");
for (int i =0; i < n; i++){
System.out.println("Process: "+ processNames.get(i)+
" Turnaround Time: "+ turnAroundTime[i]+
" Waiting Time: "+ waitingTime[i]);
}
}
void RRScheduler(ArrayList processNames, ArrayList startTime, ArrayList duration, int timeQuantum){
Queue queue = new LinkedList<>(); // Queue to store process indexes
ArrayList remainingTime = new ArrayList<>(duration); // Copy of duration
int currentTime =0; // Current time
int n = processNames.size(); // Number of processes
// Initialize remaining time and add all processes to the queue
for (int i =0; i < n; i++){
queue.offer(i);
}
// Round Robin scheduling algorithm
while (!queue.isEmpty()){
int processIndex = queue.poll(); // Get the process at the front of the queue
int executeTime = Math.min(timeQuantum, remainingTime.get(processIndex)); // Execute for time quantum or remaining time
// Update current time and remaining time
currentTime += executeTime;
remainingTime.set(processIndex, remainingTime.get(processIndex)- executeTime);
// Print the execution of the process
System.out.println(processNames.get(processIndex)+""+ currentTime);
// Re-add the process to the queue if it's not completed
if (remainingTime.get(processIndex)>0){
queue.offer(processIndex);
}
}
}
public static void main(String[] args) throws FileNotFoundException {
SchedulerDriver sd = new SchedulerDriver();
Scanner scan = new Scanner(new File("jobs.txt"));
ArrayList processNames = new ArrayList<>();
ArrayList startTime = new ArrayList<>();
ArrayList duration = new ArrayList<>();
while (scan.hasNextLine()){
String line = scan.nextLine();
String[] tokens = line.split("\t");
processNames.add(tokens[0]);
startTime.add(Integer.parseInt(tokens[1]));
duration.add(Integer.parseInt(tokens[2]));
}
System.out.println("RR Scheduler Output");
sd.RRScheduler(processNames, startTime, duration, 2);

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!