0

My goal is to have the final output display the String for card suit and card rank, not its integer value. I know I am supposed to call the method that is holding the String values but how to do that is my headache. Any suggestions would be highly appreciated. Please note I am an absolute beginner to programming. Here is my code:

public class Card {

    private final int suit, rank;

    public static final int DIAMONDS = 1;
    public static final int HEARTS = 2;
    public static final int CLUBS = 3;
    public static final int SPADES = 4;

    public static final int ACES = 1;
    public static final int DEUCE = 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 JACKS = 11;
    public static final int QUEENS = 12;
    public static final int KINGS = 13 ;

    public Card (int rank, int suit)
    {
        this.rank = rank;
        this.suit = suit;
    }

    public int getSuit()
    {
        return suit;
    }

    public int getCard()
    {
        return rank;
    }
    public static boolean checkSuit(int suit)
    {
        return DIAMONDS<=suit && suit<=SPADES;
    }
    public static boolean cheakRank(int rank)
    {
        return ACES <= rank && rank <= KINGS;
    }

    public static String rankCard(int rank)
    {

        switch(rank)
        {
            case ACES:
                return "Ace";
            case DEUCE:
                return "Deuce";
            case THREE:
                return "Three";
            case FOUR:
                return "Four";
            case FIVE:
                return "Five";
            case SIX:
                return "Six";
            case SEVEN:
                return "Seven";
            case EIGHT:
                return "Eight";
            case NINE:
                return "Nine";
            case TEN:
                return "Ten";
            case JACKS:
                return "Jack";
            case QUEENS:
                return "Queen";
            case KINGS:
                return "King";
            default:
                return null;
        }
    }
    public static String suitCard(int suit)
    {
        switch(suit)
        {
            case DIAMONDS:
                return "Diamonds";
            case CLUBS:
                return "Clubs";
            case HEARTS:
                return "Hearts";
            case SPADES:
                return "Spades";
            default:
                return null;
        }

    }    
}

My main method is:

public class PokerClass {
    public static void main(String[]args)
    {
        Card pokerCard = new Card(1, 11);
        System.out.println("The card is: "+pokerCard.getSuit()+" and a: "+pokerCard.getCard());

    }
}
iehrlich
  • 3,572
  • 4
  • 34
  • 43
willieswanjala
  • 638
  • 6
  • 13
  • have you thought about making extra fields of type `String` called `suitName` and `rankName`? Or using a data structure such as a `Hashmap` that will let you join the name with the suit/rank in a single entry? There's a lot of ways to do this – Chris Gong Jun 29 '17 at 23:46
  • 1
    Have you thought about using an enum here? – Tim Biegeleisen Jun 29 '17 at 23:49
  • Your `suitCard()` and `rankCard()` convert the numbers (`int`) into human-readable strings. Try: `System.out.println("The card is: "+suitCard(pokerCard.getSuit())+" and a: "+rankCard(pokerCard.getCard()));` – Ian Jun 29 '17 at 23:52
  • you can make the cards an enum also: https://stackoverflow.com/questions/9554872/how-to-operate-the-poker-game-by-java/9608351#9608351 – Ray Tayek Jun 30 '17 at 01:06
  • Enum solved it. Thank you all. – willieswanjala Jun 30 '17 at 09:02

0 Answers0