ng Language Given the code below 1.Change all of the low-level arrays in your program to use the appropriate C# collection class instead. Be sure to implement Deck as a Stack 2. Make sure that you use the correct type-safe generic designations throughout your program. 3.Write code that watches for that incorrect data and throws an appropriate exception if bad data is found. 4. Write Properties instead of Getter and Setter methods. no lamdas, no delegates, no LINQ, no events Go Fish using System; namespace GoFish { public enum Suit { Clubs, Diamonds, Hearts, Spades };

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

C# Programing Language

Given the code below

1.Change all of the low-level arrays in your program to use the appropriate C# collection class instead. Be sure to implement Deck as a Stack

2. Make sure that you use the correct type-safe generic designations throughout your program.

3.Write code that watches for that incorrect data and throws an appropriate exception if bad data is found.
4. Write Properties instead of Getter and Setter methods.

no lamdas, no delegates, no LINQ, no events
Go Fish

using System;

namespace GoFish
{
public enum Suit { Clubs, Diamonds, Hearts, Spades };
public enum Rank { Ace, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King };

// -----------------------------------------------------------------------------------------------------

public class Card
{
public Rank Rank { get; private set; }
public Suit Suit { get; private set; }

public Card(Suit suit, Rank rank)
{
this.Suit = suit;
this.Rank = rank;
}

public override string ToString()
{
return ("[" + Rank + " of " + Suit + "]");
}

}

// -----------------------------------------------------------------------------------------------------

public class Deck
{
private Card[] cards;
private static Random rng = new Random();

public Deck()
{
Array suits = Enum.GetValues(typeof(Suit));
Array ranks = Enum.GetValues(typeof(Rank));

int size = suits.Length * ranks.Length;
cards = new Card[size];

int i = 0;
foreach (Suit suit in suits)
{
foreach (Rank rank in ranks)
{
Card card = new Card(suit, rank);
cards[i++] = card;
}
}
}

public int Size()
{
return cards.Length;
}

public void Shuffle()
{
if (Size() == 0) return;

// Fisher-Yates Shuffle (modern algorithm)
// - http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
for (int i = 0; i < Size(); i++)
{
int j = rng.Next(i, Size());

Card c = cards[i];
cards[i] = cards[j];
cards[j] = c;

}

}

public void Cut()
{
if (Size() == 0) return;

int cutPoint = rng.Next(1, Size());

Card[] newDeck = new Card[Size()];

int i;
int j = 0;
// Copy the cards at or below the cutpoint into the top of the new deck
for (i = cutPoint; i < Size(); i++)
{
newDeck[j++] = cards[i];
}

for (i = 0; i < cutPoint; i++)
{
newDeck[j++] = cards[i];
}
cards = newDeck;
}

public Card DealCard()
{
if (Size() == 0) return null;

Card card = cards[Size() - 1]; // Deal from bottom of deck (makes Resizing easier)
Array.Resize(ref cards, Size() - 1);

return card;
}

public override string ToString()
{
string s = "[";
string comma = "";
foreach (Card c in cards)
{
s += comma + c.ToString();
comma = ", ";
}
s += "]";
s += "\n " + Size() + " cards in deck.\n";

return s;
}

}
----------------------------------------------------------------------------------
public class Hand
{
private Card[] cards;

public Hand()
{
cards = new Card[0]; // Empty hand
}

public int Size()
{
return cards.Length;
}

public Card[] GetCards()
{
Card[] cardsCopy = new Card[cards.Length];
Array.Copy(cards, cardsCopy, cards.Length);
return cards;
}

public void AddCard(Card card)
{
Array.Resize(ref cards, Size() + 1);
cards[Size() - 1] = card;
}

public Card RemoveCard(Card card)
{
Card[] newCards = new Card[cards.Length - 1];

int i = 0;
foreach (Card c in cards)
{
if (c != card)
newCards[i++] = c;
}
cards = newCards;
return card;
}

public override string ToString()
{
string s = "[";
string comma = "";
foreach (Card c in cards)
{
s += comma + c.ToString();
comma = ", ";
}
s += "]";

return s;
}

}

}

public class Hand
{
private Card[] cards;

public Hand()
{
cards = new Card[0]; // Empty hand
}

public int Size()
{
return cards.Length;
}

public Card[] GetCards()
{
Card[] cardsCopy = new Card[cards.Length];
Array.Copy(cards, cardsCopy, cards.Length);
return cards;
}

public void AddCard(Card card)
{
Array.Resize(ref cards, Size() + 1);
cards[Size() - 1] = card;
}

public Card RemoveCard(Card card)
{
Card[] newCards = new Card[cards.Length - 1];

int i = 0;
foreach (Card c in cards)
{
if (c != card)
newCards[i++] = c;
}
cards = newCards;
return card;
}

public override string ToString()
{
string s = "[";
string comma = "";
foreach (Card c in cards)
{
s += comma + c.ToString();
comma = ", ";
}
s += "]";

return s;
}

}

}
public override string ToString()
{
string s = Name + "'s Hand: ";
s += Hand.ToString();

return s;
}
}

//----------------------------------------------------------------


using System;

namespace GoFish
{
class GoFishApplication
{
private static Deck theDeck;
private static Player[] players;
private static int numTurns = 0;
private static int numBooksPlayed = 0;

public static void Main()
{
Console.WriteLine("Go Fish Simulation (Random players)");
Console.WriteLine("===================================");

theDeck = new Deck();
theDeck.Shuffle();
theDeck.Cut();

players = new Player[4];
players[0] = new RandomPlayer("Paul");
players[1] = new RandomPlayer("Tom");
players[2] = new RandomPlayer("Pat");
players[3] = new RandomPlayer("Susan");

for (int i = 0; i < 5; i++)
{
foreach (Player player in players)
player.AddCardToHand(theDeck.DealCard());
}

foreach (Player player in players)
Console.WriteLine(player);

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Map
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education