Skip to content
Snippets Groups Projects
Select Git revision
  • 3bc0c45339beee4140b4ee4dbb55037e314fba6f
  • master default protected
2 results

People.java

Blame
  • Forked from NAVES Guyslain / ProgAvExercices
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    People.java 822 B
    package fr.univamu.progav.td2;
    
    import java.util.List;
    
    public class People {
    
      private final String name;
      private final int age;
    
      public People(String name, int age) {
        this.name = name;
        this.age = age;
      }
    
      public String getName() {
        return name;
      }
    
      public int getAge() {
        return age;
      }
    
      /** Decides whether the list contains a 25-year-old "Charlie"
       * @param peopleList
       * @return true if a 25-year-old charlie is in the list
       */
      public static int whereIsCharlie(List<People> peopleList) {
        People charlie = new People("Charlie", 25);
        int count = 0;
        for (People p : peopleList) {
          if (p == charlie) {
            return  count;
          }
          count++;
        }
        return -1; // Charlie is not here.
      }
    
    
      @Override
      public String toString() {
        return this.name;
      }
    }