Question: Chapter 1 6 Card Objects Design and implement an object - oriented program for displaying a deck of cards. Each card will have a value
Chapter Card Objects
Design and implement an objectoriented program for displaying a deck of cards. Each card will have a value ranging in order from for an ace, for a two, and so on up to and including for a jack, for a queen, and for the king.
The focus of the exercise is to create three classes that represent a card, deck, and hand using composition.
Console
Cards Tester
DECK
Ace of Clubs
ranks Ace Jack, Queen, King
suits Clubs Diamonds, Hearts, Spades
The Hand class will hold a list of cards. It will have the following methods.
A constructor method, with no parameter except for self will create a private 'cards'
attribute as a list.
An 'addCard' method that takes a card object parameter which will add the card object to
the cards attribute.
A 'playCard' method that takes a named index parameter. The default index value is zero.
The method will remove the card at the index value of the cards attribute and return the
card object.
A 'count' method that returns the length of the cards attribute.
A 'totalPoints' method that returns the total of the values of all cards in the hand.
A iter and next method so that a Hand object can be used in a loop.
The main method, in a module separate from the objects module, will do the following.
Create a deck object
Print all cards in the deck as a string
Shuffle the deck
Print the size of the deck
Deal a hand with five cards
Print the cards of the hand
Print the total value of the hand
Print the number of cards in the hand, and
Print the number of cards in the deck
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
