Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Deck of cards

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    3
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Deck of cards

    I'm really new to this guys so go easy on me, I'm making a card dealing simulation and want to know a way of assigning numeric values to my cards "ranks", which are currently string types, here's what I have so far;


    import java.util.Scanner;
    import java.util.Random;

    class card_deck{
    public static void main(String args[]){

    Scanner in = new Scanner(System.in);

    String[] suit = {"Spades", "Hearts", "Clubs", "Diamonds"};
    Random random = new Random();

    int selectS = random.nextInt(suit.length);

    String[] rank = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"};

    int selectR = random.nextInt(rank.length);

    System.out.println(rank[selectR] + " of " + suit[selectS]);
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,077
    Thanks
    47
    Thanked 2,147 Times in 2,120 Posts

    Default Re: Deck of cards

    a way of assigning numeric values to my cards
    One way would be to use the value of the index required to access the element in the array.
    rank[2] = "3" would give "3" the value 2
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    gavinqotsa92 (November 27th, 2013)

  4. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    1
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Deck of cards

    Hey. You could try and use a enum. Here's what I would try and do;
    Instead of posting code I saw this thread on spoonfeeding and decided not to spoonfeed.

  5. The Following User Says Thank You to gregory.bmclub For This Useful Post:

    gavinqotsa92 (November 27th, 2013)

Similar Threads

  1. [SOLVED] Shuffling a deck of cards
    By aterrorbite in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 5th, 2013, 07:44 PM
  2. Please help with unwrap, deck, shuffle cards
    By pots in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 6th, 2013, 11:46 AM
  3. Need help with Deck of Cards
    By yanksin1st in forum Java Theory & Questions
    Replies: 1
    Last Post: March 1st, 2012, 12:28 PM
  4. A deck of cards
    By glebovg in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 1st, 2012, 08:46 AM
  5. Adding cards back into deck
    By sp4ce in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 15th, 2011, 12:21 AM

Tags for this Thread