Results 1 to 3 of 3
- 09-10-2008, 01:50 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 1
- Rep Power
- 0
creating a deck of cards using a linked list
public class Deck extends LinkedList <Card>
{private int cardPos = 0
public Deck()
{
for (int card = 1; card <= 13; card ++)
{ for ( Suit suit: Suit.values())
new Card(card, suit)
}}}
hi all im creating a deck of cards for a poker game and want to store it in a linked list, can someone please help me with storing them in the list and also shuffling and dealing the cards
tahnkyou
- 09-10-2008, 02:43 PM #2
Are you supposed to create the classes and methods for the assignment or can you use existing java classes?
If you can use existing classes, read the API doc for LinkedList and also lookup the method shuffle.
- 09-11-2008, 03:34 PM #3
Look, the parameter numHands is how much people are playing the card game,and parameter cardsPerHand indicates the amount the cards to deal to each player.Java Code:static void cardList(int numHands,int cardsPerHand){ List<String> deck,hand; //52-card deck Srting[] suit=new String[]{"S","H","D","C"}; String[] rank=new String[]{"A","2","3","4","5","6","7","8","9","10","J","Q","K"}; deck=new ArrayList<String>(); for(int i=0;i<deck.length;i++){ for(int j=i;j<deck.length;j++){ deck.add(rank[i]+"-"+suit[j]); } } Collections.shuffle(deck);//shuffles the heap of the crads //dealing the cards for(int i=0;i<numHands;i++){ hand=deck.subList(deck.size()-cardsPerHand,deck.size()); System.out.println(hand); //hand.clear();//removes the sub-list from the list } }
Similar Threads
-
Circular Double Linked List
By theonly in forum Advanced JavaReplies: 3Last Post: 12-06-2009, 05:10 PM -
Linked List help
By neobie in forum New To JavaReplies: 8Last Post: 12-22-2007, 03:15 AM -
going from vectors to linked list?
By cbrown08 in forum New To JavaReplies: 3Last Post: 12-01-2007, 12:55 AM -
Linked List
By rnavarro9 in forum New To JavaReplies: 0Last Post: 11-29-2007, 03:42 AM -
Help with linked list
By trill in forum New To JavaReplies: 1Last Post: 08-07-2007, 07:29 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks