| | |
How to Store two different class objects in Same array. - new to Java ..Need Help
Thread Solved
![]() |
•
•
Join Date: Sep 2008
Posts: 11
Reputation:
Solved Threads: 0
How to Store two different class objects in Same array. - new to Java ..Need Help
0
#1 Sep 25th, 2008
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.
[ 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 ...
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.
Hope i have given clear description of the problem ...
Re: How to Store two different class objects in Same array. - new to Java ..Need Help
0
#2 Sep 25th, 2008
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
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
•
•
Join Date: Sep 2008
Posts: 11
Reputation:
Solved Threads: 0
Re: How to Store two different class objects in Same array. - new to Java ..Need Help
0
#3 Sep 25th, 2008
Re: How to Store two different class objects in Same array. - new to Java ..Need Help
0
#4 Sep 25th, 2008
![]() |
Similar Threads
- having some trouble with my project (Java)
- GUI buttons Inventory Part 5 (Java)
- How to implement a binary tree Using HashMap Collection in java (Java)
- array problem in java "Snake game" (Java)
- java problem (Java)
- Java practice questions (Java)
- sorting through an array of objects (Java)
- need help with java (Java)
- Java with String Tokenizer (Java)
Other Threads in the Java Forum
- Previous Thread: How to go back in "main method"
- Next Thread: how to use scanner correctly
| Thread Tools | Search this Thread |
-xlint actionlistener android api applet application array automation bi binary blackberry block bluetooth character class client code compile compiler component consumer database desktop developmenthelp eclipse error fractal freeze ftp functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide image int j2me j2seprojects java javac javaee javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux mac main map method mobile myregfun netbeans nonstatic notdisplaying number online pearl printf problem program project qt researchinmotion rotatetext rsa scanner screen server set singleton sms sort spamblocker sql string swing system textfields thread threads time title tree tutorial-sample update variablebinding windows working xor





