Hi ... [ Need ur suggestion NOT code .... ]

This is one part of my assignment .. I need your help on how to do this . Below is my short description of my problem ...

I have two classes Named Passenger class and container class .

Passenger class has its own variables like passenger name ( String ) , ID ( int ), and Injury Level (An enum class which has priority like 1 , 2 , 3 and 4 ).

Employee class has its own variable like containerID ( int ) , and ConatinerType ( this can be one of the three types URGENT , IMPORTANT , or GENERAL - these are from enum class )

I will be taking this passenger details[ has 100 of passenger details ] and container details [ 100 of container ] from a file and should write to an Array . Here comes my question.

1. How do i store the Passenger and Container class object in an single array.

[ Note : There must be only one array , not a separate array for passenger and a seperate array for containers.]

Hope i have given clear description of the problem ...

Recommended Answers

All 3 Replies

one suggestion: try first, this looks like a basic question to test if you understand Object Oriented programming or not

to give you an idea how to solve this quickly: all classes can be stored in an array of their superclass (the class they inherit from) and all classes in Java, no matter who wrote them and or it is mentioned in the code itself, inherits from the object "Object"

this is just an idea, remember that 'an array of objects' does not have to be 'Object[] row = new Object[int x];'
it can occur in different ways. just make sure that when youtry to get the info out of it, you check the kind of object before you try to store it into a new (local) variable

remember that an array of objects' does not have to be 'Object[] row = new Object[int x];

what does it mean ......
Should i be doing Object[] obj = new Object[10];
obj[0] = new Passenger( );
obj[1] = new Container( );

it's a possibillity.. or maybe thinking about a Collection, if you do not know how many elements you'll have to put in the array

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.