Answered step by step
Verified Expert Solution
Question
1 Approved Answer
thats my java code which is a cpu priority with round robin , its a complete code but the gantt hart is missing something currently
thats my java code which is a cpu priority with round robin its a complete code but the gantt hart is missing something
currently it is like this P P P P P P
whats missing is the times under each process for example : PPP
PLEASE ADD THIS TO MY CODE AND CHECK IF IT WORKS
the java code : import java.util.;
class ProcessManagement
int processID;
int burstDuration;
int arrivalTime;
int priority;
int remainingTime;
int waitTime;
int completionTime;
int responseTime;
boolean isFinished;
boolean isFirstCycle;
public ProcessManagementint pID, int aTime, int bDuration, int pri
this.processID pID;
this.arrivalTime aTime;
this.burstDuration bDuration;
this.priority pri;
this.remainingTime bDuration;
this.waitTime ;
this.completionTime ;
this.responseTime ;
this.isFinished false;
this.isFirstCycle true;
public int getPriority
return this.priority;
public int getID
return this.processID;
public class PriorityRoundRobin
public static void mainString args
Scanner scanner new ScannerSystemin;
System.out.printlnEnter time quantum:";
int quantum scanner.nextInt;
List processList new ArrayList;
System.out.printlnEnter process ID arrival time, burst time, and priority terminate with :;
while true
int pID scanner.nextInt;
int aTime scanner.nextInt;
int bDuration scanner.nextInt;
int pri scanner.nextInt;
if pID && aTime && bDuration && pri
break;
processList.addnew ProcessManagementpID aTime, bDuration, pri;
scanner.close;
Collections.sortprocessList Comparator.comparingIntp parrivalTime;
int currentTime ;
int completedCount ;
int totalWaitTime ;
int totalTurnaroundTime ;
int totalResponseTime ;
StringBuilder gantt new StringBuilder;
while completedCount processList.size
ProcessManagement current getNextProcessprocessList currentTime;
if current null
if currentisFirstCycle
current.responseTime currentTime current.arrivalTime;
current.isFirstCycle false;
gantt.append PappendcurrentprocessIDappend;
int timeSlice Math.minquantum current.remainingTime;
currentTime timeSlice;
current.remainingTime timeSlice;
if currentremainingTime
current.isFinished true;
completedCount;
current.completionTime currentTime;
current.waitTime current.completionTime current.arrivalTime current.burstDuration;
totalWaitTime current.waitTime;
totalTurnaroundTime currentTime current.arrivalTime;
totalResponseTime current.responseTime;
else
currentTime;
gantt.append;
System.out.printlnScheduling done.";
System.out.printlnGantt Chart Priority RR: gantt.toStringtrim;
for ProcessManagement p : processList
System.out.printlnProcess ID: pprocessID Turnaround Time: pcompletionTime
Wait Time: pwaitTime Response Time: presponseTime;
System.out.printlnAverage Turnaround Time: double totalTurnaroundTime processList.size;
System.out.printlnAverage Wait Time: double totalWaitTime processList.size;
System.out.printlnAverage Response Time: double totalResponseTime processList.size;
private static ProcessManagement getNextProcessList processList, int currentTime
return processList.stream
filterp pisFinished && parrivalTime currentTime
minComparatorcomparingIntProcessManagement::getPriority
thenComparingIntProcessManagement::getID
orElsenull;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started