All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.pdx.cs410J.junit.Section Maven / Gradle / Ivy

The newest version!
package edu.pdx.cs410J.junit;

import java.util.*;

/**
 * This class represents a section of a course being offered in a
 * given term during a given year.
 */
public class Section {

  /** The winter term */
  public static final int WINTER = 0;

  /** The spring term */
  public static final int SPRING = 1;

  /** The summer term */
  public static final int SUMMER = 2;

  /** The fall term */
  public static final int FALL = 3;

  /////////////////////  Instance Fields  ////////////////////////

  /** The course being offered */
  private Course course;

  /** The term in which section is offered */
  private int term;

  /** The year in which the section is offered */
  private int year;

  /** The student enrolled in the course */
  private Set students;

  //////////////////////  Constructors  //////////////////////////

  /**
   * Creates a new section of a course being offered in the given term
   * and year.  Initially, no students are enrolled.
   *
   * @throws IllegalArgumentException
   *         If the term is not one of {@link #WINTER},
   *         {@link #SPRING}, {@link #SUMMER}, or {@link #FALL}.
   *         (Great, now I've got that James Taylor song going through
   *         my head.) 
   */
  public Section(Course course, int term, int year) {
    if (term != WINTER && term != SPRING && term != SUMMER && 
        term != FALL) {
      String s = "Invalid term code: " + term;
      throw new IllegalArgumentException(s);
    }

    this.course = course;
    this.term = term;
    this.year = year;
    this.students = new HashSet();
  }

  /////////////////////  Accessor Methods  ////////////////////////

  /**
   * Enrolls a student in this section
   */
  public void addStudent(Student student) {
    this.students.add(student);
  }

  /**
   * Drops a student from this section
   *
   * @throws IllegalArgumentException
   *         The student is not enrolled in this section
   */
  public void dropStudent(Student student) {
    if (!this.students.remove(student)) {
      String s = "Student " + student + " is not enrolled in " + this;
      throw new IllegalArgumentException(s);
    }
  }

  /**
   * Returns the number of students enrolled in this section
   */
  public int getClassSize() {
    return this.students.size();
  }

  /**
   * Returns the course being offered
   */
  public Course getCourse() {
    return course;
  }

  /**
   * Returns the students enrolled in this section
   */
  public Set getStudents() {
    return students;
  }

  /**
   * Returns the term in which this section is offered
   */
  public int getTerm() {
    return term;
  }

  /**
   * Returns the year in which this section is offered
   */
  public int getYear() {
    return year;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy