Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/org/launchcode/java/demos/lsn4classes2/Course.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,32 @@ public class Course {
// TODO: Add your custom 'toString' method here. Make sure it returns a well-formatted String rather than
// just the class fields.

public String toString() {
String courseReport = String.format("%s is taught by %T", this.topic, this.instructor);
return courseReport;
}

// TODO: Add your custom 'equals' method here. Consider which fields should match in order to call two
// Course objects equal.
public boolean equals(Object toBeCompared) {
if(toBeCompared == this) {
return true;
}

if(toBeCompared == null) {
return false;
}

if(toBeCompared.getClass() != getClass()){
return false;
}

Course theCourse = (Course) toBeCompared;
return theCourse.getCoursetopic() == getCoursetopic();
}

public String getCoursetopic() {
return topic;
}
}

22 changes: 22 additions & 0 deletions src/org/launchcode/java/demos/lsn4classes2/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,32 @@ public void addGrade(int courseCredits, double grade) {

// TODO: Add your custom 'toString' method here. Make sure it returns a well-formatted String rather
// than just the class fields.
public String toString() {
String studentReport = String.format("%s is %s with %d credits and a GPA of %.2f", this.name, this.getGradeLevel(this.numberOfCredits), this.getNumberOfCredits(), this.getGpa());
return studentReport;
}


// TODO: Add your custom 'equals' method here. Consider which fields should match in order to call two
// Student objects equal.

public boolean equals(Object toBeCompared) {
if(toBeCompared == this) {
return true;
}

if(toBeCompared == null) {
return false;
}

if(toBeCompared.getClass() != getClass()) {
return false;
}

Student theStudent = (Student) toBeCompared;
return theStudent.getStudentId() == getStudentId();
}

public String getName() {
return name;
}
Expand Down