-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCard.java
34 lines (28 loc) · 804 Bytes
/
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
import java.util.Objects;
public class Card {
private final Suit suit;
private final Rank rank;
public Card(Suit suit, Rank rank) {
this.suit = suit;
this.rank = rank;
}
public Rank getRank() { return rank; }
public Suit getSuit() { return suit; }
public int getValue() { return rank.getValue(); }
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Card card = (Card) o;
return suit == card.suit &&
rank == card.rank;
}
@Override
public int hashCode() {
return Objects.hash(suit, rank);
}
@Override
public String toString() {
return rank.getSymbol() + suit.getSymbol();
}
}