Round robin java code
Senin, 02 Desember 2013
0
komentar
ROUND ROBIN java code
import java.util.*;
class Process
{ String name;
int at,st;
int rt;
Process(String n,int a,int s)
{ name=n;
at=a;
st=s;
rt=st;
}
}
class RoundRobin
{ public static void main(String arg[])
{ Scanner sc=new Scanner(System.in);
System.out.println("enter the no. processes : ");
int n=sc.nextInt();
Process p[]=new Process[n];
System.out.println("enter Process details : ");
for(int i=0;i<n;i++)
{ System.out.println("process : "+(i+1)+" : \n enter name of process ");
String s=sc.next();
System.out.println("enter arival time : ");
int a=sc.nextInt();
System.out.println("enter service time : ");
int st=sc.nextInt();
p[i]=new Process(s,a,st);
}
System.out.println("name \t AT \t ST ");
for(int i=0;i<n;i++)
System.out.println(p[i].name+" \t "+p[i].at+" \t "+p[i].st);
Vector<Process> v=new Vector<Process>();
v.setSize(1000);
for(int i=0;i<n;i++)
v.insertElementAt(p[i],p[i].at);
int t=0,i=0;
while(i<=t)
{
try
{
if(v.elementAt(i).rt<=2)
{ System.out.println("process : "+v.elementAt(i).name+" from t= "+t+" to ");
t=t+v.elementAt(i).rt;
System.out.println("t= "+t);
v.remove(i);
}
else
{System.out.println("process : "+v.elementAt(i).name+" from t= "+t+" to ");
t=t+2;
v.elementAt(i).rt=v.elementAt(i).rt-2;
System.out.println("t= "+t);
v.insertElementAt(v.elementAt(i),t-1);
}
i++;
}
catch(Exception e)
{
i++;
}
}
}
}
OUTPUT
Enter the no. processes :6
enter Process details :
process : 1 :
enter name of process A
enter arival time : 0
enter service time : 5
process : 2 :
enter name of process B
enter arival time : 3
enter service time : 6
process : 3
enter name of process C
enter arival time : 5
enter service time : 2
process : 4
enter name of process D
enter arival time : 7
enter service time : 3
process : 5
enter name of process E
enter arival time : 7
enter service time : 5
process : 6
enter name of process F
enter arival time : 9
enter service time : 4
name AT ST
A 0 5
B 3 6
C 5 2
D 7 3
E 7 5
F 9 4
process : A from t= 0 to t= 2
process : A from t= 2 to t= 4
process : A from t= 4 to t= 5
process : B from t= 5 to t= 7
process : B from t= 7 to t= 9
process : C from t= 9 to t= 11
process : E from t= 11 to t= 13
process : D from t= 13 to t= 15
process : F from t= 15 to t= 17
process : E from t= 17 to t= 19
process : D from t= 19 to t= 20
process : F from t= 20 to t= 22
process : E from t= 22 to t= 23
Enjoy !
TERIMA KASIH ATAS KUNJUNGAN SAUDARA
Judul: Round robin java code
Ditulis oleh Unknown
Rating Blog 5 dari 5
Semoga artikel ini bermanfaat bagi saudara. Jika ingin mengutip, baik itu sebagian atau keseluruhan dari isi artikel ini harap menyertakan link dofollow ke https://android-reverb.blogspot.com/2013/12/round-robin-java-code.html. Terima kasih sudah singgah membaca artikel ini.Ditulis oleh Unknown
Rating Blog 5 dari 5
0 komentar:
Posting Komentar