Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This class represents one playing card.
- public class Card
- {
- // Card suits (provided for your convenience - use is optional)
- public static final int SPADES = 0;
- public static final int HEARTS = 1;
- public static final int CLUBS = 2;
- public static final int DIAMONDS = 3;
- // Card faces (provided for your convenience - use is optional)
- public static final int ACE = 1;
- public static final int TWO = 2;
- public static final int THREE = 3;
- public static final int FOUR = 4;
- public static final int FIVE = 5;
- public static final int SIX = 6;
- public static final int SEVEN = 7;
- public static final int EIGHT = 8;
- public static final int NINE = 9;
- public static final int TEN = 10;
- public static final int JACK = 11;
- public static final int QUEEN = 12;
- public static final int KING = 13;
- // define fields here
- int suit;
- int face;
- // This constructor builds a card with the given suit and face, turned face down.
- public Card(int cardSuit, int cardFace)
- {
- suit = cardSuit;
- face = cardFace;
- }
- // This method retrieves the suit (spades, hearts, etc.) of this card.
- public int getSuit()
- {
- return suit;
- }
- // This method retrieves the face (ace through king) of this card.
- public int getFace()
- {
- return face;
- }
- // This method retrieves the numerical value of this card
- // (usually same as card face, except 1 for ace and 10 for jack/queen/king)
- public int getValue()
- {
- if (face <= 10)
- return face;
- else
- return 10;
- }
- public int getAltValue()
- {
- return face;
- }
- public String showCardSuit(){
- if(suit == 0){
- return "Spades";
- }else if(suit == 1){
- return "Hearts";
- }else if(suit == 2){
- return "Clubs";
- }else if(suit == 3){
- return "Diamonds";
- }else{
- return "Error";
- }
- }
- public String showCardValue(){
- if(face == 1){
- return "Ace";
- }else if(face == 2){
- return "Two";
- }else if(face == 3){
- return "Three";
- }else if(face == 4){
- return "Four";
- }else if(face == 5){
- return "Five";
- }else if(face == 6){
- return "Six";
- }else if(face == 7){
- return "Seven";
- }else if(face == 8){
- return "Eight";
- }else if(face == 9){
- return "Nine";
- }else if(face == 10){
- return "Ten";
- }else if(face == 11){
- return "Jack";
- }else if(face == 12){
- return "Queen";
- }else if(face == 13){
- return "King";
- }else{
- return "Error";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement