431_Assignment3_OSL
431_Assignment3_OSL
3
UCE2023431
Code:
import java.util.*;
class PCB{
String n;
int arrivalTime, burstTime, completionTime, waitingTime,
turnaroundTime;
PCB(String n, int at, int bt) {
this.n = n;
arrivalTime = at;
burstTime = bt;
waitingTime = 0;
turnaroundTime = 0;
}
void calcTTWT(PCB process) {
process.turnaroundTime=process.completionTime-process.arrivalTim
e;
process.waitingTime=process.turnaroundTime-process.burstTime;
}
}
public class Main {
static Scanner sc = new Scanner(System.in);
static void sortArr(PCB[] jobQueue) {
Arrays.sort(jobQueue, (p1, p2) ->
Integer.compare(p1.arrivalTime, p2.arrivalTime));
}
static void FCFS(PCB[] jobQueue) {
sortArr(jobQueue);
for (int i = 0; i < jobQueue.length; i++) {
if (i == 0) {
jobQueue[i].completionTime =
jobQueue[i].arrivalTime+ jobQueue[i].burstTime;
} else {
//ct of prev + bt of curr
jobQueue[i].completionTime =
jobQueue[i].burstTime + jobQueue[i-1].completionTime;
}
jobQueue[i].calcTTWT(jobQueue[i]);
}
}