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
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: 893

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.

Understanding the scope of the problem is the first step on the path to true panic
I agree. Here's the link:
subject: cards game
It's not a secret anymore!