-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCard.java
49 lines (46 loc) · 1.25 KB
/
Card.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
public class Card {
private final int num;
private final Shape shape;
public Card(int num, Shape shape) {
this.num = num;
this.shape = shape;
}
public int getNum() {
return num;
}
public int compare(Card other) {
/** Compare cards based on their number*/
if (this.num < other.getNum()) {
return -1;
}
if (this.num > other.getNum()) {
return 1;
}
return 0;
}
@Override
public String toString() {
/** print with the format: "_number_ of _shape_"*/
String returnValue = "";
if (num > 1 && num <= 10) {
returnValue = "" + this.num;
} else {
switch (this.num) {
case 11:
returnValue = "Jack";
break;
case 12:
returnValue = "Queen";
break;
case 13:
returnValue = "King";
break;
case 1:
returnValue = "Ace";
break;
default:
}
}
return returnValue + " of " + this.shape;
}
}