-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCard.java
More file actions
70 lines (59 loc) · 1.93 KB
/
Card.java
File metadata and controls
70 lines (59 loc) · 1.93 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
package WCG;
class Card {
private int rank; //initialize the rank (2,3,4...King, Ace)
private int suit; //initialize the suit (spades, hearts...)
public Card(int suit, int rank){
this.rank = rank;
this.suit = suit;
}
public int getCard(){
return rank;
}
public void setCard(int rank){
this.rank = rank;
}
@Override
public String toString(){
//combine rank and suit together into a single string(ex: Ace of Diamonds)
//suing StringBuilder for modifiability later on
StringBuilder displayCard = new StringBuilder();
//personal choice to use switch
switch(rank){
//since rank is int type, now match int 11 to String jack...14 to Ace
case 11:
displayCard.append("Jack");
break;
case 12:
displayCard.append("Queen");
break;
case 13:
displayCard.append("King");
break;
case 14:
displayCard.append("Ace");
break;
default:
displayCard.append(rank); //number from 2 to 10 does not need to modify
break;
}
displayCard.append(" of "); //setting the format of the output
switch(suit){
case 0:
displayCard.append("Spades");
break;
case 1:
displayCard.append("Hearts");
break;
case 2:
displayCard.append("Clubs");
break;
case 3:
displayCard.append("Diamonds");
break;
default:
break;
}
//return the result of an entire cmombined string
return displayCard.toString();
}
}