Requirements:

For this task you are asked to create a Deck class representing a deck of 52 playing cards.

The deck will be made up of 52 regular playing cards and will not include any extra cards that may be found in a typical deck (such as jokers or rule cards).

The 52 cards will be divided up into four suits of 13 cards each, with the suits named after the suits in a pack of Swiss German playing cards.

The suit names are, in order: Roses, Bells, Acorns, Shields

The names of the 13 cards are, in order: Ace, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Knave, Knight, King.

When a Deck is first created, before the cards in it are shuffled, the cards should be in a particular order. That order is that the 13 cards (in order from Ace to King) from the Roses suit should appear first, followed by the 13 cards from the Bells suit, followed by the Acorns, followed by the Shields suit. Therefore the first card in a newly created Deck should be the Ace of Roses, while the last card should be the King of Shields.

The Deck class will provide three public methods: a constructor for creating a new deck in the order listed above. A Shuffle() method for shuffling the cards in the deck into a random order, and a Deal() method for dealing one card off the top of the deck..

public Deck()

The default constructor. This creates a new deck of 52 cards.

The cards in this newly-created deck are not shuffled, but are instead in the new deck order given above.

public void Shuffle()

This method shuffles the cards in the deck into a random order. As this method is to be random it should result in a different order each time it is called.

In addition, calling this method should shuffle any previously dealt cards back into the deck. For example, if you create a new deck and deal 10 cards from it with Deal() and then call Shuffle() the deck will have all 52 cards in it again.

public string Deal()

This method deals the top card off the deck, removing that card from the deck (until it is next shuffled). Because this method deals the first card off the top, if the deck is a newly-created deck and has not been shuffled yet, the first call to Deal() will return the Ace of Roses. Calling Deal() again 51 more times will return each card successive in the deck in order-- the Two of Roses, the Three of Roses etc. etc. all the way up to the King of Shields. This method returns the name of the card as a string, in this format: "{card} of {suit}" (for example, "Knave of Bells")

Naturally, if the deck has been shuffled, the cards could come out in any order- however, as dealing a card removes it from the deck until it is next shuffled, the same card will not be dealt twice.

If Deal() is called when there are no cards left in the deck (in other words, Deal() has been called 52 times without shuffling in between) must not return the name of a card, but must instead return "All 52 cards have been dealt". Subsequent calls to Deal() will continue returning All 52 cards have been dealt until the deck is shuffled again

For this exercise, you are not provided with a Main() method; you should write your own to test your Deck class.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CardDealer
{
class Deck
{
// Include any private fields here
// ...
public Deck()
{
// Include your code here
// ...
}
public void Shuffle()
{
// Include your code here
// ...
}
public string Deal()
{
// Include your code here
// ...
}
}
}
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.