All questions
MediumObject-Oriented Programming · Class Design
Build a Deck of Cards Class
Written by a community member · · 5 attempts · 0% pass
1
Implement a Deck class that represents a standard deck of playing cards.
The class must support these behaviors:
Deck()creates a fresh standard 52-card deck.- The deck order on construction is suit-major, then rank-major:
Clubs, Diamonds, Hearts, Spades; and within each suit:
Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King. - Each card should be represented as a string in the form
"<Rank> of <Suit>". shuffle()randomly shuffles the remaining cards in the deck in place.draw(count)removes and returns the topcountcards from the deck.- The top of the deck is the start of the internal list.
- If
countis greater than the number of cards remaining, return all remaining cards. - Drawing cards should mutate the deck.
remaining()returns the number of cards left in the deck.
Examples:
deck = Deck(); deck.draw(1)->["Ace of Clubs"]deck = Deck(); deck.draw(2)->["Ace of Clubs", "2 of Clubs"]- After
deck.draw(2),deck.remaining()->50
Assume no jokers and a standard 52-card deck only.