001package edu.pdx.cs410J.junit; 002 003/** 004 * This class represent a course taught at a university. 005 */ 006public class Course { 007 008 /** The name of the department in which this course is taught */ 009 private String department; 010 011 /** The number of the course */ 012 private int number; 013 014 /** The number of credits for this course */ 015 private int credits; 016 017 //////////////////////// Constructors ///////////////////////// 018 019 /** 020 * Creates a new <code>Course</code> with a given name, taught in a 021 * given department, and for a given number of credits 022 * 023 * @throws IllegalArgumentException 024 * <code>number</code> is less than 100 or credits is less 025 * than 0 026 */ 027 public Course(String department, int number, int credits) { 028 if (number < 100) { 029 String s = "A course number (" + number + 030 ") must be greater than 100"; 031 throw new IllegalArgumentException(s); 032 } 033 034 this.department = department; 035 this.number = number; 036 this.setCredits(credits); 037 } 038 039 ///////////////////// Accessor Methods //////////////////////// 040 041 /** 042 * Sets the number of credits that this course is worth 043 */ 044 public void setCredits(int credits) { 045 if (credits < 0) { 046 String s = "A course cannot be taken for a negative number " + 047 "of credits: " + credits; 048 throw new IllegalArgumentException(s); 049 } 050 051 this.credits = credits; 052 } 053 054 /** 055 * Returns the number of credits that this course is worth 056 */ 057 public int getCredits() { 058 return this.credits; 059 } 060 061 /** 062 * Returns the department that offers this course 063 */ 064 public String getDepartment() { 065 return department; 066 } 067 068 /** 069 * Returns the number of this course 070 */ 071 public int getNumber() { 072 return number; 073 } 074 075}