Discussion: Want to add an object to an array whilst inheriting another object?

Java Java Want to add an object to an array whilst inheriting another object?

Activities (1)
Avatar
JensenBreck
Member
Avatar
JensenBreck:1. December 6:43

Hi,
I am new to Java and am using BlueJ.
Overview of the context of the program.
I am trying to create a Club Database (arraylist, not actual database) where the user can add a new climber (name, age, gender) and which mountain they've climbed (name, height) to the arraylist.
I've created the Climber class and the mountain class. I've also created an ArrayList for the climbers and can add to this array. My question is.. How can I add a climber to the climber ArrayList, and be able to add which mountain they've climbed and its height at the same time?
The method of adding a climber needs to access both the Climber and Mountain class?
Whilst code solving the issue is appreciated, would be helpful if I was shown in the right direction so I can understand it more!
Please help.
Thanks!

I didn't find the right solution from the Internet.

References:http://www.javaprogrammingforums.com/…-object.html

"startup animation explainer ":https://blog.advids.co/…ainer-video/

 
Reply 1. December 6:43
Avatar
David Capka
ICT.social team
Avatar
Replies to JensenBreck
David Capka:1. December 8:42

Hi Jensen, this is a design question. It's a good practice to separate concerns so usually there're classes like ClimberManager which contain the climber collection (the ArrayList) and methods for managing it. There can be methods like addClimber(), removeClimber() etc.

Classes are always available to each other if they're in the same package. So the ClimberManager class will be able to use the Climber and Mountain classes. Maybe you meant how you access the instances? You'll call public methods on the managers to access their data and work with them. You typically pass the needed managers in other managers' constructors.

I suggest to introduce a MountainManager class as well with an ArrayList containing the mountain instances.

Edited 1. December 8:43
Up Reply 1. December 8:42
You can walk through a storm and feel the wind but you know you are not the wind.
To maintain the quality of discussion, we only allow registered members to comment. Sign in. If you're new, Sign up, it's free.

2 messages from 2 displayed.