001package edu.pdx.cs410J.junit;
002
003import java.util.*;
004
005/**
006 * This class represents a section of a course being offered in a
007 * given term during a given year.
008 */
009public class Section {
010
011  /** The winter term */
012  public static final int WINTER = 0;
013
014  /** The spring term */
015  public static final int SPRING = 1;
016
017  /** The summer term */
018  public static final int SUMMER = 2;
019
020  /** The fall term */
021  public static final int FALL = 3;
022
023  /////////////////////  Instance Fields  ////////////////////////
024
025  /** The course being offered */
026  private Course course;
027
028  /** The term in which section is offered */
029  private int term;
030
031  /** The year in which the section is offered */
032  private int year;
033
034  /** The student enrolled in the course */
035  private Set<Student> students;
036
037  //////////////////////  Constructors  //////////////////////////
038
039  /**
040   * Creates a new section of a course being offered in the given term
041   * and year.  Initially, no students are enrolled.
042   *
043   * @throws IllegalArgumentException
044   *         If the <code>term</code> is not one of {@link #WINTER},
045   *         {@link #SPRING}, {@link #SUMMER}, or {@link #FALL}.
046   *         (Great, now I've got that James Taylor song going through
047   *         my head.) 
048   */
049  public Section(Course course, int term, int year) {
050    if (term != WINTER && term != SPRING && term != SUMMER && 
051        term != FALL) {
052      String s = "Invalid term code: " + term;
053      throw new IllegalArgumentException(s);
054    }
055
056    this.course = course;
057    this.term = term;
058    this.year = year;
059    this.students = new HashSet<Student>();
060  }
061
062  /////////////////////  Accessor Methods  ////////////////////////
063
064  /**
065   * Enrolls a student in this section
066   */
067  public void addStudent(Student student) {
068    this.students.add(student);
069  }
070
071  /**
072   * Drops a student from this section
073   *
074   * @throws IllegalArgumentException
075   *         The <code>student</code> is not enrolled in this section
076   */
077  public void dropStudent(Student student) {
078    if (!this.students.remove(student)) {
079      String s = "Student " + student + " is not enrolled in " + this;
080      throw new IllegalArgumentException(s);
081    }
082  }
083
084  /**
085   * Returns the number of students enrolled in this section
086   */
087  public int getClassSize() {
088    return this.students.size();
089  }
090
091  /**
092   * Returns the course being offered
093   */
094  public Course getCourse() {
095    return course;
096  }
097
098  /**
099   * Returns the students enrolled in this section
100   */
101  public Set<Student> getStudents() {
102    return students;
103  }
104
105  /**
106   * Returns the term in which this section is offered
107   */
108  public int getTerm() {
109    return term;
110  }
111
112  /**
113   * Returns the year in which this section is offered
114   */
115  public int getYear() {
116    return year;
117  }
118
119}