aspose file tools*
The moose likes Beginning Java and the fly likes Cards game, deitel exercise question! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Cards game, deitel exercise question! " Watch "Cards game, deitel exercise question! " New topic
Author

Cards game, deitel exercise question!

Mona Alsh
Ranch Hand

Joined: Dec 20, 2012
Posts: 32
Hi There,
How are you?
I'm trying to solve Deitel and Deitel exercise 7.30 of chapter 7. I want to modify the example so that it can deal 5 cards instead of one . I cerate an array of 5 cards to be saved in the ArrayList of Card[] arrays.
I used the loop to iterate 52 times and each time it should save every 5 cards in the hand[] array and add the array to the ArrayList handList.
am I using correct logic because it keeps giving me ArrayOutOfBoundException error!



Thanks in advance
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8206
    
  23

Mona Alsh wrote:am I using correct logic because it keeps giving me ArrayOutOfBoundException error!

Then you've answered your own question: plainly, you're not.

Q: What is the index of the first element in a Java array?

If you still can't work it out, I'd suggest looking at the Java tutorials.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Mona Alsh
Ranch Hand

Joined: Dec 20, 2012
Posts: 32
I know it is zero , but even if it is for( int i=0; i< 52;i++)
it is giving me the same errors!!
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11476
    
  16

Stick a System.out.println() statement in your loop as the first line. Have it print your index.

Stick in another as the LAST line of your loop, and have it do the same thing.

Look and see what the index really is. If that doesn't help, stick in another just before the line that is throwing the exception. Clearly, the index is not what you think (or the array isn't).


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
jQuery in Action, 2nd edition
 
subject: Cards game, deitel exercise question!