-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCard.java
65 lines (59 loc) · 1.83 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
/*
* The purpose of this class is set up the properties of Card objects.
* Namely their suit, rank and point value of each Card object.
* Also storing the comparison and convert to String method.
* Created by AP Developers
* Modified by Yolanda Yu
* Last modified on 05/31/2017
*/
public class Card
{
// fields
private String suit; // suit of the card
private String rank; // rank of the card
private int pointValue; // point value of the card
// Constructor of the class that takes two string values of the card's rank
// and suit, then one int value containing the card's point value
public Card(String cardRank, String cardSuit, int cardPointValue)
{
rank = cardRank;
suit = cardSuit;
pointValue = cardPointValue;
}
// Get and return the card's suit
public String suit()
{
return suit;
}
// Get and return the card's rank
public String rank()
{
return rank;
}
// Get and return the card's point value
public int pointValue()
{
return pointValue;
}
// This method is used to compare two card values to test for equality. In
// order for them to be equal, the two card's rank, suit and point value must
// all be equal. Otherwise return false.
public boolean matches(Card otherCard)
{
if (rank.equals(otherCard.rank) && suit.equals(otherCard.suit) && pointValue == otherCard.pointValue)
{
return true;
}
else
return false;
}
// the @override annotation means that the method original method "toString" in
// the Object's class is being overrided in this Card class
@Override
// Output all information concerning the card in a string format to make it
// easier to read
public String toString()
{
return rank + " of " + suit + " (point value = " + pointValue + ")";
}
}