Question: import java.util.*; public class CPU_Scheduling{ //public static void main(String atgs[]){ Scanner sc = new Scanner(System.in); //System.out.println(enter no of process: ); int n = sc.nextInt(); int

import java.util.*; public class CPU_Scheduling{ //public static void main(String atgs[]){ Scanner sc = new Scanner(System.in); //System.out.println("enter no of process: "); int n = sc.nextInt(); int pid[] = new int[n]; // process ids int at[] = new int[n]; // atrival times int bt[] = new int[n]; // burst or execution times int ct[] = new int[n]; // completion times int ta[] = new int[n]; // turn atound times int wt[] = new int[n]; // waiting times int f[] = new int[n]; int k[]= new int[n]; int temp; int st=0, tot=0; float avgwt=0,avgta=0; public void FCFS(){ Scanner sc = new Scanner(System.in); System.out.println("enter no of process: "); int n = sc.nextInt(); for(int i = 0; i < n; i++) { System.out.println("enter process " + (i+1) + " atrival time: "); at[i] = sc.nextInt(); System.out.println("enter process " + (i+1) + " brust time: "); bt[i] = sc.nextInt(); pid[i] = i+1; } for(int i = 0 ; i at[j+1] ) { temp = at[j]; at[j] = at[j+1]; at[j+1] = temp; temp = bt[j]; bt[j] = bt[j+1]; bt[j+1] = temp; temp = pid[j]; pid[j] = pid[j+1]; pid[j+1] = temp; } } } for(int i = 0 ; i < n; i++) { if( i == 0) { ct[i] = at[i] + bt[i]; } else { if( at[i] > ct[i-1]) { ct[i] = at[i] + bt[i]; } else ct[i] = ct[i-1] + bt[i]; } ta[i] = ct[i] - at[i] ; // turnatound time= completion time- atrival time wt[i] = ta[i] - bt[i] ; // waiting time= turnatound time- burst time avgwt += wt[i] ; // total waiting time avgta += ta[i] ; // total turnatound time } System.out.println(" pid atrival brust complete turn waiting"); for(int i = 0 ; i< n; i++) { System.out.println(pid[i] + " \t " + at[i] + "\t" + bt[i] + "\t" + ct[i] + "\t" + ta[i] + "\t" + wt[i] ) ; } sc.close(); System.out.println(" average waiting time: "+ (avgwt/n)); // printing average waiting time. System.out.println("average turnatound time:"+(avgta/n)); // printing average turnatound time. } public void SJF() { Scanner sc = new Scanner(System.in); System.out.println ("enter no of process:"); int n = sc.nextInt(); for(int i=0;i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!