-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThingCount.java
More file actions
75 lines (60 loc) · 1.25 KB
/
Copy pathThingCount.java
File metadata and controls
75 lines (60 loc) · 1.25 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
///(c) A+ Computer Science
//www.apluscompsci.com
//Name -
public class ThingCount implements Comparable
{
private int count;
private Object thing;
public ThingCount()
{
count = 0;
thing = null;
}
public ThingCount(Object thang, int cnt)
{
thing = thang;
count = cnt;
}
public int getCount()
{
return count;
}
public void setCount(int cnt)
{
count = cnt;
}
public void setThing(Object obj)
{
thing = obj;
}
public Object getThing()
{
return thing;
}
public boolean equals(Object obj)
{
if (obj == null) return false;
// Cast provided by starter code implies obj will be ThingCount
ThingCount other = (ThingCount)obj;
if (this.thing == null) {
return other.thing == null;
}
return this.thing.equals(other.thing);
}
public int compareTo(Object obj)
{
ThingCount other = (ThingCount)obj;
// Required check based on Lab Output Exception trace
if (this.thing != null && other.thing != null) {
if (!this.thing.getClass().equals(other.thing.getClass())) {
throw new RuntimeException("both objects are not of the same type");
}
return ((Comparable)this.thing).compareTo(other.thing);
}
return -1;
}
public String toString()
{
return ""+ getThing() + " - " + getCount();
}
}