Question: how to do this: The first class, Card will model a standard playing card. Suits for each Card can be Spade, Heart, Club, or Diamond.
how to do this:
The first class, Card will model a standard playing card. Suits for each Card can be Spade, Heart, Club, or Diamond. The value can be Ace through 10, jack, Queen and King. Order of the cards will be based on the value first and then on the suit. For this assignment, Ace will be considered high. Suit order is Spade, Heart, Diamond and then Club.
CardDeck, will model a deck of cards and provide methods to access the cards. The deck will contain 52 cards, one of each of the possible Suit and Value.
CardTester, will allow the user to call methods on the Card and CardDeck classes. Please spend some time thinking about your interface for the cards class.
InvalidCardException a custom exception to be used when a Card is found to be invalid.
InvalidDeckException a custom exception to be used when a CardDeck is found to be invalid.
CardDeck class requirements:
The CardDeck class will model a standard deck of playing cards. This deck will contain 52 cards, Ace through King in four suits, Spades, Clubs, Diamonds and Hearts. Recommend using an ArrayList
public CardDeck() This constructor will create the deck of cards and place them in the following order:
Spades Ace to King
Hearts Ace to King
Diamonds Ace to King
Clubs Ace to King
public void shuffle() This method will take the constructed deck and randomize the cards and store the new ordering of all cards.
public Card deal() This method will deal the next card in the deck. We will deal with an empty deck in future assignments.
public Card selectCard(int cardNumber) This method will return the card at a specific location, similar to cutting the deck. The program must not allow for an out of bounds cut. In other words, if the user passes a number that is out of range, an InvalidDeckException will be thrown and must be handled in the CardTester class.
public void saveDeck(String fileName) This method will write the current deck to a file. This method should throw a FileNotFoundException if an error occurs in writing the file.
public void loadDeck(String fileName) This method will read the supplied file and create a deck from this file. If an invalid deck is discovered, please create and throw an InvalidDeckException. This method should throw a FileNotFoundException if the file name is invalid.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
