I'm trying to add a Person which has been defined within a constructor to an ArrayList so that I can then call a method which is in another class. I'm having issues with actually adding a Person to the ArrayList however. Here is what I have so far:
GrownUp class updated
public class GrownUp extends Person
{
ArrayList<Person> people;
GrownUp(int age, String name)
{
super(age, name);
this.people = new ArrayList<>();
name = "Bill";
age = 36;
}
public ArrayList<Person> getGrownUp()
{
return people;
}
public void setGrownUp(int age, String name)
{
//how to add a GrownUp?
}
So what needs to be done is:
- Add
Personwho has been defined as "Bill" aged 36 to ArrayListpeople.
Any help is appreciated, thanks.
I previously asked a question similar ot this but was not clear in what I was asking so I've changed my question so that hopefully it makes more sense in what I'm trying to achieve. I've added a get method but I can't figure out how to do the set method. how would I relate the Person constructor to the ArrayList to add a person into it?