public class Student extends Person
1: package inheritance;
3: /**
4: * A simplified Student class to demonstrate inheritance from Person.
5: * This class has public and private methods.
6: * Undergrad and GradStudent extend this class.
7: *
8: * @author Mark Young (A00000000)
9: */
10: public class Student extends Person {
12: public final String A_NUMBER;
13: private int grade;
15: public static final int MAX_GRADE = 100;
16: private static int numStudents = 0;
18: public Student(String n) {
19: super(n); // set my name AS A Person
20: grade = 0;
21: A_NUMBER = nextANumber();
22: }
24: public void setGrade(int g) {
25: if (isValidGrade(g)) {
26: this.grade = g;
27: }
28: }
30: public int getGrade() {
31: return this.grade;
32: }
34: public void publicStudentMethod() {
35: System.out.println("\tin publicStudentMethod for " + this);
36: publicPersonMethod();
37: privateStudentMethod();
38: System.out.println("\tpublicStudentMethod done");
39: }
41: private void privateStudentMethod() {
42: System.out.println("\tin privateStudentMethod for " + this);
43: }
45: @Override
46: public void replacedMethod() {
47: System.out.println("\tin replacedMethod for the Student " + this);
48: }
50: @Override
51: public void revisedMethod() {
52: System.out.println("\tin revisedMethod for the Student " + this);
53: super.revisedMethod();
54: System.out.println("\trevisedMethod for Student done");
55: }
57: @Override
58: public String toString() {
59: return this.getName() + " (" + this.A_NUMBER + ")";
60: }
62: private boolean isValidGrade(int g) {
63: return 0 <= g && g <= MAX_GRADE;
64: }
66: private String nextANumber() {
67: ++numStudents;
68: return String.format("A%08d", numStudents);
69: }
71: }