-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask.java
More file actions
60 lines (60 loc) · 1.47 KB
/
Task.java
File metadata and controls
60 lines (60 loc) · 1.47 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
49
50
51
52
53
54
55
56
57
58
59
60
/*
* @author Tien N.
* A task object has 2 attributes:
* a priority number and a description
*/
public class Task implements Comparable<Task>{
private int aPriority;
private String aDescription;
/**
* overloaded constructor
* @param pPriority
* @param pDescription
*/
public Task(int pPriority, String pDescription) {
aPriority = pPriority;
aDescription = pDescription;
}
@Override
/**
* compare 2 tasks by their priority number
* @return negative integer if task1 < task2
* @return 0 if task1 = task2
* @return positive integer if task1 > task2
*/
public int compareTo(Task pTask) {
String task1 = String.valueOf(this.aPriority) + " " + this.aDescription;
String task2 = String.valueOf(pTask.aPriority) + " " + pTask.aDescription;
return task1.compareTo(task2);
}
@Override
/**
* 2 tasks are equal if they have the same description
* @return true if equals
* @return false if not equals
*/
public boolean equals(Object o) {
Task otherTask = (Task) o;
if (this.aDescription.equalsIgnoreCase(otherTask.aDescription)) {
return true;
}
else {
return false;
}
}
@Override
/**
* corresponding with equals() method
* @return a task's hashCode based on its description
*/
public int hashCode() {
return this.aDescription.hashCode();
}
@Override
/**
* @return description of a task
*/
public String toString() {
return this.aDescription.trim();
}
}//end of class