-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoundRobin.java
More file actions
64 lines (64 loc) · 1.52 KB
/
RoundRobin.java
File metadata and controls
64 lines (64 loc) · 1.52 KB
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
60
61
62
63
64
import java.util.Scanner;
class RoundRobin
{
public static void main(String args[])
{
int n, i, qt, count = 0, temp, sq = 0, bt[], wt[], tat[], rembt[];
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of process : ");
n = sc.nextInt();
float awt = 0, atat = 0;
bt = new int[n];
wt = new int[n];
tat = new int[n];
rembt = new int[n];
System.out.print("Enter burst time of the process : ");
for(i = 0; i < n; i++)
{
bt[i] = sc.nextInt();
rembt[i] = bt[i];
}
System.out.print("Enter quantum time : ");
qt = sc.nextInt();
while(true)
{
for(i = 0, count = 0; i < n; i++)
{
temp = qt;
if(rembt[i] == 0)
{
count++;
continue;
}
if(rembt[i] > qt)
rembt[i] -= qt;
else
{
if(rembt[i] >= 0);
{
temp = rembt[i];
rembt[i] = 0;
}
}
sq += temp;
tat[i] = sq;
}
if(n == count)
break;
}
System.out.println("------------------------------------------------------------------------------------");
System.out.println("\nProcess\tBurst Time\tTurn Around Time\tWaiting Time");
System.out.println("------------------------------------------------------------------------------------");
for(i = 0; i < n; i++)
{
wt[i] = tat[i] - bt[i];
awt += wt[i];
atat += tat[i];
System.out.println((i + 1) +"\t" + bt[i] + "\t\t" + tat[i] + "\t\t" + wt[i]);
}
awt /= n;
atat /= n;
System.out.println("Average waiting time = " + awt);
System.out.println("Average Turnaroud time = " + atat);
}
}