Advertisement
bunny007

code 5(a)

Nov 20th, 2022
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.43 KB | None | 0 0
  1. import java.text. ParseException;
  2. class GFG {
  3.     static void findWaitingTime(int processes[], int n,
  4.             int bt[], int wt[]) {
  5.         wt[0] = 0;
  6.         for (int i = 1; i < n; i++) {
  7.             wt[i] = bt[i - 1] + wt[i - 1];
  8.         }
  9.     }
  10.     static void findTurnAroundTime(int processes[], int n,
  11.             int bt[], int wt[], int tat[]) {
  12.         // calculating turnaround time by adding
  13.         // bt[i] + wt[i]
  14.         for (int i = 0; i < n; i++) {
  15.             tat[i] = bt[i] + wt[i];
  16.         }
  17.     }
  18.     static void findavgTime(int processes[], int n, int bt[]) {
  19.         int wt[] = new int[n], tat[] = new int[n];
  20.         int total_wt = 0, total_tat = 0;
  21.         findWaitingTime(processes, n, bt, wt);
  22.         findTurnAroundTime(processes, n, bt, wt, tat);
  23.         System.out.printf("Processes Burst time Waiting"+" time Turn around time\n");
  24.         for (int i = 0; i < n; i++) {
  25.             total_wt = total_wt + wt[i];
  26.             total_tat = total_tat + tat[i];
  27.             System.out.printf(" %d ", (i + 1));
  28.             System.out.printf("  %d ", bt[i]);
  29.             System.out.printf("  %d", wt[i]);
  30.             System.out.printf("  %d\n", tat[i]);
  31.         }
  32.         float s = (float)total_wt /(float) n;
  33.         int t = total_tat / n;
  34.         System.out.printf("Average waiting time = %f", s);
  35.         System.out.printf("\n");
  36.         System.out.printf("Average turn around time = %d ", t);
  37.     }
  38.     public static void main(String[] args) throws ParseException {
  39.         //process id's
  40.         int processes[] = {1, 2, 3};
  41.         int n = processes.length;
  42.         int burst_time[] = {10, 5, 8};
  43.         findavgTime(processes, n, burst_time);
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement