Let’s do a quick analysis of your code:
Your Student
object looks like a constructor for the Student
class object type which is most likely in this case an inner class of the CollegeTester class.
So here’s the deal, your addCommand()
already connects your CollegeTester class with your Student class, by executing this command after you provide the input for name and address it creates a new instance of the Student object.
This means that at this point, you need to add this newly created Student
object to your College
list.
However if you take a good look at your College
list you will see that:
- It’s marked private (meaning it can be accessed only from within itself)
- It is a list of
College
type objects (but you need a list ofStudent
type objects)
So your options at this point are:
- Make the list public
- Create a public setter method that will do the adding
You will also need to change the list object type to Student
if you wish to store Student
objects in the list.
Also unless you want to have multiple colleges you might consider declaring your list as static
otherwise you will have to declare an instance of it to add the Student
objects to it.
Hopefully this is enough information to get you started in the right direction.
Also an advice is to not look at classes as actual objects, instead look at them as blueprints that can be used to construct those real objects.
2
solved Connecting 3 different java files