title: Java class card enum example. REVISED
body: <p>*Any help is much appreciated *</p>
  
  <p>I am using the class card example from java website to try to build a game.</p>
  
  <p><a href="http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html" rel="nofollow noreferrer">http://java.sun.com/j2se/1.5.0/docs/guide/language/enums.html</a></p>
  
  <p>I want to assign the suits and ranks values. I am not sure how to do that..</p>
  
  <p>For suit, What i want to do is assign Heart = 4
  diamond = 3, club =2, spade = 1</p>
  
  <p>for rank, ace = 11
  jack,queen,king = 10<br>
  2-10 the value of the card..</p>
  
  <p>the program accepts user input as arguments for number of hands and number of cards per hand..
  like this: $ java Deal 4 5</p>
  
  <p>so then I want it to print Eight of spades(8), ten of hearts(40)</p>
  
  <p>based off from the values.. example spade = 1 *  8
  hearts = 4 * 10</p>
  
  <p>I can get it to print the hand just not the values...</p>
  
  <p>Example of my 
  Current output scaled down:</p>
  
  <pre><code>FIVE of CLUBS(0),
  DEUCE of SPADES(0),
  SEVEN of SPADES(0),
  TEN of SPADES(0),
  THREE of HEARTS(0),
  FOUR of SPADES(0),
  THREE of DIAMONDS(0),
  [TEN of SPADES, THREE of HEARTS, FOUR of SPADES, THREE of DIAMONDS]
  [FOUR of CLUBS, FIVE of CLUBS, DEUCE of SPADES, SEVEN of SPADES]
  [QUEEN of HEARTS, SIX of HEARTS, FOUR of HEARTS, KING of DIAMONDS]
  
  C:\Java\a02&gt;
  </code></pre>
  
  <p>Here is the code for the program in two different classes</p>
  
  <pre><code>import java.util.*;
  
  public class Cards {
  
      public enum Rank {
          DEUCE(2), THREE(3), FOUR(4), FIVE(5), SIX(6), SEVEN(7), EIGHT(8), NINE(
                  9), TEN(10), JACK(10), QUEEN(10), KING(10), ACE(11);
  
          private int Rankpoints;
  
          Rank(int points) {
              this.Rankpoints = points;
          }
  
          public int getRankpoints() {
              return this.Rankpoints;
          }
  
      }
  
      public enum Suit {
          CLUBS(2), DIAMONDS(3), HEARTS(4), SPADES(1);
  
          private int Suitpoints;
  
          Suit(int points) {
  
              this.Suitpoints = points;
  
          }
  
          public int getSuitpoints() {
              return this.Suitpoints;
          }
  
      }
  
      private final Rank rank;
      private final Suit suit;
  
      private Cards(Rank rank, Suit suit) {
          this.rank = rank;
          this.suit = suit;
      }
  
      public Rank rank() {
          return this.rank;
      }
  
      public Suit suit() {
  
          return this.suit;
  
      }
  
      public String toString() {
          return rank + " of " + suit;
      }
  
      private static final List&lt;Cards&gt; protoDeck = new ArrayList&lt;Cards&gt;();
  
      // Initialize prototype deck
      static {
          for (Suit suit : Suit.values())
              for (Rank rank : Rank.values())
                  protoDeck.add(new Cards(rank, suit));
  
      }
  
      public static ArrayList&lt;Cards&gt; newDeck() {
  
          return new ArrayList&lt;Cards&gt;(protoDeck); // Return copy of prototype deck
      }
  
  }
  </code></pre>
  
  <p>and here is the main</p>
  
  <pre><code>import java.util.*;
  
  public class Deal {
      public static void main(String args[]) {
          int numHands = Integer.parseInt(args[0]);
          int cardsPerHand = Integer.parseInt(args[1]);
          List&lt;Cards&gt; deck = Cards.newDeck();
          Collections.shuffle(deck);
  
          for (Cards card : deck) {
              System.out.println(card.rank() + " of " + card.suit() + "("
                      + card.getSuitpoints() + ")" + ",");
  
          }
  
          for (int i = 0; i &lt; numHands; i++)
              System.out.println(deal(deck, cardsPerHand));
      }
  
      public static ArrayList&lt;Cards&gt; deal(List&lt;Cards&gt; deck, int n) {
          int deckSize = deck.size();
          List&lt;Cards&gt; handView = deck.subList(deckSize - n, deckSize);
          ArrayList&lt;Cards&gt; hand = new ArrayList&lt;Cards&gt;(handView);
          handView.clear();
          return hand;
      }
  }
  </code></pre>
  
  <p>when i try to compile i get an error..
  for </p>
  
  <p>card.getSuitpoints()</p>
  
  <p>error: cannot find symbol: method getSuitpoints()</p>
  
  <p>i find that odd because </p>
  
  <p>card.getRankpoints()
  compiles..
  is it the way i am putting it into the enum?</p>
  
  <p>getRankpoints()
  returns zero.
  whats wrong?</p>