-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComparatorUse.java
More file actions
49 lines (40 loc) · 817 Bytes
/
ComparatorUse.java
File metadata and controls
49 lines (40 loc) · 817 Bytes
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
package Data_Structures;
public class ComparatorUse implements Comparable<ComparatorUse> {
int size;
String type;
ComparatorUse(int size, String type)
{
this.size = size;
this.type = type;
}
public int getsize()
{
return size;
}
public String gettype()
{
return type;
}
@Override
public int compareTo(ComparatorUse cc)
{
if(this.getsize()>cc.getsize())
{
return 1;
}
else if(this.getsize()<cc.getsize())
{
return -1;
}
else return 0;
}
public static void main(String[] args) {
ComparatorUse tv1 = new ComparatorUse(55, "Samsung");
ComparatorUse tv2 = new ComparatorUse(55, "Sony");
if (tv1.compareTo(tv2) > 0) {
System.out.println(tv1.gettype() + " is better.");
} else {
System.out.println(tv2.gettype() + " is better.");
}
}
}