Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cards game, deitel exercise question!

 
Mona Alsh
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 10111
56
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mona Alsh
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12090
29
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic