Get up to 80 % extra points for free! More info:

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

In the previous quiz, Online Java Quiz, we tested our experience gained from the course.

Activities
Avatar
JensenBreck
Member
Avatar
JensenBreck:12/1/2017 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
12/1/2017 6:43
Avatar
Replies to JensenBreck
David Capka Hartinger:12/1/2017 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 12/1/2017 8:43
Up Reply
12/1/2017 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.