Answer to Question #261992 in Java | JSP | JSF for hatipo

Question #261992

Shortest Job First Algorithm: Step1:Get the number of process. Step2:Get the id and service time for each process. Step3:Initially the waiting time of first short process as 0 and total time of first short is process the service time of that process. Step4:Calculate the total time and waiting time of remaining process. Step5:Waiting time of one process is the total time of the previous process. Step6:Total time of process is calculated by adding the waiting time and service time of each process. Step7:Total waiting time calculated by adding the waiting time of each process. Step8:Total turn around time calculated by adding all total time of each process. Step9:calculate average waiting time by dividing the total waiting time by total number of process. Step10:Calculate average turn around time by dividing the total waiting time by total number of process. Step11:Display the result.


1
Expert's answer
2021-11-06T13:51:50-0400
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
		 //Step1:Get the number of process
		 Scanner in=new Scanner(System.in);
		 int num_process;
		 System.out.print("(Enter the number of process: ");
		 num_process=in.nextInt();
		 
		 //Step2:Get the id and service time for each process. 
		 String []process_id=new String[num_process];
		 int [] service_time=new int[num_process];
		 
		 for(int i=0;i<num_process;i++){
		     System.out.print("Enter process id for process "+(i+1)+": ");
		     process_id[i]=in.next();
		     System.out.print("Enter service time for process "+(i+1)+": ");
		     service_time[i]=in.nextInt();
		 }
		 int waiting_time[]=new int[num_process];
		 int [] total_time=new int[num_process];
		 int waiting_tm=0;
		 for(int i=0;i<num_process;i++){
		     waiting_time[i]=waiting_tm;
		     waiting_tm=waiting_tm+service_time[i];
		 }
		 System.out.println("Process ID\tService\tWaiting\tTotal");
		 for(int i=0;i<num_process;i++){
		     System.out.println(process_id[i]+"\t"+service_time[i]+"\t"+waiting_time[i]);
		 }
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS