Title :TO IMPLEMENT PROCESS PRIORITY IN JAVA
*/
import java.util.*;
public class Priority
{
public static void main(String args[])throws Exception{
Scanner s=new Scanner(System.in);
int n=0;
System.out.println("Enter no of processes :");
n=s.nextInt();
Process[] p=new Process[n];
for(int i=0;i<n;i++)
{
p[i]=new Process();
}
for(int i=0;i<n;i++)
{
System.out.println("PROCESS ID :");
p[i].id=s.nextInt();
System.out.println("ARRIVAL TIME :");
p[i].atime=s.nextInt();
System.out.println("Burst TIME :");
p[i].btime=s.nextInt();
System.out.println("Priority :");
p[i].prior=s.nextInt();
}
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-1;j++)
{
if(p[j].prior>p[j+1].prior)
{
Process t=p[j];
p[j]=p[j+1];
p[j+1]=t;
}
}
}
System.out.println("Process id\tArrival time\tBurst time\tPriority");
System.out.println("...............................");
for(int i=0;i<n;i++)
{
System.out.println(""+p[i].id+"\t\t"+p[i].atime+"\t\t"+p[i].btime+"\t\tp"+p[i].prior);
}
}
}
class Process {
int id,btime,atime,prior;
}
/*OUTPUT
Enter no of processes :
2
PROCESS ID :
12
ARRIVAL TIME :
14
Burst TIME :
45
Priority :
1
PROCESS ID :
21
ARRIVAL TIME :
23
Burst TIME :
45
Priority :
2
Process id Arrival time Burst time Priority
...............................
12 14 45 p1
21 23 45 p2
*/
No comments:
Post a Comment