Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-10-2008, 03:50 PM
Member
 
Join Date: Sep 2008
Posts: 1
boomba88 is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-10-2008, 04:43 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 09-11-2008, 05:34 PM
serjant's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Ukraine,Zaporozhye
Posts: 320
serjant is on a distinguished road
Send a message via ICQ to serjant Send a message via Skype™ to serjant
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Circular Double Linked List theonly Advanced Java 1 04-04-2008 09:18 AM
Linked List help neobie New To Java 8 12-22-2007 05:15 AM
going from vectors to linked list? cbrown08 New To Java 3 12-01-2007 02:55 AM
Linked List rnavarro9 New To Java 0 11-29-2007 05:42 AM
Help with linked list trill New To Java 1 08-07-2007 09:29 AM


All times are GMT +3. The time now is 08:01 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org