Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class Person
- {
- public String name;
- public int age;
- public Person()
- {
- }
- public void setName(String nameOfPerson)
- {
- name = nameOfPerson;
- }
- public void setAge(int ageInYears)
- {
- age = ageInYears;
- }
- public int getAge()
- {
- return age;
- }
- public String getName()
- {
- return name;
- }
- }
- import java.util.ArrayList;
- public class People
- {
- ArrayList<Person> people = new ArrayList<Person>();
- private int maxAge;
- public People()
- {
- }
- ******************************************* not sure what to do with this bit either actually - i need to add all my instances of person to the ArrayList right? But idk how to do that when its an object you're adding not just a bit of String or something...
- public void newPerson()
- {
- people.add(Person);
- }
- *******************************************
- public int greatestAge()
- {
- for (int i = 0; i < people.size(); i++){
- people.get(i).getAge(age);
- if (age>maxAge)
- {maxAge = age;}
- return maxAge;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement