This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes cards game Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "cards game" Watch "cards game" New topic

cards game

Mona Alsh
Ranch Hand

Joined: Dec 20, 2012
Posts: 32
Hi There ,,
I'm trying to solve one of the cards exercise questions using arrays and linkedList.
The question goes like this. modify the program to deal five- cards poker hand.
I'm try to store every 5 cards in an array and then add this array to the ArrayList.
when I print the list to check if it is correctly storing every 5 elements. I found that it just repeating
the same five cards from every ArrayList element

Card Class


DeckOfCardsTest class

I'm concerned with the last class in which I should make the 5 cards in every ArrayList element!!
Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 173

You need to add a *new* hand array each time to the ArrayList. As it is you keep adding a reference to the same hand array each time.
subject: cards game
Similar Threads
Exception in thread "AWT-EventQueue-0" java.lang.OutOfMemoryError: Java heap space
variable returns "null" value in output
can't split card shuffle method into a separate class
Help With 5 card stud program
Problems overwriting toString() method.