Advertisement
mmayoub

Solitaire, Card

Jul 30th, 2018
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. public class Card {
  2.     // type of the cards
  3.     public static final String CARD_TYPE = "CDHS";
  4.     // color of card type
  5.     public static final String[] CARD_COLOR = { "Black", "Red", "Red", "Black" };
  6.     // values to as printed
  7.     public static final String[] CARD_VALUE = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
  8.  
  9.     private char type; // type of the card
  10.     private int value; // value of the card
  11.  
  12.     // create a new card
  13.     public Card(char type, int value) {
  14.         // no need to check parameters
  15.         this.type = type;
  16.         this.value = value;
  17.     }
  18.  
  19.     // get card type
  20.     public char getType() {
  21.         return type;
  22.     }
  23.  
  24.     // get card value
  25.     public int getValue() {
  26.         return value;
  27.     }
  28.  
  29.     // get color card
  30.     public String getColor() {
  31.         int index = CARD_TYPE.indexOf(this.type);
  32.         return CARD_COLOR[index];
  33.     }
  34.  
  35.     @Override
  36.     public String toString() {
  37.         return String.format("(%c%2s)", type, CARD_VALUE[this.value - 1]);
  38.     }
  39.  
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement