public class Student
1: //Student.java
2:
3: package javadocsample;
4:
5: /**
6: * A simple class for a student with a name and a student number.
7: */
8: public class Student
9: extends Person
10: {
11: private int studentNumber;
12:
13: /**
14: * Creates a default student.
15: */
16: public Student()
17: {
18: super();
19: studentNumber = 0;//Indicating no number yet
20: }
21:
22: /**
23: * Creates a student with the supplied name and student number.
24: * @param initialName The name of the student.
25: * @param initialStudentNumber The student's student number.
26: */
27: public Student
28: (
29: String initialName,
30: int initialStudentNumber
31: )
32: {
33: super(initialName);
34: studentNumber = initialStudentNumber;
35: }
36:
37: /**
38: * Resets student name and number.
39: * @param newName The new name to be given to the student.
40: * @param newStudentNumber The student's new student number.
41: */
42: public void reset
43: (
44: String newName,
45: int newStudentNumber
46: )
47: {
48: setName(newName);
49: studentNumber = newStudentNumber;
50: }
51:
52: /**
53: * Gets the student's student number.
54: * @return The student number of the student.
55: */
56: public int getStudentNumber()
57: {
58: return studentNumber;
59: }
60:
61: /**
62: * Sets student number.
63: * newStudentNumber The new student number to be given to the student.
64: */
65: public void setStudentNumber
66: (
67: int newStudentNumber
68: )
69: {
70: studentNumber = newStudentNumber;
71: }
72:
73: /**
74: * Displays the name and student number of the student.
75: * The name and student number appear on separate lines.
76: */
77: public void writeOutput()
78: {
79: System.out.println("Name: " + getName());
80: System.out.println("Student Number: " + studentNumber);
81: }
82:
83: /**
84: * Tests if this student is the same as another student.
85: * @param otherStudent the Student object being compared to the calling
86: * object.
87: * @return true only if calling object and otherStudent have the same
88: * name and the same student number.
89: */
90: public boolean equals
91: (
92: Student otherStudent
93: )
94: {
95: return (this.sameName(otherStudent) &&
96: (this.studentNumber == otherStudent.studentNumber));
97: }
98:
99: /**
100: * Returns a string representation of the student. It consists of the
101: * student's name and student number combined into a single string.
102: */
103: public String toString()
104: {
105: return ("Name: " + getName() + "\nStudent number: " + studentNumber);
106: }
107: }
108: