Advertisement
econnell111

Emma Java

Dec 8th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. import java.util.ArrayList;
  2.  
  3. public class Person
  4. {
  5.     public String name;
  6.     public int age;
  7.  
  8.    
  9.     public Person()
  10.     {
  11.     }
  12.    
  13.     public void setName(String nameOfPerson)
  14.     {
  15.         name = nameOfPerson;
  16.     }
  17.    
  18.     public void setAge(int ageInYears)
  19.     {
  20.         age = ageInYears;
  21.     }
  22.    
  23.     public int getAge()
  24.     {
  25.         return age;
  26.     }
  27.    
  28.     public String getName()
  29.     {
  30.         return name;
  31.     }
  32.    
  33. }
  34.  
  35.  
  36.  
  37. import java.util.ArrayList;
  38.  
  39. public class People
  40. {
  41.     ArrayList<Person> people = new ArrayList<Person>();
  42.    
  43.     private int maxAge;
  44.    
  45.     public People()
  46.     {
  47.     }
  48.  
  49.     ******************************************* 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...
  50.  
  51.    public void newPerson()
  52.    {
  53.        people.add(Person);
  54.    }
  55.    *******************************************
  56.    public int greatestAge()
  57.    {
  58.        for (int i = 0; i < people.size(); i++){
  59.            people.get(i).getAge(age);
  60.        if (age>maxAge)
  61.        {maxAge = age;}
  62.        return maxAge;
  63.     }
  64.    }
  65.    
  66.    
  67.    
  68.    
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement