This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 7549
    
  18

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: 11161
    
  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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Cards game, deitel exercise question!
 
Similar Threads
Selection Sort?
illegal start of expression
variable returns "null" value in output
can't split card shuffle method into a separate class
Deck of cards