-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroundRobin.java
59 lines (54 loc) · 1.98 KB
/
roundRobin.java
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import java.util.Scanner;
public class Round_Robin {
public static void main(String args[]) {
int n, i, qt, count = 0, temp, sq = 0, bt[], wt[], tat[], rem_bt[];
float awt = 0, atat = 0;
bt = new int[10];
wt = new int[10];
tat = new int[10];
rem_bt = new int[10];
try (Scanner sc = new Scanner(System.in)) {
System.out.print("Enter the number of processes = ");
n = sc.nextInt();
System.out.print("Enter the burst time of the process:\n");
for (i = 0; i < n; i++) {
System.out.print("P" + (i + 1) + " = ");
bt[i] = sc.nextInt();
rem_bt[i] = bt[i];
}
System.out.print("Enter the quantum time: ");
qt = sc.nextInt();
while (true) {
for (i = 0, count = 0; i < n; i++) {
temp = qt;
if (rem_bt[i] == 0) {
count++;
continue;
}
if (rem_bt[i] > qt)
rem_bt[i] = rem_bt[i] - qt;
else if (rem_bt[i] >= 0) {
temp = rem_bt[i];
rem_bt[i] = 0;
}
sq = sq + temp;
tat[i] = sq;
}
if (n == count)
break;
}
System.out.print("\nPID\tBT\tTAT\tWT\n");
for (i = 0; i < n; i++) {
wt[i] = tat[i] - bt[i];
awt = awt + wt[i];
atat = atat + tat[i];
System.out.print("\n " + (i + 1) + "\t " + bt[i] + "\t " + tat[i] + "\t " + wt[i] + "\n");
}
awt = awt / n;
atat = atat / n;
sc.close();
}
System.out.println("\nAverage Waiting Time (WT) = " + awt + "\n");
System.out.println("Average Turn Around Time (TAT) = " + atat);
}
}