-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCard.java
More file actions
37 lines (33 loc) · 853 Bytes
/
Card.java
File metadata and controls
37 lines (33 loc) · 853 Bytes
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
public class Card implements Comparable<Card>{
//the Suits the cards can be
public static enum Suits {Spades, Clubs, Diamonds, Hearts}
//the Ranks the cards can be
public static enum Ranks {Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace}
private Suits suit;
private Ranks rank;
//card initilizer
public Card(Suits s, Ranks r)
{
suit = s;
rank = r;
}
// Equals is only true if both the suit and the rank of the cards match
public boolean equals(Object rhs)
{
Card rside = (Card) rhs;
if (suit == rside.suit && rank == rside.rank)
return true;
else
return false;
}
// returns the card into a string represntation
public String toString()
{
return (rank + "-of-" + suit);
}
// Compare one Card to another Card
public int compareTo(Card rhs)
{
return rank.compareTo(rhs.rank);
}
}