Results 1 to 4 of 4

Thread: Card

  1. #1
    hedonist is offline Member
    Join Date
    Jun 2009
    Posts
    35
    Rep Power
    0

    Default Card

    I have to simulate shuffling and dealing of card(any card game).
    What i have done is created, enum types of Suit and Rank in a class called Card and the constructor
    public Card(Suit suit, Rank rank)
    {
    if(suit ==null || rank ==null)
    throw new NullPointerException(rank+" , "+suit);
    this.suit = suit;
    this.rank = rank;

    }
    i think i have to use an arrayList to put a rank and its corresponding suit, thus shuffling it but can't figure out how.
    Any help would be highly appreciated!!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Create a Deck class that holds an ArrayList<Card>. In the Deck class have a shuffle() method that shuffles the arraylist via Collections.shuffle(...). If you search this forum or the Sun fora you'll find many examples of this as it is an assignment that has been given to students for years. Best of luck.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  4. #4
    hedonist is offline Member
    Join Date
    Jun 2009
    Posts
    35
    Rep Power
    0

Similar Threads

  1. Can we access sim card from computer
    By rajasekharpv in forum Sun Java Wireless Toolkit
    Replies: 3
    Last Post: 09-03-2009, 03:22 PM
  2. card game Rummy
    By javafox in forum New To Java
    Replies: 4
    Last Post: 03-14-2009, 03:53 PM
  3. Card Layout
    By Gilbee in forum NetBeans
    Replies: 3
    Last Post: 03-03-2009, 09:37 PM
  4. A Online Card Game
    By GonzaloP in forum Networking
    Replies: 0
    Last Post: 12-28-2008, 06:37 PM
  5. Card program , need help thanks.
    By carlos123 in forum New To Java
    Replies: 2
    Last Post: 12-31-2007, 07:23 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
  •