This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori 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 OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 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: 780

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.

When I was your age I was toggling in the bootstrap code on the front panel
I agree. Here's the link:
subject: cards game
It's not a secret anymore!