-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStudent.java
More file actions
40 lines (35 loc) · 965 Bytes
/
Student.java
File metadata and controls
40 lines (35 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
public class Student extends Person {
//Initializers
//
private int id;
//Constructors
//
public Student() {
super(); //Call parent's Constructor
this.id = 0;
}//Student default
public Student(String aName, int anID) {
super(aName); //Call parent with parameter
this.setID(anID); //Set the ID
}//Student with parameters
//Accessors
//
public int getID() {
return this.id;
}//getID
//Mutators
//
public void setID(int anID) {
if(anID >= 0) {//Check for errors
this.id = anID;
}//if
}//setID
public boolean equals(Student aStudent) {
return aStudent != null && //First argument is redundant; super equals will return false if null
super.equals(aStudent) && //A student is always a person but not necessarily vice versa, POLYMORPHISM
this.id == aStudent.getID();
}//equals
public String toString() {
return super.toString() + " " + this.id;
}
}//Student