-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImplementation_of_RR.java
57 lines (51 loc) · 1.82 KB
/
Implementation_of_RR.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
mport java.util.*;
public class Lab_1_RR {
public static void main(String args[]){
int n, i, time_slice, count = 0, temp, sq = 0, burst_time[], wait[], turn_around[], rem_bt[];
float avg_wait = 0;
burst_time = new int[10];
wait = new int[10];
turn_around = new int[10];
rem_bt = new int[10];
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of processes : ");
n = sc.nextInt();
System.out.print("Enter burst time of process\n");
for (i = 0; i < n; i++){
System.out.print("P" + i + " = ");
burst_time[i] = sc.nextInt();
rem_bt[i] = burst_time[i];
}
System.out.print("Enter Time Slice = ");
time_slice = sc.nextInt();
while(true){
for (i = 0, count = 0; i < n; i++){
temp = time_slice;
if(rem_bt[i] == 0){
count++;
continue;
}
if(rem_bt[i] > time_slice)
rem_bt[i] = rem_bt[i] - time_slice;
else
if(rem_bt[i] >= 0){
temp = rem_bt[i];
rem_bt[i] = 0;
}
sq = sq + temp;
turn_around[i] = sq;
}
if(n == count)
break;
}
System.out.print("\nProcess\tBurst Time\tWaiting Time\n");
for(i = 0; i < n; i++){
wait[i] = turn_around[i] - burst_time[i];
avg_wait = avg_wait + wait[i];
System.out.print("\n " + (i + 1) + "\t " + burst_time[i] + "\t\t " + wait[i]);
}
sc.close();
avg_wait = avg_wait / n;
System.out.println("\nAverage waiting Time = " + avg_wait);
}
}