Cardlist, Hand and Deck

0 comments

Write 3 classes: CardList, Hand, and Deck, where Hand and Deck are both children of CardList. CardList is meant to be an “abstract class” while Hand is a player’s hand and Deck is a deck of cards. For simplicity, a card is just an integer between 1 and 52. The classes should have the following methods:

CardList: Stores an ordered set of cards.

1. Initializer: Takes no inputs and starts with an empty set of cards.

2. AddCard: Takes a single integer between 1 and 52 as input and adds this to the top of the list of cards only if the card is not already in the list of cards.

3. RemoveCard: Takes no input, and returns the most recently added card, removing this card from the card list.

Deck: Stores a set of cards meant to be a deck.

1. Initializer: Takes no input, but starts with all 52 cards shu✏ed in some order.

2. RemoveCard: Takes no input, and returns the top card, removing this card from the deck. Design your classes, so that you do not need to write a RemoveCard method for Deck; it should just be able to use RemoveCard of its parent class.

Hand: Stores a set of cards meant to be a player’s hand.

1. Score: Returns the sum of the values in the players hand, which we take to be its score.

2. RemoveCard: Takes a single integer between 1 and 52 as input, and removes this card if it is in the list of cards, and otherwise does nothing; should override the method from its parent class

1

About the Author

Follow me


{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}