import java.io.*;
class process
{
String name;
int burst;
int priority;
process(String x, int y, int z)
{
name=x;
burst=y;
priority=z;
}
}
class use
{
public static void main(String args[])throws Exception
{
BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter no. of processes: ");
int n=Integer.parseInt(br.readLine());
process a[]=new process[n];
for(int i=0;i<n;i++)
{
System.out.println("Enter name: ");
String name=br.readLine();
System.out.println("Enter burst time: ");
int time=Integer.parseInt(br.readLine());
System.out.println("Enter priority (greater is higher)");
int
pr=Integer.parseInt(br.readLine());
a[i]=new process(name,time,
pr);
}
for(int i=0;i<n-1;i++)
{
for(int j=0;j<n-1;j++)
{
if(a[j].priority<a[j+1].priority)
{
process temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
System.out.println("Gantt chart: ");
for(int m=0;m<a.length;m++)
{
System.out.print(a[m].name+ " || ");
}
System.out.println();
int wt=0;
for(int i=0;i<a.length;i++)
{
wt+=(a.length-1-i)*a[i].burst;
}
System.out.println("Total waiting time: "+ wt);
System.out.println("Avg waiting time: "+((float)wt/a.length));
int bt=0;
for(int j=0;j<a.length;j++)
{
bt+=a[j].burst;
}
System.out.println("Total turnaround time: "+(wt+bt));
System.out.println("Average turnaround time: "+((wt+bt)/(float)a.length));
}
}