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 4 of 4

Thread: Two-dimensional Array representing playing cards

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    29
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Two-dimensional Array representing playing cards

    My two-dimensional array is:
    String[][] cards

    The first dimension is to represent the suit and the second dimension will represent the type of card(from ace to King)

    I want the constructor to take one parameter, which will represent the suit of the trump. Then the cards should be given the following values based on the trump suit:
    Non trump from 2 to 10 = 1 point
    non trump jack = 2
    non trump queen = 3
    non trump king = 4
    non trump ace = 5
    any trump card = non trump value + 1

    How do I assign these values so that I can print out the methods:

    returning the trump suit, by name
    I used:
    [code = Java]
    String get_trump_suit()
    {
    return trump_suit;
    }
    [/code]

    another method printing the whole deck of cards, suit by suit, with the value for each card.

    And finally, a method taking a String as a parameter representing a suit, and returning the total value of the cards in that suit.

    I need help getting started in this program! Thank you.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Two-dimensional Array representing playing cards

    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    29
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Two-dimensional Array representing playing cards

    I know how to use classes and objects but I am not good with the arrays. I am not sure how to assign the suit for the first dimension because I also had to create a single dimensional array for the suits. So can I put that single dimensional array into the first dimension of the multi dimensional array. and also would I need to define all of the cards for the second dimension? or is there an easier way

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Two-dimensional Array representing playing cards

    how to assign the suit for the first dimension
    Define int varaibles like this to use as the first index into the 2 dim array
    final int ClubIdx = 0;
    final int DiamondIdx = 1;
    etc
    ...
     
    cards[ClubIdx]  is the one dim array holding the Clubs
    cards[HeartIdx][0]  is the first Heart card

    would I need to define all of the cards for the second dimension?
    Depends on how the array is used. Each second dim can be a one dim array of different size. For example
    cards[ClubIdx].length does not need to be the same value as
    cards[SpadeIdx].length
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Create two dimensional array from a one dimensional array
    By Kristenw17 in forum Collections and Generics
    Replies: 1
    Last Post: April 9th, 2013, 07:51 PM
  2. need two dimensional array help..
    By mmagyar14 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 16th, 2013, 09:11 PM
  3. Converting Two dimensional array into an Array list
    By NewbieJavaProgrammer in forum Object Oriented Programming
    Replies: 11
    Last Post: September 29th, 2012, 04:23 PM
  4. Help with looking through a two-dimensional array.
    By aesguitar in forum Algorithms & Recursion
    Replies: 14
    Last Post: June 1st, 2012, 11:10 AM
  5. Help with one-dimensional array
    By brandon66 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 26th, 2012, 04:59 PM