Source of Student.java


  1: //Student.java
  2: 
  3: public class Student
  4:     extends Person
  5: {
  6:     private int studentNumber;
  7: 
  8:     public Student()
  9:     {
 10:         super();
 11:         studentNumber = 0;//Indicating no number yet
 12:     }
 13: 
 14:     public Student
 15:     (
 16:         String initialName,
 17:         int initialStudentNumber
 18:     )
 19:     {
 20:         super(initialName);
 21:         studentNumber = initialStudentNumber;
 22:     }
 23: 
 24:     public void reset
 25:     (
 26:         String newName,
 27:         int newStudentNumber
 28:     )
 29:     {
 30:         setName(newName);
 31:         studentNumber = newStudentNumber;
 32:     }
 33: 
 34:     public int getStudentNumber()
 35:     {
 36:         return studentNumber;
 37:     }
 38: 
 39:     public void setStudentNumber
 40:     (
 41:         int newStudentNumber
 42:     )
 43:     {
 44:         studentNumber = newStudentNumber;
 45:     }
 46: 
 47:     public void writeOutput()
 48:     {
 49:         System.out.println("Name: " + getName());
 50:         System.out.println("Student Number: " + studentNumber);
 51:     }
 52: 
 53:     public boolean equals
 54:     (
 55:         Student otherStudent
 56:     )
 57:     {
 58:         return this.hasSameName(otherStudent) &&
 59:             (this.studentNumber == otherStudent.studentNumber);
 60:     }
 61: 
 62:     public String toString()
 63:     {
 64:         return "Name: " + getName() + "\nStudent number: " + studentNumber;
 65:     }
 66: 
 67:     /*
 68:     //For Optional Section
 69:     public boolean equals
 70:     (
 71:         Object otherObject
 72:     )
 73:     {
 74:         if (otherObject == null)
 75:             return false;
 76:         else if (!(otherObject instanceof Student))
 77:             return false;
 78:         else
 79:         {
 80:             Student otherStudent = (Student)otherObject;
 81:             return (this.sameName(otherStudent)
 82:                 && (this.studentNumber == otherStudent.studentNumber));
 83:         }
 84:     }
 85:     */
 86: }