-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRoundRobin_Scheduling.java
55 lines (54 loc) · 2.57 KB
/
RoundRobin_Scheduling.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
import java.util.Scanner;
public class RoundRobin_Scheduling {
public static void main(String args[]) {
int n, i, qt, count = 0, temp, sq = 0, burstTime[], waitingTime[], turnaroundTime[], remainingBurstTime[];
float averageWaitingTime = 0, averageTurnaroundTime = 0;
burstTime = new int[10];
waitingTime = new int[10];
turnaroundTime = new int[10];
remainingBurstTime = new int[10];
Scanner s = new Scanner(System.in);
System.out.print("Enter the number of process (maximum 10) = ");
n = s.nextInt();
System.out.print("Enter the burst time of the process\n");
for (i = 0; i < n; i++) {
System.out.print("P" + i + " = ");
burstTime[i] = s.nextInt();
remainingBurstTime[i] = burstTime[i];
}
System.out.print("Enter the quantum time: ");
qt = s.nextInt();
while (true) {
for (i = 0, count = 0; i < n; i++) {
temp = qt;
if (remainingBurstTime[i] == 0) {
count++;
continue;
}
if (remainingBurstTime[i] > qt)
remainingBurstTime[i] = remainingBurstTime[i] - qt;
else if (remainingBurstTime[i] >= 0) {
temp = remainingBurstTime[i];
remainingBurstTime[i] = 0;
}
sq = sq + temp;
turnaroundTime[i] = sq;
}
if (n == count)
break;
}
System.out.print("--------------------------------------------------------------------------------");
System.out.print("\nProcess\t Burst Time\t Turnaround Time\t Waiting Time\n");
System.out.print("--------------------------------------------------------------------------------");
for (i = 0; i < n; i++) {
waitingTime[i] = turnaroundTime[i] - burstTime[i];
averageWaitingTime = averageWaitingTime + waitingTime[i];
averageTurnaroundTime = averageTurnaroundTime + turnaroundTime[i];
System.out.print("\n " + (i + 1) + "\t\t " + burstTime[i] + "\t\t\t " + turnaroundTime[i] + "\t\t\t\t " + waitingTime[i] + "\n");
}
averageWaitingTime = averageWaitingTime / n;
averageTurnaroundTime = averageTurnaroundTime / n;
System.out.println("\nAverage waiting Time = " + averageWaitingTime + "\n");
System.out.println("Average turnaround time = " + averageTurnaroundTime);
}
}