-
Notifications
You must be signed in to change notification settings - Fork 0
/
Card.java
92 lines (81 loc) · 2.27 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* Card.java
*
* <code>Card</code> represents a playing card.
*/
public class Card {
/**
* String value that holds the suit of the card
*/
private String suit;
/**
* String value that holds the rank of the card
*/
private String rank;
/**
* int value that holds the point value.
*/
private int pointValue;
/**
* Creates a new <code>Card</code> instance.
*
* @param cardRank a <code>String</code> value
* containing the rank of the card
* @param cardSuit a <code>String</code> value
* containing the suit of the card
* @param cardPointValue an <code>int</code> value
* containing the point value of the card
*/
public Card(String cardRank, String cardSuit, int cardPointValue) {
//initializes a new Card with the given rank, suit, and point value
rank = cardRank;
suit = cardSuit;
pointValue = cardPointValue;
}
/**
* Accesses this <code>Card's</code> suit.
* @return this <code>Card's</code> suit.
*/
public String suit() {
return suit;
}
/**
* Accesses this <code>Card's</code> rank.
* @return this <code>Card's</code> rank.
*/
public String rank() {
return rank;
}
/**
* Accesses this <code>Card's</code> point value.
* @return this <code>Card's</code> point value.
*/
public int pointValue() {
return pointValue;
}
/** Compare this card with the argument.
* @param otherCard the other card to compare to this
* @return true if the rank, suit, and point value of this card
* are equal to those of the argument;
* false otherwise.
*/
public boolean matches(Card otherCard) {
return otherCard.suit().equals(this.suit())
&& otherCard.rank().equals(this.rank())
&& otherCard.pointValue() == this.pointValue();
}
/**
* Converts the rank, suit, and point value into a string in the format
* "[Rank] of [Suit] (point value = [PointValue])".
* This provides a useful way of printing the contents
* of a <code>Deck</code> in an easily readable format or performing
* other similar functions.
*
* @return a <code>String</code> containing the rank, suit,
* and point value of the card.
*/
@Override
public String toString() {
return rank + " of " + suit + " (point value = " + pointValue + ")";
}
}