I'm trying to code a CPU Scheduling Simulator in java. The processes are processed in an order such that the process with the least burst time (Processing Time) should be processed first. before beginning I enter all the processes in an ArrayList specifying a name , burst Time & arrival Time. The code works logically fine if all the processes enters at the same time.
The problem is that the processes have different arrival times. how can I edit the code to take this arrival time in consideration.
I just need to edit the part of code that gets me the Process with the least burst time (with respect to arrival time)
public Process removeSJ(){ // removes & returns the process with the min. burst time
int minBurstTime = processes.get(0).getBurstTime(); // processes is ArrayList of Processe objects
int minIndex = 0;
for (int i=1 ; i<processes.size(); i++){
int curBurstTime = processes.get(i).getBurstTime();
if ( (curBurstTime < minBurstTime)){
minBurstTime = curBurstTime;
minIndex = i;
}
}
numberOfProcesses--;
return (processes.remove(minIndex));}
sample output
The processor schedules process : P2
arrival time = 8 , burst time = 1 , waiting Time = 0
Turnaround time = 1
The processor schedules process : P3
arrival time = 5 , burst time = 3 , waiting Time = 1
Turnaround time = 4
The processor schedules process : P1
arrival time = 1 , burst time = 9 , waiting Time = 4
Turnaround time = 13
****** Average Turnaround Time = 6 ******