title: Java code for dealing cards from a deck
body: <p>I am trying to write a method to remove the specified number of cards from the top of the deck and return them as an array.</p>
  
  <p>This is what i have done so far. A method to create the deck, copy the deck, a method to return the card that is at the specified position in the array, a method to returns the size of the array of Cards, shuffle, and cut the deck (not sure if these are correct). Here is the card class</p>
  
  <pre><code>public class Card {
  
      private final int suit; // 0, 1, 2, 3 represent Spades, Hearts, Clubs,
                              // Diamonds, respectively
  
      private final int value; // 1 through 13 (1 is Ace, 11 is jack, 12 is
                                  // queen, 13 is king)
  
      /*
       * Strings for use in toString method and also for identifying card images
       */
      private final static String[] suitNames = { "s", "h", "c", "d" };
      private final static String[] valueNames = { "Unused", "A", "2", "3", "4",
              "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
  
      /**
       * Standard constructor.
       * 
       * @param value
       *            1 through 13; 1 represents Ace, 2 through 10 for numerical
       *            cards, 11 is Jack, 12 is Queen, 13 is King
       * @param suit
       *            0 through 3; represents Spades, Hearts, Clubs, or Diamonds
       */
      public Card(int value, int suit) {
          if (value &lt; 1 || value &gt; 13) {
              throw new RuntimeException("Illegal card value attempted.  The "
                      + "acceptable range is 1 to 13.  You tried " + value);
          }
          if (suit &lt; 0 || suit &gt; 3) {
              throw new RuntimeException("Illegal suit attempted.  The  "
                      + "acceptable range is 0 to 3.  You tried " + suit);
          }
          this.suit = suit;
          this.value = value;
      }
  
      /**
       * "Getter" for value of Card.
       * 
       * @return value of card (1-13; 1 for Ace, 2-10 for numerical cards, 11 for
       *         Jack, 12 for Queen, 13 for King)
       */
      public int getValue() {
          return value;
      }
  
      /**
       * "Getter" for suit of Card.
       * 
       * @return suit of card (0-3; 0 for Spades, 1 for Hearts, 2 for Clubs, 3 for
       *         Diamonds)
       */
      public int getSuit() {
          return suit;
      }
  
      /**
       * Returns the name of the card as a String. For example, the 2 of hearts
       * would be "2 of h", and the Jack of Spades would be "J of s".
       * 
       * @return string that looks like: value "of" suit
       */
      public String toString() {
          return valueNames[value] + " of " + suitNames[suit];
      }
  
      /**
       * [STUDENTS SHOULD NOT BE CALLING THIS METHOD!] Used for finding the image
       * corresponding to this Card.
       * 
       * @return path of image file corresponding to this Card.
       */
      public String getImageFileName() {
  
          String retValue;
          retValue = suitNames[suit];
          if (value &lt;= 10)
              retValue += value;
          else if (value == 11)
              retValue += "j";
          else if (value == 12)
              retValue += "q";
          else if (value == 13)
              retValue += "k";
          else
              retValue += "Unknown!";
          return "images/" + retValue + ".gif";
      }
  }
  </code></pre>
  
  <p>The Deck method is the one that I need help on</p>
  
  <pre><code>public class Deck {
  
      private Card[] cards;
  
      public Deck() {
          cards = new Card[52];
          int numberOfCard = 0;
          for (int suit = 0; suit &lt;= 3; suit++) {
              for (int value = 1; value &lt;= 13; value++) {
                  cards[numberOfCard] = new Card(value, suit);
                  numberOfCard++;
              }
          }
      }
  
      public Deck(Deck other) {
  
          cards = new Card[other.cards.length];
          for (int i = 0; i &lt; other.cards.length; i++) {
              cards[i] = other.cards[i];
          }
      }
  
      public Card getCardAt(int position) {
          if (position &gt;= cards.length) {
              throw new IndexOutOfBoundsException("Values are out of bounds");
          } else {
              return cards[position];
          }
      }
  
      public int getNumCards() {
          return cards.length;
      }
  
      public void shuffle() {
          int temp = 0;
          for (int row = 0; row &lt; cards.length; row++) {
              int random = (int) (Math.random() * ((cards.length - row) + 1));
              Deck.this.cards[temp] = this.getCardAt(row);
              cards[row] = cards[random];
              cards[random] = cards[temp];
          }
  
      }
  
      public void cut(int position) {
          Deck tempDeck = new Deck();
          int cutNum = tempDeck.getNumCards() / 2;
          for (int i = 0; i &lt; cutNum; i++) {
              tempDeck.cards[i] = this.cards[52 - cutNum + i];
          }
          for (int j = 0; j &lt; 52 - cutNum; j++) {
              tempDeck.cards[j + cutNum] = this.cards[j];
          }
          this.cards = tempDeck.cards;
      }
  
      public Card[] deal(int numCards) {
          return cards;
      }
  
  }
  </code></pre>