Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to print Enums to resemble a deck of cards but can't print object just description
    text
    copied!<p>I'm trying to make a deck of cards using enums for the suit and card values. I'm trying to print off the lists of enums but I only get their numerical value and not the objects name. I have watched the video on newboston over 9 thousand times and can't seem to get this figured out. </p> <p>This is my printout when I run the program</p> <blockquote> <p>123456789101112131 2 3 4</p> </blockquote> <p>My overall goal is to put these enums into an arraylist where I can deal them out the players. When I print these statements shouldn't it tell me (Ace, King, Queen....ect)?</p> <p>PRINT STATEMENTS</p> <pre><code>for(CardValue card : CardValue.values()) {//Enhanced for loop System.out.printf("%s",card);//I tried using different styles of print to see if it would change anything } for(Suit card : Suit.values()) {//Enhanced for loop System.out.println(card.toString()); } </code></pre> <p>ENUM CLASS CardValue</p> <pre><code> public enum CardValue { ACE(1), TWO(2), THREE(3), FOUR(4), FIVE(5), SIX(6), SEVEN(7), EIGHT(8), NINE(9), TEN(10), JACK(11), QUEEN(12), KING(13); private final int cardValue; private CardValue (int value) { this.cardValue = value; } public int getCardValue() { return cardValue; } public String toString(){ return String.format("%s", cardValue); } } </code></pre> <p>Enum Class Suit</p> <pre><code>public enum Suit { HEARTS(1), SPADES(2), CLUBS(3), DIAMONDS(4); private final int suit; private Suit (int value) { this.suit = value; } public int getCardSuit() { return suit; } public String toString(){ return String.format("%s", suit); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload