0% found this document useful (0 votes)
217 views3 pages

Round Robin

DOWLOAD HERE: http://adf.ly/aJSFm SCREENSHOT:http://adf.ly/aJSvj ====== CPU Scheduling: Round Robin Java Program copy in notepad. save as RoundRobin.java CSC110
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
0% found this document useful (0 votes)
217 views3 pages

Round Robin

DOWLOAD HERE: http://adf.ly/aJSFm SCREENSHOT:http://adf.ly/aJSvj ====== CPU Scheduling: Round Robin Java Program copy in notepad. save as RoundRobin.java CSC110
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
You are on page 1/ 3

CPU SCHEDULING: ROUND ROBIN

import java.io.*;
public class RoundRobin {
public static void main(String[] args) throws IOException {
BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));
System.out.println("\n\n\t\tProgram Name: Scheduler (RoundRobin)");
int n=0,twt=0,awt=0,i,j,k,tq,m,sum=0,max=0;
System.out.print("\n\n\nEnter number of process: ");
n = Integer.parseInt(inp.readLine());
System.out.print("Enter the time quantum: ");
tq = Integer.parseInt(inp.readLine());
int bu[] = new int[20];
int wt[] = new int[20];
int tat[] = new int[20];
int b[] = new int[20];
int count[] = new int[20];
int Rrobin[][] = new int[20][20];
System.out.print("Enter Burst Times: \n");
for(i=1;i<=n;i++) {
b[i]=bu[i];
System.out.print("Process #"+i+": ");
b[i] = Integer.parseInt(inp.readLine());
if(max<b[i]) {
max=b[i];
wt[i]=0;
}
}

//TO find the dimension of the Round robin array


m=max/tq+1;
//initializing Round robin array
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
Rrobin[i][j]=0;
}
}
//placing value in the Rrobin array
i=1;
while(i<=n)
{
j=1;
while(b[i]>0)
{
if(b[i]>=tq) {

b[i]=b[i]-tq;
Rrobin[i][j]=tq;
j++;
}
else {
Rrobin[i][j]=b[i];
b[i]=0;
j++;
}
}
count[i]=j-1;
i++;
}

for(j=1;j<=n;j++) {
for(i=1;i<=count[j];i++) {
if(i==count[j]) {
for(k=1;k<j;k++) {
if(k!=j) {
wt[j]+=Rrobin[k][i];
}
}
}
else {
for(k=1;k<=n;k++) {
if(k!=j) {
wt[j]+=Rrobin[k][i];
}
}
}
}
}
System.out.print("\n\n");
System.out.print("**********************************\n");
for(i=1;i<=n;i++) {
System.out.print("\nWaiting Time for Process#"+i+"="+wt[i]);
}
System.out.print("\n\n**********************************");
//calculating Average Weighting Time
for(i=1;i<=n;i++) {
twt=twt+wt[i];
tat[i]=b[i]+wt[i];
sum+=tat[i];
}
awt=twt/n;
sum=sum/n;
System.out.print("\n\nTotal Waiting Time: "+twt);
System.out.print("\nAverage Waiting Time: "+awt);

}
}

You might also like