I am in desperate need of help... I were to create Operating System's Shortest Job First Preemptive Algorithm .... The problem is that I am not getting how to calculate the average waiting time of each process... HELP !
SJF.java:
import javax.swing.JOptionPane;
import java.util.*;
public class SJF {
int process=0;
int BurstTime[]=new int[20];
int ArrivalTime[]=new int[20];
int in=0;
int totaltime=0;
int temp[],temp1,temp2,temp3;
SJF h[]=new SJF[20];
public void setProcess(int t){
process=t;
}
public int getProcess(){
return process;
}
void getData(){
in=Integer.parseInt(JOptionPane.showInputDialog("Enter Number of Processes:"));
for(int i=0;i<in;i++){
int bt=Integer.parseInt(JOptionPane.showInputDialog("Enter Burst Time of Process P"+(i+1)));
BurstTime[i]=bt;
}
for(int i=0;i<in;i++){
int at=Integer.parseInt(JOptionPane.showInputDialog("Enter Arrival Time of Process P"+(i+1)));
ArrivalTime[i]=at;
}
}
void cpuScheduale(){
for(int i=0;i<in;i++){
h[i]= new SJF();
totaltime=totaltime+BurstTime[i];
h[i].setProcess(i);
System.out.println(h[i].getProcess());
}
System.out.println("Your Input:");
System.out.println("----------------------");
System.out.println("Process"+" "+"Burst Time"+" "+"Arrival Time");
for(int i=0;i<in;i++){
int t=h[i].getProcess();
System.out.println("P"+(t+1)+" "+BurstTime[i]+" "+ArrivalTime[i]);
}
}
void Compare(){
/*for(int i=0;i<in;i++){
if(BurstTime[i]>BurstTime[i+1]){
temp=BurstTime[i];
BurstTime[i]=BurstTime[i+1];
BurstTime[i+1]=temp;
Arrays.sort(ArrivalTime, 0, in);
System.out.println(BurstTime[i]+" "+ArrivalTime[i]);
}*/
for(int i=0;i<in;i++){
if(BurstTime[i]>BurstTime[i+1]){
Arrays.sort(ArrivalTime, i, in);
h[i].setProcess(temp1);
Arrays.sort(BurstTime, i, in);
}
System.out.println(BurstTime[i]+" "+ArrivalTime[i]);
}
}
void Calc(){
/* for(int i=0;i<in;i++){
for(int j=ArrivalTime[i];j>0;j--){
if(ArrivalTime[i]<ArrivalTime[j+1]){
System.out.println("Hey");
}
else{
System.out.println("Nay man");
}
System.out.println();
}
}*/
for(int i=0;i<in;i++){
temp[i]=BurstTime[i]-ArrivalTime[i];
}
}