java problem with creating arrays

Reply

Join Date: Nov 2004
Posts: 3
Reputation: usha is an unknown quantity at this point 
Solved Threads: 0
usha usha is offline Offline
Newbie Poster

java problem with creating arrays

 
0
  #1
Nov 5th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,614
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 713
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: java problem with creating arrays

 
0
  #2
Nov 5th, 2004
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:
  1. abstract class process_thingie {
  2. public abstract String get_thingie();
  3. }
  4.  
  5. class process_id extends process_thingie {
  6. private String id;
  7.  
  8. public process_id ( String init ) {
  9. id = new String ( init );
  10. }
  11.  
  12. public String get_thingie() {
  13. return id;
  14. }
  15.  
  16. // ID specific stuff
  17. }
  18.  
  19. class process_time extends process_thingie {
  20. private String time;
  21.  
  22. public process_time ( String init ) {
  23. time = new String ( init );
  24. }
  25.  
  26. public String get_thingie() {
  27. return time;
  28. }
  29.  
  30. // Time specific stuff
  31. }
  32.  
  33. public class Main {
  34. public static void main ( String[] args ) {
  35. process_thingie[] list = new process_thingie[10];
  36.  
  37. for ( int i = 0; i < 5; i++ )
  38. list[i] = new process_id ( "id: " + i );
  39. for ( int i = 5; i < 10; i++ )
  40. list[i] = new process_time ( "time: " + i );
  41.  
  42. for ( int i = 0; i < 10; i++ ) {
  43. if ( i % 5 == 0 )
  44. System.out.println();
  45. System.out.print ( list[i].get_thingie() + "\t" );
  46. }
  47. }
  48. }
Provided you only use the common subset of methods from the array items then you can let polymorphism do the dirty work for you.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 3
Reputation: usha is an unknown quantity at this point 
Solved Threads: 0
usha usha is offline Offline
Newbie Poster

Re: java problem with creating arrays

 
0
  #3
Nov 6th, 2004
Thanks Narue you save me ...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC