-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFCFS.java
More file actions
26 lines (21 loc) · 949 Bytes
/
Copy pathFCFS.java
File metadata and controls
26 lines (21 loc) · 949 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.util.*;
public class FCFS {
public void schedule(List<PCB> readyQueue) {
int currentTime = 0;
int totalWaitingTime = 0;
int totalTurnaroundTime = 0;
System.out.println("\n--- FCFS Scheduling ---");
for (PCB job : readyQueue) {
job.state = "Running";
job.startTime = currentTime;
job.finishTime = currentTime + job.burstTime;
currentTime = job.finishTime;
job.calculateTimes();
totalWaitingTime += job.waitingTime;
totalTurnaroundTime += job.turnaroundTime;
System.out.println("Job " + job.id + " | Start: " + job.startTime + "ms | End: " + job.finishTime + "ms");
}
System.out.println("Average Waiting Time: " + (totalWaitingTime / readyQueue.size()) + "ms");
System.out.println("Average Turnaround Time: " + (totalTurnaroundTime / readyQueue.size()) + "ms");
}
}