-
Notifications
You must be signed in to change notification settings - Fork 0
/
Card.java
69 lines (62 loc) · 1.36 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package hw3;
/*
* This class creates the Card object, which is a basic class that will be used in other classes.
*/
public class Card {
// A card object has three attributes, the suit, the rank and the score.
private String suit;
private String rank;
private int score;
/*
* This is the constructor of the Card class.
* @param s is the suit.
* @param r is the rank.
* The score of Ace is set to be 1 initially.
*/
public Card(String s, String r) {
suit=s;
rank=r;
if(rank.equalsIgnoreCase("Jack")||rank.equalsIgnoreCase("Queen")||rank.equalsIgnoreCase("King")||rank.equalsIgnoreCase("10")) {
score=10;
}
else if(rank.equalsIgnoreCase("2")){
score=2;
}
else if(rank.equalsIgnoreCase("3")) {
score=3;
}
else if(rank.equalsIgnoreCase("4")) {
score=4;
}
else if(rank.equalsIgnoreCase("5")) {
score=5;
}
else if(rank.equalsIgnoreCase("6")){
score=6;
}
else if(rank.equalsIgnoreCase("7")) {
score=7;
}
else if(rank.equalsIgnoreCase("8")){
score=8;
}
else if(rank.equalsIgnoreCase("9")) {
score=9;
}
else {
score=1;
}
}
// This method is the getter of the score.
public int getScore() {
return score;
}
// This method is the getter of the suit.
public String getSuit() {
return suit;
}
// This method is the getter of the rank.
public String getRank() {
return rank;
}
}