Results 1 to 3 of 3
  1. #1
    boomba88 is offline Member
    Join Date
    Sep 2008
    Posts
    1
    Rep Power
    0

    Exclamation 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

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,900
    Rep Power
    25

    Default

    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.

  3. #3
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    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
    }
    }
    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.

Similar Threads

  1. Circular Double Linked List
    By theonly in forum Advanced Java
    Replies: 3
    Last Post: 12-06-2009, 06:10 PM
  2. Linked List help
    By neobie in forum New To Java
    Replies: 8
    Last Post: 12-22-2007, 04:15 AM
  3. going from vectors to linked list?
    By cbrown08 in forum New To Java
    Replies: 3
    Last Post: 12-01-2007, 01:55 AM
  4. Linked List
    By rnavarro9 in forum New To Java
    Replies: 0
    Last Post: 11-29-2007, 04:42 AM
  5. Help with linked list
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 08:29 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •