@@ -12,36 +12,36 @@ public class RoundRobin {
1212 * This method calculates the waiting time for all processes
1313 *
1414 * @param burstTime an array with burst time for all processes
15- * @param quantum the quantum quantity
16- *
15+ * @param quantum the quantum quantity
1716 * @return an array with waiting time for all processes
1817 */
19- public int []calcWaitingTime (int []burstTime ,int quantum )
20- {
21- int n =burstTime .length ;
18+ public int []calcWaitingTime (int []burstTime ,int quantum ) {
19+ int n =burstTime .length ;
2220//create a copy of burstTime table to executeTime table
23- int []executeTIme =new int [n ];
24- for (int i =0 ;i <n ;i ++)
25- executeTIme [i ]=burstTime [i ];
21+ int []executeTIme =new int [n ];
22+ for (int i =0 ;i <n ;i ++) {
23+ executeTIme [i ] =burstTime [i ];
24+ }
2625
2726//initialize the waiting time table and set all waiting times equal to zero
28- int []waitingTime =new int [n ];
29- for (int i =0 ;i <n ;i ++)
30- waitingTime [i ]=0 ;
27+ int []waitingTime =new int [n ];
28+ for (int i =0 ;i <n ;i ++) {
29+ waitingTime [i ] =0 ;
30+ }
3131
3232//initialize an array list to emulate the queue of ready processes
3333ArrayList <Integer >readyQueue =new ArrayList <>();
34- for (int i = 0 ; i < n ; i ++)
34+ for (int i = 0 ; i < n ; i ++) {
3535readyQueue .add (i );
36+ }
3637
3738//the total time that processes need to be finished
38- int time = 0 ;
39- int i = 0 ;
39+ int time = 0 ;
40+ int i = 0 ;
4041//calculate waiting times while there are uncompleted processes
41- while (!readyQueue .isEmpty ())
42- {
42+ while (!readyQueue .isEmpty ()) {
4343//check if a process has finished
44- if (executeTIme [i ]>= 0 ) {
44+ if (executeTIme [i ] >= 0 ) {
4545if (executeTIme [i ] -quantum >0 ) {
4646//add time that have been passed
4747time +=quantum ;
@@ -57,7 +57,7 @@ public int[] calcWaitingTime(int[] burstTime, int quantum)
5757//mark the process as finished
5858executeTIme [i ] = -1 ;
5959//remove the process that have finished by shrinking queue's length
60- readyQueue .remove (readyQueue .size ()- 1 );
60+ readyQueue .remove (readyQueue .size () - 1 );
6161
6262 }else {
6363//add time that have been passed
@@ -68,11 +68,13 @@ public int[] calcWaitingTime(int[] burstTime, int quantum)
6868//mark the process as finished
6969executeTIme [i ] = -1 ;
7070//remove the process that have finished by shrinking queue's length
71- readyQueue .remove (readyQueue .size ()- 1 );
71+ readyQueue .remove (readyQueue .size () - 1 );
7272 }
7373 }
7474i ++;
75- if (i >=n )i =0 ;
75+ if (i >=n ) {
76+ i =0 ;
77+ }
7678 }
7779
7880return waitingTime ;
@@ -82,20 +84,19 @@ public int[] calcWaitingTime(int[] burstTime, int quantum)
8284/**
8385 * This method calculates turn around time for all processes
8486 *
85- * @param burstTime an array with burst time for all processes
87+ * @param burstTime an array with burst time for all processes
8688 * @param waitingTime an array with waiting time for all processes
87- *
8889 * @return an array with turnaround time for all processes
8990 */
90- public int []calcTurnAroundTime (int []burstTime ,int []waitingTime )
91- {
92- int n =burstTime .length ;
91+ public int []calcTurnAroundTime (int []burstTime ,int []waitingTime ) {
92+ int n =burstTime .length ;
9393//initialize the turnaround time table
94- int []turnAroundTime =new int [n ];
94+ int []turnAroundTime =new int [n ];
9595
9696//calculate turnaround time for each process (T.T= W.T + B.T)
97- for (int i =0 ;i <n ;i ++)
98- turnAroundTime [i ]=waitingTime [i ]+burstTime [i ];
97+ for (int i =0 ;i <n ;i ++) {
98+ turnAroundTime [i ] =waitingTime [i ] +burstTime [i ];
99+ }
99100
100101//return the turnaround time table
101102return turnAroundTime ;
@@ -106,10 +107,9 @@ public int[] calcTurnAroundTime(int[] burstTime, int[] waitingTime)
106107 * This method prints the results and calculates the average waiting and turnaround times
107108 *
108109 * @param burstTime an array with burst time for all processes
109- * @param quantum the quantum quantity
110+ * @param quantum the quantum quantity
110111 */
111- void printAvgTimes (int []burstTime ,int quantum )
112- {
112+ void printAvgTimes (int []burstTime ,int quantum ) {
113113int n =burstTime .length ;
114114int totalWaitingTime =0 ;
115115int totalTurnAroundTime =0 ;
@@ -128,14 +128,14 @@ void printAvgTimes(int[] burstTime, int quantum)
128128for (int i =0 ;i <n ;i ++) {
129129totalWaitingTime +=waitingTime [i ];
130130totalTurnAroundTime +=turnAroundTime [i ];
131- System .out .println (i +"\t \t " +burstTime [i ] +"\t \t \t " +
132- waitingTime [i ] +"\t \t \t " +turnAroundTime [i ]);
131+ System .out .println (i +"\t \t " +burstTime [i ] +"\t \t \t " +
132+ waitingTime [i ] +"\t \t \t " +turnAroundTime [i ]);
133133 }
134134
135135System .out .println ("\n Average waiting time = " +
136- (float )totalWaitingTime / (float )n );
136+ (float )totalWaitingTime / (float )n );
137137System .out .println ("Average turnaround time = " +
138- (float )totalTurnAroundTime / (float )n );
138+ (float )totalTurnAroundTime / (float )n );
139139 }
140140}
141141