Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C# SAMPLE CODE: 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

C#

image text in transcribed

SAMPLE CODE:

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 // ... } } }

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 Italian playing cards. The suit names are, in order: Cups, Coins, Clubs, Swords 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 Cups suit should appear first, followed by the 13 cards from the Coins suit, followed by the Clubs, followed by the Swords suit. Therefore the first card in a newly created Deck should be the Ace of Cups, while the last card should be the King of Swords 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 agair 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 Cups. Calling Deal() again 51 more times will return each card successive in the deck in order-- the Two of Cups, the Three of Cups etc. etc. all the way up to the King of Swords. This method returns the name of the card as a string, in this format (card of (suit)" (for example, "Knave of Coins") 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. IfDeal() 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"(out of cards) ". Subsequent calls to Deal) will continue retuning (out of cards) 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago