This is the Card.java code for the video poker game
Fri Dec 13 2024 06:13:04 GMT+0000 (Coordinated Universal Time)
Saved by
@Sasere
// Banner: Card class for representing individual cards in a deck.
import java.util.*;
public class Card implements Comparable<Card> {
private int suit; // Encodes suit (1-4: Clubs, Diamonds, Spades, Hearts)
private int rank; // Encodes rank (1-13: Ace through King)
public Card(int s, int r) {
this.suit = s;
this.rank = r;
}
public int getSuit() {
return suit;
}
public int getRank() {
return rank;
}
@Override
public int compareTo(Card c) {
if (this.rank == c.rank) {
return this.suit - c.suit;
}
return this.rank - c.rank;
}
@Override
public String toString() {
String[] suits = { "Clubs", "Diamonds", "Spades", "Hearts" };
String[] ranks = { "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King" };
return ranks[this.rank - 1] + " of " + suits[this.suit - 1];
}
}
content_copyCOPY
Comments