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.
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.