Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

2 Dimensional Java Array issue, Cards problem

807601Jun 28 2008 — edited Jun 28 2008
Ok, below is my code, and below that is my error message. I've been running at this all morning and most of the afternoon. I've googled my heart out, and I'm stuck.

I'd appreciate a bit of help in getting past this, I'm aware that it's a newbie mistake and that tends to apply the newbie tag to me for a while longer.

Essentially, I'm attempting to populate the deck of cards. My compile error is hitting right in the populate section, and shutting me down. I'm wondering if I should simply set this up as an array of ints, and then just correlate the values to a name or if it's even possible to do a 2d string array.

And while I can appreciate that some of you know a great deal more about this than I do, I could honestly do without being trolled.
import java.util.*;


public class DeckOfCards
{
   private int cardsleft;
   private Card deck[]; // array of Card objects
   private int currentCard; // index of next Card to be dealt
   Random randomNumbers; // random number generator

// constructor fills deck of Cards
   public DeckOfCards()
   {
      String faces[] = { "Ace", "Deuce", "Three", "Four", "Five", "Six",
            "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" };
      String suits[] = { "Hearts", "Diamonds", "Clubs", "Spades" };
      
      deck = new Card[ 52 ]; // create array of Card objects
      currentCard = 0; // set currentCard so first Card dealt is deck[ 0 ]
      randomNumbers = new Random(); // create random number generator

// populate deck with Card objects
      for (int i = 0; i <deck>
           deck[i] = new Card(faces[i % 13], suits[i / 13]);
   } // end DeckOfCards constructor

// shuffle deck of Cards with one-pass algorithm
   public void shuffle()
   {
   // after shuffling, dealing should start at deck[0] again
      currentCard = 0; // reinitialize currentCard
   // for each Card, pick another random Card and swap them
      for (int i = 0;i < deck.length;i++)
      {
         int x =  randomNumbers.nextInt(52);// select a random number between 0 and 51
         Card temp = deck; // swap current Card with randomly selected Card 
deck[i] = deck[x];
deck[x] = temp;
} // end for
} // end method shuffle

// deal one Card
public Card dealCard()
{
if (currentCard <deck> 0)
{
Integer cardCountWrapper = new Integer(cardCount);
System.out.println("Card " + cardCountWrapper.toString());

Card dealtCard = deck.dealCard();
System.out.println(dealtCard.toString());

cardCount++;
}
} // method dealCard

// returns number of Cards left
public int cardsLeft()
{
return cardsleft;
}//end method cardsLeft


} // end class DeckOfCards
Error Message:
DeckOfCards.java:25: cannot find symbol
symbol : constructor Card(java.lang.String,java.lang.String)
location: class Card
deck[i] = new Card(faces[i % 13], suits[i / 13]);
^
1 error
Edited by: Onker on Jun 28, 2008 3:01 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 26 2008
Added on Jun 28 2008
7 comments
348 views