aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "cards game" Watch "cards game" New topic
Author

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




DeckOfCardsClass



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

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: cards game