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];
                  }
              }

Your question pertains to computer science in general more than it does to java, maybe you should try posting in that forum?

commented: In academics we are simulating the OS CPU Scheduling policies in either Java or C/C++. So it can be posted in this forum. +0
commented: I just dont get what faisal6621 meant to justify the negative rep +6

There is no main() method in the code.
How could be executed as t also doesn't have any applet or frame used.

Please recheck your code and re-submit.

Your optimistic that the OP remembers this after 9 months.

I did a java operative system simulator some time ago. Yo can check it out doing clic here: [snipped]. I hope it is useful.

Now after 15 months there is another post on this thread.

Jajaja, it still can be useful

Please do not resurrect old threads just to promote blog entries. Thread closed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.