-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActivity.java
More file actions
48 lines (41 loc) · 1.32 KB
/
Activity.java
File metadata and controls
48 lines (41 loc) · 1.32 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
42
43
44
45
46
47
48
public abstract class Activity {
// attributes
private String name;
private int duration; // in hours
private int difficulty; // scale 1-10
// argumented constructor
public Activity(String name, int duration, int difficulty) {
this.name = name;
this.duration = duration;
this.difficulty = difficulty;
}
// get methods
public String getName() {
return name;
}
public int getDuration() {
return duration;
}
public int getDifficulty() {
return difficulty;
}
// overridden toString that gives all attributes formatted
@Override
public String toString() {
return "Activity: " + name + "\nDuration: " + duration + " hours\nDifficulty: " + difficulty;
}
// abstract method - used to be dynamically (output depends on the class) called in subclasses of Activity
public abstract void displayActivityData(int month, String location);
// overridden equals method to compare activities based on their name
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || getClass() != obj.getClass()) {
return false;
}
Activity activity = (Activity) obj;
return name.equals(activity.name);
}
}