Question: i have a java code that is about cpu priority with round robin , the code is complete and correct except for one part which
i have a java code that is about cpu priority with round robin the code is complete and correct except for one part which is the gantt chart output.
i will provide you the code and the sample input and the sample output so please update what is neccesary in my code
my input
Please enter Quantum time:
Please enter in this order: process ID arrival time, burst time, and priority to execute enter :
the gantt chart output i get : Gantt Chart: P P P P P P P P
the correct gantt chart is this : Gantt Chart: PPPPPPPPP
my java code :
begin of code
import java.util.;
define variables
class ProcessDetails
int pID; int bTime; int aTime; int pri; int remTime; int wTime; int tTime; int resTime;
boolean done; boolean start;
start the variables
public ProcessDetailsint pid, int aTime, int bTime, int priority
this.pID pid;
this.aTime aTime;
this.bTime bTime;
this.pri priority;
this.remTime bTime;
defaults values
this.wTime ;
this.tTime ;
this.resTime ;
this.done false;
this.start true;
get methods for the id and priority
public int getPri
return this.pri;
public int getpID
return this.pID;
public class PRR
public static void mainString args
start scanner for input
Scanner kbd new ScannerSystemin;
System.out.printPlease enter Quantum time:";
int q kbdnextInt; quantum value saved here
create new list for the process details arrival time
List processsos new ArrayList;
output and form
System.out.printlnPlease enter in this order: process ID arrival time, burst time, and priority to execute enter :;
while true
int ID kbdnextInt;
int arrivalTime kbdnextInt;
int burstTime kbdnextInt;
int priority kbdnextInt;
condition to executeterminate
if ID && arrivalTime && burstTime && priority
break;
add the inputs to the new list
processsos.addnew ProcessDetailsID arrivalTime, burstTime, priority;
kbdclose; Close the scanner to avoid resource leaks
organize the processes compared to thier arrival times
Collections.sortprocesssos Comparator.comparingIntp paTime;
new variablesdefaults
int cTime ; int processDone ; int totalwTime ; int totaltTime ; int totalresTime ;
StringBuilder GanttChart new StringBuilder;
int preTime ;
while processDone processsos.size
ProcessDetails cur pickNextProcessprocesssos cTime;
calculate response time
if cur null
if curstart
cur.resTime cTime cur.aTime;
cur.start false;
draw the gantt chart
GanttChart.appendpreTimeappend PappendcurpIDappend;
preTimecTime;
int timeSlice Math.minq cur.remTime;
cTime timeSlice;
cur.remTime timeSlice;
calculate turnaround,wait times add them to the prev value total
if curremTime
cur.done true;
processDone;
cur.tTime cTime cur.aTime;
cur.wTime cur.tTime cur.bTime;
totalwTime cur.wTime;
totaltTime cur.tTime;
totalresTime cur.resTime;
else
cTime; because there is no process active right now so so add to go next
preTimecTime;
helpful message for the user
System.out.println
Schedule Successfully done.";
print the gantt chart
System.out.printlnGantt Chart: GanttChart.toStringtrim;
print the process details
for ProcessDetails p : processsos
System.out.println
Process ID: ppID
The Turnaround Time: ptTime
The Waiting Time: pwTime
The Response Time: presTime
;
print the averages
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
