You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class Process {
int pid; // process ID
int at; // arrival time
int bt; // burst time
int ct; // completion time
int wt; // waiting time
int tat; // turnaround time
}
public class FCFS {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Read in data
System.out.println("Give number of processes: ");
int n = scanner.nextInt();
Process[] arr = new Process[n];
for (int i = 0; i < n; ++i) {
arr[i] = new Process();
System.out.println("Give ID of process " + (i + 1) + ":");
arr[i].pid = scanner.nextInt();
System.out.println("Give arrival time of process " + (i + 1) + ":");
arr[i].at = scanner.nextInt();
System.out.println("Give burst time of process " + (i + 1) + ":");
arr[i].bt = scanner.nextInt();
}
int currentTime = 0; // Current time
for (int i = 0; i < n; i++) {
// Wait for the process to arrive
if (currentTime < arr[i].at) {
currentTime = arr[i].at; // Jump to the arrival time of the next process
}
arr[i].ct = currentTime + arr[i].bt; // Completion time
currentTime = arr[i].ct; // Move time forward
}
System.out.println("\nProcess ID | Arrival Time | Burst Time | Completion Time | Waiting Time | Turnaround Time");
for (int i = 0; i < n; i++) {
arr[i].tat = arr[i].ct - arr[i].at; // Turnaround time
arr[i].wt = arr[i].tat - arr[i].bt; // Waiting time
System.out.printf("%-11d | %-12d | %-10d | %-15d | %-12d | %-15d\n",
arr[i].pid, arr[i].at, arr[i].bt, arr[i].ct, arr[i].wt, arr[i].tat);
}
scanner.close();
}
}
#This title reflects the focus on enhancing the algorithm's accuracy and performance metrics.
The text was updated successfully, but these errors were encountered:
import java.util.Scanner;
class Process {
int pid; // process ID
int at; // arrival time
int bt; // burst time
int ct; // completion time
int wt; // waiting time
int tat; // turnaround time
}
public class FCFS {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
}
#This title reflects the focus on enhancing the algorithm's accuracy and performance metrics.
The text was updated successfully, but these errors were encountered: