0

I have 3 classes (Air, Ocean and Ground) representing 3 modes of transportation:

Air:

Class Air
{

  public int ID;
  public datetime Start;
  public datetime End;

  public string FlightNo;

}

Ground:

Class Ground
{

  public int ID;
  public datetime Start;
  public datetime End;

  public string VehicleNo;
  public string DriverName;
  public string DriverMobile;

}

Ocean:

Class Ocean
{

  public int ID;
  public datetime Start;
  public datetime End;

  public string VessalName;
  public string FTZNo;

}

I have an object named Job. Transportation is a part of Job. Job can have multiple Transportation(Air, Ocean, Ground)

How to assign Transportation list in Job class?

Bas Peeters
  • 3,269
  • 4
  • 33
  • 49
Nijil Nmk
  • 1
  • 8

1 Answers1

0

The question is unclear.In my understanding your question is how to assign a Transportation list to Job object? Right? I assumed Job class has a member of type

List<Tranportation> transList;

And all the Air,Water and Ground are subclass of Transportation. so you can assign the list with a setter method. say

void setTransportationList(List<Transportation> x){
    this.transList=x;
}

EDIT

Lets say you have to print the details of the traspotations used in the Job object

Class Job{
     public List<Transportation> trainsList;


     public void setTransportationList(List<Transportation> x){
        this.transList=x;
     }
     void printTransportationDetails(){
         Iterator itr = this.transList.iterator();
         while(itr.hasNext()) {
         Transportation element = itr.next();
         element.printDetails();
         }
     }
}

Now your Transportation subclass should have a printDetails() member function.

gman
  • 1,242
  • 2
  • 16
  • 29
  • but some time job may have 3 types of transportation same time. Is it i want to create 3 diffrent proprty list in job? – Nijil Nmk Dec 23 '14 at 06:36
  • You can have a List of Transportation objects with the type List. So that you can access the multiple entries in the list as you like. Does this answer your question?? – gman Dec 23 '14 at 06:39
  • but Air have only flight no , ground have 3 extra proeprty , ocean have 2 extra proprty – Nijil Nmk Dec 23 '14 at 06:41
  • now this problem can be solved with the solution from the following link http://stackoverflow.com/questions/307765/what-is-a-good-way-to-check-if-an-objects-type-is-a-particular-subclass Does this solves your problem?? – gman Dec 23 '14 at 06:46
  • how will be my job class properties ? – Nijil Nmk Dec 23 '14 at 06:52
  • note the edit. If this answers your question accept and upvote the answer. – gman Dec 23 '14 at 06:59
  • But gman i need to print flight no with flight no label and Vehicle no with vehicle no label – Nijil Nmk Dec 23 '14 at 07:09
  • You can always do so by having different definitions for printDetails() in Air, Ocean and Ground classes. – gman Dec 23 '14 at 07:11
  • class job { List m_objAirlList; List m_objGroundList; List m_objOceanList; } – Nijil Nmk Dec 23 '14 at 07:12
  • yeah, Thats one one solution. – gman Dec 23 '14 at 07:14