-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBigTwoCard.java
More file actions
63 lines (58 loc) · 1.38 KB
/
BigTwoCard.java
File metadata and controls
63 lines (58 loc) · 1.38 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
/**
* This class is a subclass of the Card class and is used to model a card used in a Big Two card game.
*
* @author Zach Lyu
*
*/
public class BigTwoCard extends Card {
private static final long serialVersionUID = -713898713776577970L;
/**
* a constructor for building a card with the specified suit and rank.
*
* @param suit
* an integer between 0 and 3
* 0 = Diamond, 1 = Club, 2 = Heart, 3 = Spade
* @param rank
* an integer between 0 and 12
* 0 = 'A', 1 = '2', 2 = '3', ..., 8 = '9', 9 = '0', 10 = 'J', 11
* = 'Q', 12 = 'K'
*/
public BigTwoCard(int suit, int rank) {
super(suit,rank);
}
/**
* Compares this BigTwoCard with the specified BigTwoCard for order.
*
* @param card
* the BigTwoCardto be compared
* @return a negative integer, zero, or a positive integer as this card is
* less than, equal to, or greater than the specified card
*/
public int compareTo(Card card) {
int tempt = this.rank;
int tempc = card.rank;
if (tempt == 0){
tempt = 13;
}
if (tempc == 0){
tempc = 13;
}
if (tempt == 1){
tempt = 14;
}
if (tempc == 1){
tempc = 14;
}
if (tempt > tempc) {
return 1;
} else if (tempt < tempc) {
return -1;
} else if (this.suit > card.suit) {
return 1;
} else if (this.suit < card.suit) {
return -1;
} else {
return 0;
}
}
}