Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

THe answer for the following missing the code for SRTF and 2 screenshots of the

ID: 3815826 • Letter: T

Question

THe answer for the following missing the code for SRTF and 2 screenshots of the runs of the program

Write a program that simulates the FCFS (first-come, first-served), SJF (shortest-job-first), SRTF (shortest-remaining-time-first), RR (round-robin) and Priority CPU scheduling algorithms. Create a separate Class for the jobs. Each job has a ID, Arrival time, Burst Time, and Priority. Randomly generate the job details for 10 jobs (the ID’s should be generated in a sequence i.e., ID#1, ID#2, …, ID#10). Arrival time should be between 0 and 10, Burst time between 1 and 20 seconds, and priority between 1 and 10 (lower value has higher priority i.e., 1 has more priority than 5). For jobs with the same priority, give preference to arrival time. For the RR scheduling, assume the time quantum or time slice to be 3 seconds. Execute the same set of jobs for each of the algorithms. Report the average waiting time and average turnaround time for each scheduling algorithm. The program can be implemented either in C++ or Java. Submit a pdf including screenshots of the program in execution. Include 2 runs of the program. Expert Answer ROUND ROBIN #include int main() { int count,j,n,time,remain,flag=0,time_quantum; int wait_time=0,turnaround_time=0,at[10],bt[10],rt[10]; printf("Enter Total Process: "); scanf("%d",&n); remain=n; for(count=0;countbt[i];" wt[0]="0;" first="" is="" 0="" calculating="" void="" bt[20],p[20],wt[20],tat[20],i,j,n,total="0,pos,temp;" float="" avg_wt,avg_tat;="" process:");="" scanf("%d",&n);="" printf(" enter="" time: ");="" bt[20],p[20],wt[20],tat[20],pr[20],i,j,n,total="0,pos,temp,avg_wt,avg_tat;" process:";="" priority ";="" cout<<"priority:";="" cin>>pr[i];="" p[i]="i+1;" contains="" sorting="" time,="" priority="" in="" ascending="" order="" selection="" sort="">;count++)>

Explanation / Answer

/**
*
*/
package com.chegg.test;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
* @author NAP0911
*
*/
public class FCFS {
   public static void main(String args[]) throws Exception {

       int n, averageTime[], burstTime[], waitingTime[], TaverageTime[];
       float averageWaitingTime = 0;
       InputStreamReader isr = new InputStreamReader(System.in);
       BufferedReader br = new BufferedReader(isr);
       System.out.println("Enter no of process");
       n = Integer.parseInt(br.readLine());
       burstTime = new int[n];
       waitingTime = new int[n];
       TaverageTime = new int[n];
       averageTime = new int[n];
       System.out
               .println("Enter Burst time for each process ");
       for (int i = 0; i < n; i++) {
           System.out.println("Enter burstTime for process " + (i + 1));
           burstTime[i] = Integer.parseInt(br.readLine());
       }
       for (int i = 0; i < n; i++) {
           System.out.println("Enter averageTime for process" + i);
           averageTime[i] = Integer.parseInt(br.readLine());
       }
       waitingTime[0] = 0;
       for (int i = 1; i < n; i++) {
           waitingTime[i] = waitingTime[i - 1] + burstTime[i - 1];
           waitingTime[i] = waitingTime[i] - averageTime[i];
       }
       for (int i = 0; i < n; i++) {
           TaverageTime[i] = waitingTime[i] + burstTime[i];
           averageWaitingTime = averageWaitingTime + waitingTime[i];
       }
       System.out.println(" PROCESS burstTime waitingTime TaverageTime ");
       for (int i = 0; i < n; i++) {
           System.out.println(" " + i + " " + burstTime[i] + " " + waitingTime[i] + " "
                   + TaverageTime[i]);
       }
       averageWaitingTime = averageWaitingTime / n;
      
       System.out.println("Average waiting time=" + averageWaitingTime
               + " ***********************************************");

   }
}

/**
*
*/
package com.chegg.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
* @author NAP0911
*
*/public class SRTF {

   public static void main(String args[]) throws IOException {
   InputStreamReader isr = new InputStreamReader(System.in);
   BufferedReader in = new BufferedReader(isr);

   int n;
   System.out.print("Enter no.of Jobs: ");
   n = Integer.parseInt(in.readLine());

   int process[] = new int[n];
   int averageTime[] = new int[n];
   int burstTime[] = new int[n];
   int bt2[] = new int[n];
   int waitingTime[] = new int[n];
   int tat[] = new int[n];
   for (int i = 0; i < n; i++) {
   System.out.print("Enter Job no.: ");
   process[i] = Integer.parseInt(in.readLine());
   System.out.print("Enter Job " +process[i] +" arrival time: ");
   averageTime[i] = Integer.parseInt(in.readLine());
   System.out.print("Enter Job " +process[i] +" burst time: ");
   burstTime[i] = Integer.parseInt(in.readLine());
   bt2[i] = burstTime[i];
   }

   int tbt = 0;
   for (int i = 0; i < n; i++) {
   tbt = tbt + burstTime[i];
   }

   int time[] = new int[tbt];
   int k = 0;
   int q2 = 0;

   System.out.println("Gantt Chart");
   System.out.print("|");
   //bt[0] = bt[0] - 1;

   for (int i = 0; i < tbt; i++) {
   int q = minTime(burstTime, averageTime, tbt, i, n);
   if (q != q2) {
   System.out.print(" p[" + process[q] + "] |");
   time[k++] = i;
   waitingTime[q] = i;
   tat[q] = i + burstTime[q];
   }
   burstTime[q] = burstTime[q] - 1;
   q2 = q;
   }
   time[k] = tbt;
   System.out.println();
   System.out.print("0 ");
   for (int i = 0; i <= k; i++) {
   System.out.print(time[i] + " ");
   }
  
   }
  
  
   public static int minTime(int b[], int a[], int tbt, int r, int n) {
   int j = 0;
   int min = tbt;

   for (int i = n - 1; i >= 0; i--) {
   if (b[i] < min && b[i] > 0 && r >= a[i]) {
   min = b[i];
   j = i;
   }
   }
   return j;
   }
  
}