/* Student class with a constructor that initialises the name, gender, and degreeProgramme. */
public class Student {
public static void main(String[] args){
Student s1 = new Student("a", "b", "c", "d");
System.out.println(s1.toString());
s1.setName("Mary Jones");
s1.setGender("female");
s1.setStudentID("0564");;
s1.setDegreeProgramme("History");
Student s2 = new Student("Mary jones", "female", "0564", "History");
Student s3 = new Student("Mary Jones", "female", "0564", "History");
System.out.println(s1);
System.out.println(s3);
System.out.println(s2);
System.out.println(s1.equals(s2));
System.out.println(s1.equals(s3));
}
private String name; /* instance variable */
private String gender; /* instance variable */
private String studentID; /* instance variable */
private String degreeProgramme; /* instance variable */
/* Student constructor that receives 4 parameters */
public Student(String name, String gender, String studentID, String degreeProgramme){
this.name = name; /* assigns name to instance variable name */
this.gender = gender; /* assigns gender to instance variable gender */
this.studentID = studentID; /* assigns studentID to instance variable studentID */
this.degreeProgramme = degreeProgramme; /* assigns degreeProgramme to instance variable degreeProgramme */
}
/* method that returns the name of the student */
public String getName(){
return name;
}
/* method that returns the gender of the student */
public String getGender(){
return gender;
}
/* method that returns the degree programme of the student */
public String getDegreeProgramme(){
return degreeProgramme;
}
/* method that returns the student ID */
public String getStudentID(){
return studentID;
}
/* method that sets the name of the student */
public void setName(String name){
this.name = name;
}
/* method that sets the student ID */
public void setStudentID(String studentID){
this.studentID = studentID;
}
/* method that sets the gender of the student */
public void setGender(String Gender){
this.gender = Gender;
}
/* method that sets the degree programme of the student */
public void setDegreeProgramme(String degreeProgramme){
this.degreeProgramme = degreeProgramme;
}
/* method that returns the name, gender, and degree programme of the student */
public String toString(){
String studentInfo = "["+name+ ", " +gender+ ", ID: " +studentID+ ", " +degreeProgramme+"]" ;
return studentInfo;
}
} /* end class Student */
Can anyone tell me why the line "System.out.println(s1.equals(s3));" returns output "false" even though the output is identical? I've been trying to figure it out for 10 hours and can't seem to figure out why.