I am writing a program in java for the Shortest Job First Scheduling , have generate the Process ID and Process Time separately but i have to put both in an array and would like someone to help me please.

If both Process ID and Process Time have a common subset of operations that you can use from the array then you can have them as derived classes:

abstract class process_thingie {
  public abstract String get_thingie();
}

class process_id extends process_thingie {
  private String id;
  
  public process_id ( String init ) {
    id = new String ( init );
  }
  
  public String get_thingie() {
    return id;
  }
  
  // ID specific stuff
}

class process_time extends process_thingie {
  private String time;
  
  public process_time ( String init ) {
    time = new String ( init );
  }
  
  public String get_thingie() {
    return time;
  }
  
  // Time specific stuff
}

public class Main {
  public static void main ( String[] args ) {
    process_thingie[] list = new process_thingie[10];
    
    for ( int i = 0; i < 5; i++ )
      list[i] = new process_id ( "id: " + i );
    for ( int i = 5; i < 10; i++ )
      list[i] = new process_time ( "time: " + i );
    
    for ( int i = 0; i < 10; i++ ) {
      if ( i % 5 == 0 )
        System.out.println();
      System.out.print ( list[i].get_thingie() + "\t" );
    }
  }
}

Provided you only use the common subset of methods from the array items then you can let polymorphism do the dirty work for you.

Thanks Narue you save me ...

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.