Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Visual C# How To Program - Deitel I see the answer to the Java side everywhere, but I am lost when it comes to the

Visual C# How To Program - Deitel

I see the answer to the Java side everywhere, but I am lost when it comes to the C# side.

What I have so far is below. I cannot seem to figure out how to identify hands.

8.29 (Card Shuffle and Dealing)

Modify Fig. 8.12 in the textbook to deal a five-card poker hand. Then modify class Deckofcards of Fig. 8.11 to include methods that determine whether a hand contains:

a pair

two pair

three of a kind (e.g., three jacks)

four of a kind (e.g., four aces)

a flush (i.e., all five cards of the sam suit)

a straight (i.e., five cards of consecutive face values)

a full house (i.e., two cards of one face value, and three cards of another face value.

class Card { private string Face { get; } private string Suit { get; }

public Card (string face, string suit) { Face = face; Suit = suit; }

public override string ToString() => ($"{Face} of {Suit}"); }

using System;

class DeckOfCards { private static Random randomNumbers = new Random(); private const int NumberOfCards = 52; //Number of cards in Deck private Card[] deck = new Card[NumberOfCards]; private int currentCard = 0;

public DeckOfCards() { string[] faces = { "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King" }; String[] suits = { "Hearts", "Diamonds", "Clubs", "Spades" };

//populate deck with card objects for (var count = 0; count < deck.Length; ++count) { deck[count] = new Card(faces[count % 13], suits[count / 13]); } }

public void Shuffle() { currentCard = 0;

for (var first = 0; first< deck.Length; ++first) { var second = randomNumbers.Next(NumberOfCards);

Card temp = deck[first]; deck[first] = deck[second]; deck[second] = temp; } } // deal a card public Card DealCard() { if (currentCard < deck.Length) { return deck[currentCard++]; } else { return null; } }

public Card DealHand() { if (currentCard < deck.Length) { return deck[currentCard++]; } else { return null; } }

}

using System;

class Program { static void Main() { var myDeckOfCards = new DeckOfCards();

myDeckOfCards.Shuffle();

for (var i = 0; i < 5; ++i) { Console.Write($"{myDeckOfCards.DealCard(),-19}");

if ((i+1) % 5 == 0) { Console.WriteLine(); } }

} }

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

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions