Design and implement an object-oriented program for displaying a deck of cards. Each card will have a value ranging in order from 1 for an ace, 2 for a two, and so on up to and including 11 for a jack, 12 for a queen, and 13 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 2 of clubs 3 of clubs 4 of clubs 5 of clubs 9 of Spades 10 of Spades Jack of Spades Queen of Spades King of Spades Shuffled Deck Count: 52 HAND 10 of Diamonds Ace of clubs Queen of Diamonds 7 of Diamonds 6 of Diamonds Hand points: 36 Hand count: 5 Deck count: 47 Process finished with exit code e Specifications Implement a Card, Deck, and Hand class for the business tier. The three classes can be in separate modules or a single objects module. • The Card class has a constructor method with parameters for three public attributes: suit, rank, and value. It also has a __str_method that returns the "rank" of "suit" (i.e. "5 of Diamonds") • The Deck class will hold 52 cards. It will have the following methods. • A constructor that initializes a private deck attribute, which is a list. There are no parameters, except for the ubiquitous self-parameter. This method will have a ranks and suits list (see below). Use a loop in a loop to create a card object for all ranks in all suits. A set of if statements is needed to assign the card value based on the rank. Add each object to the deck list attribute. • A 'Shuffle' method which randomizes the deck attribute. A 'dealCard' method that removes one card from the deck and returns the card. A count' method that returns the length of the deck attribute. A_iter_and_next_method so that a Deck object can be used in a loop. (See chapter 15 for details on these methods.) ranks = ["Ace", "2", "3", "4", "5", "6","7", "8", "9", "10", "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

Respuesta :

ACCESS MORE