File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Android Security Essentials Live Lessons this week in the Android 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: 174

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.
I agree. Here's the link:
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.