I have been trying to create a deck of cards using this code:
public DeckOfCards()
{
//constructor fills deck of Cards
String faces[] = { "Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve" };
String suits[] = { "Hearts", "Diamonds", "Clubs", "Spades" };
deck = new Cards[ NUMBER_OF_CARDS ];
currentCard = 0;
randomNumbers = new Random();
//populate deck with Card objects
for( int count = 0; count < deck.length; count++ )
deck[ count ] =
new Cards( faces[ count % 13 ], suits[ count / 13 ] );
} //end DeckOfCard constructor
Yet, there is one error that I just cannot fix. It pops out like this: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException at:
for( int count = 0; count < deck.length; count++ )
deck[ count ] =
new Cards( faces[ count % 13 ], suits[ count / 13 ] );
Why does this error keep showing up? Any help will be greatly appreciated.
facesarray. And why are you naming Eleven instead of Jack?