-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathCourse.java
More file actions
42 lines (32 loc) · 1.12 KB
/
Course.java
File metadata and controls
42 lines (32 loc) · 1.12 KB
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
41
package org.launchcode.java.demos.lsn4classes2;
import java.util.ArrayList;
import java.util.Objects;
public class Course {
private String topic;
private Teacher instructor;
private ArrayList<Student> enrolledStudents;
// 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;
}
}