Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Using ArrayList and Collections of objects

807601Apr 16 2008 — edited Apr 17 2008
I am having trouble creating an arraylist that either stores another arraylist or multiple objects in the same position.

The program's main is provided and asks me to rely on three classes I created, passing into them (Person(string name, int weight), Elevator(int capacity), ElevatorCollection(int [caps]).


The driver program calls a getElevator(int pos) method from ElevatorCollectioion. I seem to having problems creating an arrayList or something to hold multiple Person objects at each position.

I tried:

ArrayList<Person> building = new ArrayList<Person>
ArrayList<building> elevColl = new ArrayList<Person>

Obviously doesn't work because building is not a type.

The task is to add people with a .add method which automatically adds them into a proper elevator based on person's weight >= capacity: updating NumPeople, the capacity of each elevator, and adding them into some type of collection which holds multiple objects of Person at each pos. The main then s.o.println a variable which stores this collection, asking me I think to overload a toString method so it prints each elevator with every person in said elevator on different lines.

I have figured out the majority of everything besides the above.

Am I going about this wrong?

I am grateful for any help, I've been working on this for days
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 15 2008
Added on Apr 16 2008
12 comments
527 views