Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

you need to implement the methods to get TestCardDeck to run properly. First imp

ID: 3562286 • Letter: Y

Question

you need to implement the methods to get TestCardDeck to run properly. First implement a constructor that will create an empty deck of playing cards. You should decide how to store a deck of playing cards as a data structure - I suggest using an ArrayList in the code, but if you have a better idea you can try it. Next implement a toString() method that displays a list of cards to the console. If you have used an ArrayList for your deck, you can try just returning the result of calling the ArrayList's toString() method and see what it does. Next implement remainingCards() and newDeck(). Note that after you implement newDeck() your test code will give an infinite loop (why is that?) until you get dealNext() working properly.

public class TestCardDeck {

/**

   * @param args

   */

public static void main(String[] args) {

CardDeck myDeck = new CardDeck();

myDeck.newDeck();

System.out.println("Deck contains:" + myDeck);

int count = 0;

while (myDeck.remainingCards() > 0) {

PlayingCard c1 = myDeck.dealNext();

System.out.println("Card #" + count + " is " + c1);

count = count + 1;

}

System.out.println("All cards displayed");

System.out.println("Deck contains: " + myDeck);

}

}

public class CardDeck {

//TODO - Private variables here

public CardDeck() {

// TODO - implement the constructor

// This constructor should create a new "empty"

// deck with no cards in it. Just set up the

// initial variables. This is useful for creating

// a "discard pile" for games that need it.

}

// TODO - implement the toString() method to be something

// reasonable. It is only going to be used for debugging

// purposes. See Exercise ## for suggestions on what might

// be "reasonable".

// @Override

// public String toString() {

//

// }

public int remainingCards() {

// TODO - returns the number of cards remaining in the

// deck.

return 0;

}

public void newDeck() {

// TODO - implement this method. It should create

// a new deck of 52 playing cards. The deck should

// be a List of PlayingCard objects stored as a

// private member variable. Initialize should take

// care to generate exactly the right cards with values

// 2 through 10 and Ace, King, Queen and Jack for each

// of the four suits.

// NOTE: Remember to take care of the case where

// you already have cards in your deck - you don't want

// to create duplicates!

}

public PlayingCard dealNext() {

// TODO - implement this so that the "top" PlayingCard

// on your deck is removed and passed back to the calling

// program. Note that you can decide which end of your

// List is the top card - you do not need to make it the

// card at position 0, though you may choose to.

return null;

}

Explanation / Answer

#include #include #include #include #define EVER ;; using namespace std; class Cards { public: Cards() { } ~Cards() { } void SetCardValues(int, int, int); void GetCardValues(); private: int Suit; int Value; int Index; }; class DeckOfCards : public Cards { public: DeckOfCards(); ~DeckOfCards() { } void SetDeckValues(int, int, int, int); void GetDeckValues(int); void Shuffle(); void Deal(); Cards pCard[52]; };