title: Poker game: creating a deck with java
body: <p>I am working on a project to create a poker game. Even though the instructions are pretty clear, I am having so much trouble with object-oriented programming. </p>
  
  <p>So for this project, we have to create four objects, Card, Deck, Hand, and Poker Hand. I have already finished creating the card object and am now working on the deck object. That's the area I am having trouble right now. I have tried googling my problem. However, since I am such a newbie at programming, I don't really get their methods. For instance, I don't know how to use ArrayList. I only know very basic array methods. </p>
  
  <p>The following code is what I have done so far for the Deck object: </p>
  
  <pre><code>import java.util.*;
  
  public class Deck {
  
      public static final int CARDS_IN_DECK = 52;
      public static final int SHUFFLE_SWAPS = 700;
      int shufflex = 0;
  
      private Card[] cards;
      private int card_holder;
      private int seed;
  
      public Deck(int seed) {
          this.cards = new Card[CARDS_IN_DECK];
  
          seed = 0;
  
          for (int i = 2; i &lt;= 14; i++) {
              for (int j = 0; j &lt;= 3; j++) {
  
                  if (j == 0) {
                      cards[seed] = new Card(i, 'c'); // c = Clubs
  
                  } else if (j == 1) {
                      cards[seed] = new Card(i, 'd'); // d == Diamond
  
                  } else if (j == 2) {
                      cards[seed] = new Card(i, 's'); // s== Spade
  
                  } else if (j == 3) {
                      cards[seed] = new Card(i, 'h'); // h = Heart
                  }
                  seed++;
              }
          }
  
      }
  
      public void shuffle(){
          Random rand = new Random ();
          int randomNumber = rand.nextInt(51);
          int randomNumber2 = rand.nextInt(51);
  
          while( shufflex &lt; SHUFFLE_SWAPS ){
  
              HOW DO I DO THE SWAP HERE? DON'T KNOW THE SYNTAX
              I KNOW I NEED TO CREATE ANOTHER ARRAY TO TEMPORARY STORE THE FIRST CARD
              THEN I REPLACE THE FIRST CARD WITH THE SECOND CARD
              AND THEN REPLACE THE SECOND CARD WITH THE TEMPORARY CARD
  
              shufflex++;
          }
      }
  
      public Card nextCard() {
  
      }
  
      public String toString() {
  
      }
  }
  </code></pre>
  
  <p>And here are the descriptions for this part:</p>
  
  <p>The Deck class represents a deck of 52 playing cards. We will use an array of Card objects to manage the actual cards in the deck.</p>
  
  <p>The following are the class and instance fields, followed by the methods of the Deck class. Complete each item in the following order.</p>
  
  <p>Class Constants</p>
  
  <p>Declare and initialize the following public static class constants:
  CARDS_IN_DECK - An integer value to represent the number of cards in the deck. Set this equal to 52.
  SHUFFLE_SWAPS - An integer value to represent the number of times cards should switch positions during the shuffling of the deck. The higher the number, the more random and thoroughly shuffled the deck will be. Set this equal to at least 500.
  Instance Fields</p>
  
  <p>Declare the following instance fields:
  An array of Card objects that will be used to manage the CARDS_IN_DECK cards in the deck. Each element in the array is a single Card object.
  An integer that holds the index of the next card to be dealt from the array of Cards. As a side note, this variable will start at 0 and increase by 1 each time a card is dealt (see methods below).
  An integer variable that maintains the random seed provided for testing.
  Methods</p>
  
  <p>The following is the list of methods you must complete. </p>
  
  <p><code>public Deck(int seed)</code> - This is the constructor of the Deck class. You must first initalize your array of Card objects to hold 52 cards using your class constant "CARDS_IN_DECK." After your array is initialized, you must go through the array one element at a time and actually create a Card object. All cards must be created (values 2-14 for each of the four suits), and there must not be any duplicates. The seed parameter should be stored in the instance field for the seed.
  HINT: Use Card.CLUBS, Card.LOWEST_VALUE, etc., in this constructor.</p>
  
  <p><code>public void shuffle()</code> - This method handles resetting the deck for a new hand to be played. This method must handle shuffling the deck by using the Random class to generate random numbers. You must randomly generate two integers between 0-51. Then, you must swap the cards at those two positions. For example, if the random numbers are 20 and 11, and the 2 of Clubs is in element 20 of the array and the 3 of Hearts is in element 11 of the array, after these two cards are swapped element 20 will hold the 3 of Hearts, and element 11 will hold the 2 of Clubs. You must repeat this process of generating two numbers and swapping the cards in the corresponding locations for as many times as the class constant "SHUFFLE_SWAPS" indicates that you should. If the random seed is not -1, the Random object you create should use the provided random seed. This will ensure that the deck will be shuffled the same way every time you run the program with the same random seed. For example,</p>
  
  <p><code>Random rand = new Random(seed);</code>
  If the random seed is -1, create a Random object with no seed, which will create a different game every time you play. For example,</p>
  
  <p><code>Random rand = new Random();</code>
  Finally, the index used for selecting the next card to be dealt from the deck must be reset to 0. </p>
  
  <p><code>public Card nextCard()</code> - This method returns the next card in the deck based on the instance field that knows the position within the array where the next card to be dealt is located. Before returning the card, make sure you update this number so that the next time the method is called, the next card in the deck will be returned (increase it by 1).</p>
  
  <p><code>public String toString()</code> - This method returns a String representation of the Deck which will come in handy for Unit Testing. HINT: call the toString() method of the Card class for each Card in the array of Card objects.</p>
  
  <hr>
  
  <p>I think I got <code>public Deck (int seed)</code> method right. Can you take a look at that? The card object has parameter of ( int value, char suit), so for deck, I am returning ( int, char). After this method, I am not really sure how to go from there. Can somebody please give me some pointers on this?</p>