diff --git a/src/org/launchcode/java/demos/lsn4classes2/Course.java b/src/org/launchcode/java/demos/lsn4classes2/Course.java index 1da62f376..bb36bfa68 100644 --- a/src/org/launchcode/java/demos/lsn4classes2/Course.java +++ b/src/org/launchcode/java/demos/lsn4classes2/Course.java @@ -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; + } } diff --git a/src/org/launchcode/java/demos/lsn4classes2/Student.java b/src/org/launchcode/java/demos/lsn4classes2/Student.java index e550ccbb7..b65b61ed0 100644 --- a/src/org/launchcode/java/demos/lsn4classes2/Student.java +++ b/src/org/launchcode/java/demos/lsn4classes2/Student.java @@ -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; }