-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathRating.java
35 lines (30 loc) · 873 Bytes
/
Rating.java
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
// An immutable passive data object (PDO) to represent the rating data
public class Rating implements Comparable<Rating> {
private String item;
private double value;
public Rating (String anItem, double aValue) {
item = anItem;
value = aValue;
}
// Returns item being rated
public String getItem () {
return item;
}
// Returns the value of this rating (as a number so it can be used in calculations)
public double getValue () {
return value;
}
// Returns a string of all the rating information
public String toString () {
return "[" + getItem() + ", " + getValue() + "]";
}
public int compareTo(Rating other) {
if (value < other.value) {
return -1;
}
if (value > other.value) {
return 1;
}
return 0;
}
}