Source of Student.java


  1: /**
  2:  * A simplified Student class to demonstrate inheritance from Person.
  3:  * This class has public and private methods.
  4:  * Undergrad and GradStudent extend this class.
  5:  *
  6:  * @author Mark Young (A00000000)
  7:  */
  8: public class Student extends Person {

 10:     public final String A_NUMBER;
 11:     private int grade;

 13:     public static final int MAX_GRADE = 100;
 14:     private static int numStudents = 0;

 16:     public Student(String n) {
 17:         super(n);   // set my name AS A Person
 18:         grade = 0;
 19:         A_NUMBER = nextANumber();
 20:     }

 22:     public void setGrade(int g) {
 23:         if (isValidGrade(g)) {
 24:             this.grade = g;
 25:         }
 26:     }

 28:     public int getGrade() {
 29:         return this.grade;
 30:     }

 32:     public void publicStudentMethod() {
 33:         System.out.println("\tin publicStudentMethod for " + this);
 34:         publicPersonMethod();
 35:         privateStudentMethod();
 36:         System.out.println("\tpublicStudentMethod done");
 37:     }

 39:     private void privateStudentMethod() {
 40:         System.out.println("\tin privateStudentMethod for " + this);
 41:     }

 43:     @Override
 44:     public void replacedMethod() {
 45:         System.out.println("\tin replacedMethod for the Student " + this);
 46:     }

 48:     @Override
 49:     public void revisedMethod() {
 50:         System.out.println("\tin revisedMethod for the Student " + this);
 51:         super.revisedMethod();
 52:         System.out.println("\trevisedMethod for Student done");
 53:     }

 55:     @Override
 56:     public String toString() {
 57:         return this.getName() + " (" + this.A_NUMBER + ")";
 58:     }

 60:     private boolean isValidGrade(int g) {
 61:         return 0 <= g && g <= MAX_GRADE;
 62:     }

 64:     private String nextANumber() {
 65:         ++numStudents;
 66:         return String.format("A%08d", numStudents);
 67:     }

 69: }