I'm trying to create a Person-object inside of a method called on, and then i want to add that person to a list of participants.
public void addPerson(String name, int age){
//Adding person in a list of participants, capping it at 99 participants
int i = 0;
if (i<100) {
Person participant = new Person(name, age);
participants.add(participant.getName());
this.newest= deltager;
i++;
}
}
If i want to call on a specific participant after having filled up the list, how would i name the object so that they won't all be called "participant"? Wouldn't the object be overridden every time i add a new person, because the name of it would be the same?
if (participants.size() < 100) {. You might consider returning a boolean, whether added.