Advertisement
Guest User

Card.java

a guest
Nov 18th, 2012
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.48 KB | None | 0 0
  1. // This class represents one playing card.
  2. public class Card
  3. {
  4.     // Card suits (provided for your convenience - use is optional)
  5.     public static final int SPADES   = 0;
  6.     public static final int HEARTS   = 1;
  7.     public static final int CLUBS    = 2;
  8.     public static final int DIAMONDS = 3;
  9.  
  10.     // Card faces (provided for your convenience - use is optional)
  11.     public static final int ACE      = 1;
  12.     public static final int TWO      = 2;
  13.     public static final int THREE    = 3;
  14.     public static final int FOUR     = 4;
  15.     public static final int FIVE     = 5;
  16.     public static final int SIX      = 6;
  17.     public static final int SEVEN    = 7;
  18.     public static final int EIGHT    = 8;
  19.     public static final int NINE     = 9;
  20.     public static final int TEN      = 10;
  21.     public static final int JACK     = 11;
  22.     public static final int QUEEN    = 12;
  23.     public static final int KING     = 13;
  24.  
  25.  
  26.     // define fields here
  27.     int suit;
  28.     int face;
  29.    
  30.     // This constructor builds a card with the given suit and face, turned face down.
  31.     public Card(int cardSuit, int cardFace)
  32.     {
  33.         suit = cardSuit;
  34.         face = cardFace;
  35.     }
  36.  
  37.     // This method retrieves the suit (spades, hearts, etc.) of this card.
  38.     public int getSuit()
  39.     {
  40.         return suit;
  41.     }
  42.    
  43.     // This method retrieves the face (ace through king) of this card.
  44.     public int getFace()
  45.     {
  46.         return face;
  47.     }
  48.    
  49.     // This method retrieves the numerical value of this card
  50.     // (usually same as card face, except 1 for ace and 10 for jack/queen/king)
  51.     public int getValue()
  52.     {
  53.         if (face <= 10)
  54.             return face;
  55.         else
  56.             return 10;
  57.     }
  58.  
  59.     public int getAltValue()
  60.     {
  61.  
  62.             return face;
  63.  
  64.     }
  65.    
  66.    
  67.     public String showCardSuit(){
  68.         if(suit == 0){
  69.             return "Spades";
  70.         }else if(suit == 1){
  71.             return "Hearts";
  72.         }else if(suit == 2){
  73.             return "Clubs";
  74.         }else if(suit == 3){
  75.             return "Diamonds";
  76.         }else{
  77.             return "Error";
  78.         }
  79.        
  80.     }
  81.    
  82.     public String showCardValue(){
  83.         if(face == 1){
  84.             return "Ace";
  85.         }else if(face == 2){
  86.             return "Two";
  87.         }else if(face == 3){
  88.             return "Three";
  89.         }else if(face == 4){
  90.             return "Four";
  91.         }else if(face == 5){
  92.             return "Five";
  93.         }else if(face == 6){
  94.             return "Six";
  95.         }else if(face == 7){
  96.             return "Seven";
  97.         }else if(face == 8){
  98.             return "Eight";
  99.         }else if(face == 9){
  100.             return "Nine";
  101.         }else if(face == 10){
  102.             return "Ten";
  103.         }else if(face == 11){
  104.             return "Jack";
  105.         }else if(face == 12){
  106.             return "Queen";
  107.         }else if(face == 13){
  108.             return "King";
  109.         }else{
  110.             return "Error";
  111.         }
  112.     }
  113.    
  114.    
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement