-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCard.java
More file actions
34 lines (33 loc) · 888 Bytes
/
Copy pathCard.java
File metadata and controls
34 lines (33 loc) · 888 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
/*
Card class for Problem 54.
Implements the Comparable interface to enable sorting of arrays of objects of type Card.
*/
public class Card implements Comparable{
String suit;
int value;
public Card(String cardSuit, int cardVal){
this.suit = cardSuit;
this.value = cardVal;
}
public String toString(){
return Integer.toString(this.value) + " " + this.suit;
}
public int compareTo(Object o) {
try{
if (o instanceof Card) {
Card c = (Card)o;
if (this.value < c.value)
return -1;
else if (this.value > c.value)
return 1;
else
return 0;
}
return 0;
}
catch(Exception e){
e.printStackTrace();
return 0;
}
}
}