Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbe160de

Browse files
format code
1 parent72efcaa commitbe160de

File tree

2 files changed

+43
-43
lines changed

2 files changed

+43
-43
lines changed

‎src/main/java/com/others/RoundRobin.java‎

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
publicint[]calcWaitingTime(int[]burstTime,intquantum)
20-
{
21-
intn=burstTime.length;
18+
publicint[]calcWaitingTime(int[]burstTime,intquantum) {
19+
intn =burstTime.length;
2220
//create a copy of burstTime table to executeTime table
23-
int[]executeTIme=newint [n];
24-
for (inti=0;i<n;i++)
25-
executeTIme[i]=burstTime[i];
21+
int[]executeTIme =newint[n];
22+
for (inti =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=newint [n];
29-
for (inti=0;i<n;i++)
30-
waitingTime[i]=0;
27+
int[]waitingTime =newint[n];
28+
for (inti =0;i <n;i++) {
29+
waitingTime[i] =0;
30+
}
3131

3232
//initialize an array list to emulate the queue of ready processes
3333
ArrayList<Integer>readyQueue =newArrayList<>();
34-
for(inti=0;i<n;i++)
34+
for(inti =0;i <n;i++) {
3535
readyQueue.add(i);
36+
}
3637

3738
//the total time that processes need to be finished
38-
inttime=0;
39-
inti=0;
39+
inttime =0;
40+
inti =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) {
4545
if (executeTIme[i] -quantum >0) {
4646
//add time that have been passed
4747
time +=quantum;
@@ -57,7 +57,7 @@ public int[] calcWaitingTime(int[] burstTime, int quantum)
5757
//mark the process as finished
5858
executeTIme[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
6969
executeTIme[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
}
7474
i++;
75-
if(i>=n)i=0;
75+
if (i >=n) {
76+
i =0;
77+
}
7678
}
7779

7880
returnwaitingTime;
@@ -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 burstTimean 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-
publicint[]calcTurnAroundTime(int[]burstTime,int[]waitingTime)
91-
{
92-
intn=burstTime.length;
91+
publicint[]calcTurnAroundTime(int[]burstTime,int[]waitingTime) {
92+
intn =burstTime.length;
9393
//initialize the turnaround time table
94-
int[]turnAroundTime=newint[n];
94+
int[]turnAroundTime=newint[n];
9595

9696
//calculate turnaround time for each process (T.T= W.T + B.T)
97-
for (inti=0;i<n;i++)
98-
turnAroundTime[i]=waitingTime[i]+burstTime[i];
97+
for (inti =0;i <n;i++) {
98+
turnAroundTime[i] =waitingTime[i] +burstTime[i];
99+
}
99100

100101
//return the turnaround time table
101102
returnturnAroundTime;
@@ -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 quantumthe quantum quantity
110111
*/
111-
voidprintAvgTimes(int[]burstTime,intquantum)
112-
{
112+
voidprintAvgTimes(int[]burstTime,intquantum) {
113113
intn =burstTime.length;
114114
inttotalWaitingTime =0;
115115
inttotalTurnAroundTime =0;
@@ -128,14 +128,14 @@ void printAvgTimes(int[] burstTime, int quantum)
128128
for (inti =0;i <n;i++) {
129129
totalWaitingTime +=waitingTime[i];
130130
totalTurnAroundTime +=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

135135
System.out.println("\nAverage waiting time = " +
136-
(float)totalWaitingTime / (float)n);
136+
(float)totalWaitingTime / (float)n);
137137
System.out.println("Average turnaround time = " +
138-
(float)totalTurnAroundTime / (float)n);
138+
(float)totalTurnAroundTime / (float)n);
139139
}
140140
}
141141

‎src/test/java/com/others/RoundRobinTest.java‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ public class RoundRobinTest {
1010
privatefinalRoundRobinroundRobin =newRoundRobin();
1111

1212
@Test
13-
publicvoidtestWaitingTime(){
14-
int[]expectedTime = {9,12,14,9};
15-
int[]realtime=roundRobin.calcWaitingTime(burstTime,3);
13+
publicvoidtestWaitingTime(){
14+
int[]expectedTime = {9,12,14,9};
15+
int[]realtime=roundRobin.calcWaitingTime(burstTime,3);
1616
Assert.assertArrayEquals(realtime,expectedTime);
1717
}
1818

1919
@Test
20-
publicvoidtestTurnAroundTIme(){
21-
int[]expectedTIme={14,27,18,12};
22-
int[]waitingTime = {9,12,14,9};
23-
int[]realTime=roundRobin.calcTurnAroundTime(burstTime,waitingTime);
24-
Assert.assertArrayEquals(realTime,expectedTIme);
20+
publicvoidtestTurnAroundTIme(){
21+
int[]expectedTIme ={14,27,18,12};
22+
int[]waitingTime = {9,12,14,9};
23+
int[]realTime=roundRobin.calcTurnAroundTime(burstTime,waitingTime);
24+
Assert.assertArrayEquals(realTime,expectedTIme);
2525
}
2626
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp