# Problem printing the card's value and suit

Page 1 of 1

## 4 Replies - 523 Views - Last Post: 14 October 2011 - 01:16 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=251286&amp;s=307e33e2f4b015c14b1c866ef0f9e075&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 mike28

Reputation: 0
• Posts: 62
• Joined: 03-October 11

# Problem printing the card's value and suit

Posted 14 October 2011 - 09:23 AM

```[public class Card
{
public static final int HEARTS = 0;
public static final int DIAMONDS = 1;
public static final int CLUBS = 2;
public static final int SPADES = 3;
//the card has a value (2..10, J, Q, K, A)
public static final int Ace = 0;
public static final int Two = 1;
public static final int Three = 2;
public static final int Four = 3;
public static final int Five = 4;
public static final int Six = 5;
public static final int Seven = 6;
public static final int Eight = 7;
public static final int Nine = 8;
public static final int Ten = 9;
public static final int J = 11;
public static final int Q = 12;
public static final int K = 13;

public int face=1;
public int value=1;

public Card()
{
face = 1;
value = 1;
shuffleValue();
shuffleFace();
//pick();
}

public Card(int f, int v)
{
face = f;
value = v;
shuffleValue();
shuffleFace();
//pick();
}

public void shuffleFace()
{
face = (int)(Math.random()*4);
}

public void shuffleValue()
{
value = (int)(Math.random()*14);
}

public void pick()
{
shuffleFace();
shuffleValue();
}

public String  getValue()
{
if (value == Ace)
return "Ace";
else if (value == Two)
return "Two";
else if (value == Three)
return "Three";
else if (value == Four)
return "Five";
else if (value == Six)
return "Six";
else if (value == Seven)
return "Seven";
else if (value == Eight)
return "Eight";
else if (value == Nine)
return "Nine";
else if (value == Ten)
return "Ten";
else if (value == J)
return "Jack";
else if (value == Q)
return "Queen";
else
return "King";
}

public String getFace()
{
if (face == HEARTS)
return "HEARTS";
else if (face == DIAMONDS)
return "DIAMONDS";
else if (face == CLUBS)
return "CLUBS";
else
}

public String toString()
{
return "Value: " +getValue()+ ", Face: " +getFace();
}
}]

[public class Deck extends Card
{
public Card[] Collection;   // An array of 52 Cards, representing the deck.
public int cardsUsed; // How many cards have been dealt from the deck.

public Deck() {
// Create an unshuffled deck of cards.
Collection = new Card[52];
int cardCt = 0; // How many cards have been created so far.
for ( int face = 0; face <= 3; face++ ) {
for ( int value = 1; value <= 13; value++ ) {
Collection[cardCt] = new Card(value,face);
cardCt++;

}
System.out.println(Collection[cardCt]);
}
cardsUsed = 0;

}

public String toString()
{
String CardDescription = super.toString();
return"Card "+CardDescription;
}
}]

[import java.lang.*;
import java.io.*;
public class Table
{
public static void main(String[] args)
{

Deck[] deck = new Deck[25];

}
}]
```

This post has been edited by modi123_1: 14 October 2011 - 10:57 AM
Reason for edit:: please use code tags

Is This A Good Question/Topic? 0

## Replies To: Problem printing the card's value and suit

### #2 Fuzzyness

• Comp Sci Student

Reputation: 669
• Posts: 2,438
• Joined: 06-March 09

## Re: Problem printing the card's value and suit

Posted 14 October 2011 - 10:41 AM

what errors are you getting? What way do you want it to print?

### #3 mike28

Reputation: 0
• Posts: 62
• Joined: 03-October 11

## Re: Problem printing the card's value and suit

Posted 14 October 2011 - 10:47 AM

I dont get an error i just want to print the whole deck which is 52 cards

Thank you!

### #4 Fuzzyness

• Comp Sci Student

Reputation: 669
• Posts: 2,438
• Joined: 06-March 09

## Re: Problem printing the card's value and suit

Posted 14 October 2011 - 10:50 AM

make a for loop to cycle through the array and call each objects toString method.

ie. System.out.println(Deck[x].toString());

### #5 mike28

Reputation: 0
• Posts: 62
• Joined: 03-October 11

## Re: Problem printing the card's value and suit

Posted 14 October 2011 - 01:16 PM

Thank You