// Faculty4.java // Faculty class extends the Person4 class and adds an array for sections // This class clones the class array when it returns it; maintains encapsulation public class Faculty4 extends Person4 { private int lastClass; // age private int sections[]; // sections taking // Facutly constructor initializes sections taught public Faculty4() { super( ); int temp[] = {0}; sections = new int[20]; setStudent(temp); } // set a new Facutly value // validity checks on the age; set invalid values to 20 public void setStudent( int sections[] ) { int i; for (i = 0; i < sections.length; i++) { this.sections[i] = sections[i]; } lastClass = i - 1; } public int[] getClasses() { return sections.clone(); } public void addClass(int newClass) { if (lastClass == sections.length - 1) return; else if (sections[lastClass] == 0) sections[lastClass] = newClass; else sections[++lastClass] = newClass; } public int getNumClasses() { return lastClass + 1; } public int getClass(int theElement) { return sections[theElement]; } public String getType(){ return "Faculty"; } } // end class Facutly4 /************************************************************************** * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and * * Prentice Hall. All Rights Reserved. * * * * DISCLAIMER: The authors and publisher of this book have used their * * best efforts in preparing the book. These efforts include the * * development, research, and testing of the theories and programs * * to determine their effectiveness. The authors and publisher make * * no warranty of any kind, expressed or implied, with regard to these * * programs or to the documentation contained in these books. The authors * * and publisher shall not be liable in any event for incidental or * * consequential damages in connection with, or arising out of, the * * furnishing, performance, or use of these programs. * *************************************************************************/