Skip to content
Snippets Groups Projects
Select Git revision
  • 02cc0e063fcf1dbfc3dd3752a54cb20a3168c50d
  • master default protected
  • sdas
3 results

Cohort.java

Blame
  • Forked from NASR Alexis / Programmation2
    1 commit behind, 4 commits ahead of the upstream repository.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    Cohort.java 1.33 KiB
    import java.util.ArrayList;
    import java.util.List;
    
    /**
     * A group of students.
     */
    
    public class Cohort {
      private final String name;
      private final List<Student> students;
    
      /**
       * Constructs a cohort with a name equals to the specified {@code name} and no students.
       *
       * @param name the name of the constructed Cohort
       */
    
      public Cohort(String name) {
        this.name = name;
        this.students = new ArrayList<>();
      }
    
      /**
       * Add the specified {@code student} to the students of the cohort.
       *
       * @param student the student to be added to the cohort
       */
      public void addStudent(Student student) {
        students.add(student);
      }
    
      /**
       * Returns the list of students of the cohort.
       *
       * @return the list of students of the cohort.
       */
      public List<Student> getStudents() {
        return students;
      }
    
      /**
       * Print via the standard output the name of the cohort and all results associated to the students with their average
       * grade.
       */
      public void printStudentsResults() {
        printName();
        System.out.println();
        for (Student student : students){
          student.printResults();
        }
    
      }
    
      private void printName() {
        System.out.println(name);
      }
    
      /**
       * Returns the name of the cohort.
       *
       * @return the name of the cohort
       */
      @Override
      public String toString() {
        return name;
       }
    }