i have this class that should create an array of cards
this is the card
how do i make a tester to display the deck
that is what i was told to do
. Provide a Class Card that knows it face value and suit value. Keep these as integers,
2. The class must be able to translate its values to strings. (i.e. a face value of 13 will translate into King, a suit value of 1 may translate into Clubs).
3. Provide a class DeckOfCards that will start out with 52 different cards. Create them in order. Use an array or array list to keep track of the cards.
4. A DeckOfCards will return the top card when the deal() method is invoked.
5. A DeckOfCards will know how many cards are still left in the deck.
6. Provide a method to shuffle the cards in the deck. Swap the location of two random cards in the array and repeat this many times.
7. Provide a driver that deals two cards, displays them and then asks the user whether s/he wants an additional card. Stop when the user says no.
Code:
public class DeckOfCards{
public Card card;
public Card deck[];
DeckOfCards() {
for (int s = 0; s < 3; s++)
{
for (int i=0; i < 13; i++)
{
deck[i] = new Card(i,s);
deck[i+13] = new Card(i,s);
deck[i+26] = new Card(i,s);
deck[i+39] = new Card(i,s);
}
}
}
}
Code:
public class Card {
private final int suit;
private final int value;
public Card(int theValue, int theSuit) {
value = theValue;
suit = theSuit;
}
public int getSuit() {
return suit;
}
public int getValue() {
return value;
}
public String toString() {
return getValue() + " of " + getSuit();
}
}
that is what i was told to do
. Provide a Class Card that knows it face value and suit value. Keep these as integers,
2. The class must be able to translate its values to strings. (i.e. a face value of 13 will translate into King, a suit value of 1 may translate into Clubs).
3. Provide a class DeckOfCards that will start out with 52 different cards. Create them in order. Use an array or array list to keep track of the cards.
4. A DeckOfCards will return the top card when the deal() method is invoked.
5. A DeckOfCards will know how many cards are still left in the deck.
6. Provide a method to shuffle the cards in the deck. Swap the location of two random cards in the array and repeat this many times.
7. Provide a driver that deals two cards, displays them and then asks the user whether s/he wants an additional card. Stop when the user says no.
Comment