1 // Professor.java 2 // 3 // Ethan Bolker 4 // May, 2004 for cs110 final project 5 6 import java.util.*; 7 8 /** 9 * A Professor object in the WISE system. 10 */ 11 public class Professor extends WISEObject 12 { 13 // private fields for Professor attributes 14 private int teachingLoad; 15 16 /** 17 * Construct a new Professor. 18 */ 19 public Professor( StringTokenizer st ) 20 { 21 super(st.nextToken()); 22 teachingLoad = Integer.parseInt(st.nextToken()); 23 setList( new Schedule(this) ); 24 } 25 26 public String toString() 27 { 28 return getName() + "\t" + teachingLoad; 29 } 30 31 /** 32 * Can this Professor teach at this time? 33 */ 34 public boolean isAvailable( TimeOfDay tod ) 35 { 36 return ( super.isAvailable(tod) && 37 (getList().size() < teachingLoad)); 38 } 39 40 public void unAssign( Course course ) 41 { 42 getList().remove( course ); 43 } 44 45 /** 46 * Add a Course for this Professor. 47 */ 48 public void add( Course course ) 49 throws WISEException 50 { 51 if (getList().contains( course )) { 52 throw new WISEException( 53 getName() + " already assigned to course " + 54 course.getName()); 55 } 56 if ( ! isAvailable( course.getTimeOfDay())) { 57 throw new WISEException( "Professor " + 58 getName() + " not free " + course.getTimeOfDay()); 59 } 60 if (getList().size() >= teachingLoad) { 61 throw new WISEException( "Schedule full: " + getName()); 62 } 63 getList().put( course ); 64 } 65 66 private class Schedule extends CourseList 67 { 68 public Schedule( Professor professor ) 69 { 70 super("Schedule for Professor " + professor.getName()); 71 } 72 73 // same code in Student.java! 74 public String getHeader( ) 75 { 76 StringBuffer buf = new StringBuffer("*** CS110 WISE ***\n"); 77 buf.append( this.getName()); 78 buf.append( "\n"); 79 buf.append( (new Date()).toString() ); 80 buf.append( "\n\nCourses\nname time capacity"); 81 return buf.toString(); 82 } 83 } 84 }