# Two-dimensional Array representing playing cards

• April 25th, 2013, 12:07 PM
Spanky_10
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.
• April 25th, 2013, 12:08 PM
KevinWorkman
Re: Two-dimensional Array representing playing cards
• April 25th, 2013, 12:41 PM
Spanky_10
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
• April 25th, 2013, 12:51 PM
Norm
Re: Two-dimensional Array representing playing cards
Quote:

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
Code :

```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```

Quote:

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