Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Card {
- // type of the cards
- public static final String CARD_TYPE = "CDHS";
- // color of card type
- public static final String[] CARD_COLOR = { "Black", "Red", "Red", "Black" };
- // values to as printed
- public static final String[] CARD_VALUE = { "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
- private char type; // type of the card
- private int value; // value of the card
- // create a new card
- public Card(char type, int value) {
- // no need to check parameters
- this.type = type;
- this.value = value;
- }
- // get card type
- public char getType() {
- return type;
- }
- // get card value
- public int getValue() {
- return value;
- }
- // get color card
- public String getColor() {
- int index = CARD_TYPE.indexOf(this.type);
- return CARD_COLOR[index];
- }
- @Override
- public String toString() {
- return String.format("(%c%2s)", type, CARD_VALUE[this.value - 1]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement