How to convert the integer value to a string but with different contents

advertisements

Sorry if the question is confusing, but I am making a small blackjack program to test my skills in java thus far, and I've come to a problem that I cannot think of a way out of.

Currently, I have a Card class that create the cards for the game, and I have the random number generator set up to go between integer values 1-14. However, how can I write a method that will take that integer value, and get it to output that if the integer value of 11, a string value will show this card as a jack, and not a 11 card, etc.

Here is all I have at the moment, unfortunately.

private void assignCard(){
        for(int i = 0; i < cardInHand.length; i++){
            if(cardInHand[i] >= 11){

            }
        }
    }

The point of the method I have here is to run through the contents of the cards in the players hand, and check to see if they're above 11, and as such would then begin the process of sorting out which number corresponds to the the proper card type (jack, queen, etc) in a string value printed to the user.

In saying all this, I am still only a beginner at programming, so there is a chance that this project may be out of my skill level, but any sort of relevant suggestions/criticism are greatly appreciated.


Keep the "names" of the cards in a String array like

    int cardNum = 11;
    String [] cards = new String [] {"ace", "two", "three", ..., "jack", "queen", "king"};

    System.out.println(cards[11 - 1]);

As solution like this allows you to internationalize the card names later