Write a program in Java that could be used to schedule jobs based on the “shorte
ID: 3583850 • Letter: W
Question
Write a program in Java that could be used to schedule jobs based on the “shortest job” algorithm, and compare the running of the programs to using a queue. Use the data from the given table to calculate the “turnaround” time for each job (time a job is completed – time a job enters the system), and the average waiting time for the jobs ((total turnaround time – total “running” time)/number of jobs) a) using a queue b) using a heap based on “expected run time” (CPU burst) Which method gives the lower average waiting time?
Explanation / Answer
import java.util.*;
class Shortestjobfirst
{
public static void main(String args[])
{
Scanner scanner=new Scanner(System.in);
int a,BurstTime[],WaitingTime[],TurnAroundTime[];
System.out.println(“Enter no of process”);
a=scanner.nextInt();
BurstTime =new int[n+1];
WaitingTime =new int[n+1];
TurnAroundTime =new int[n+1];
float AverageWaitingTime=0;
System.out.println(“Enter Burst time for each process”);
for(int i=0;i<n;i++)
{
System.out.println(“Enter BurstTime for process “+(i+1));
BurstTime [i]=scanner.nextInt();
}
for(int i=0;i<n;i++)
{
WaitingTime[i]=0; TurnAroundTime[i]=0;
}
int temp;
for(int i=0;i<n;i++)
{
for(int j=0;j<n-1;j++)
{
if(BurstTime[j]> BurstTime [j+1])
{
temp= BurstTime [j];
BurstTime [j]= BurstTime [j+1];
BurstTime [j+1]=temp;
temp= WaitingTime[j];
WaitingTime[j]= WaitingTime[j+1];
WaitingTime [j+1]=temp;
}
}
}
for(int i=0;i<n;i++)
{
TurnAroundTime[i]= BurstTime [i]+ WaitingTime[i];
WaitingTime[i+1]= TurnAroundTime[i];
}
TurnAroundTime[n]= WaitingTime[n]+ BurstTime [n];
System.out.println(” PROCESS BurstTime WaitingTime TurnAroundTime “);
for(int i=0;i<n;i++)
System.out.println(” “+ i + ” “+BurstTime [i]+” “+WaitingTime[i]+” “+TurnAroundTime[i]);
for(int j=0;j<n;j++) AverageWaitingTime+= WaitingTime[j];
AverageWaitingTime = AverageWaitingTime/n;
System.out.println(“***********************************************”);
System.out.println(“Avg waiting time=”+AverageWaitingTime +” ***********************************************”);
}
}
Thankyou For Your Question for other Question to be solved please provide as seprate questions
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.