Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Goal: Implement and test the Card class as shown in the Card/Deck UML Diagram. Relevant Examples: Person Pet Details: The ranks of the cards from

  • image text in transcribedGoal: Implement and test the Card class as shown in the Card/Deck UML Diagram.
  • Relevant Examples: Person Pet
  • Details:
    1. The ranks of the cards from lowest to highest:
      2 3 4 5 6 7 8 9 10 11 (Jack) 12 (Queen) 13 (King) 14 (Ace) 
    2. The order of the suits from lowest to highest:
      "C" (Club) "D" (Diamond) "H" (Heart) "S" (Spade) 
    3. The color method returns "black" if the suit is "C" or "S"; it returns "red" otherwise (if the suit is "D" or "H").
    4. In the __str__ method, define a list named symbols that contains the possible symbols for each index, specified by the rank instance variable.
      symbols = ["", "", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"] 
      Here are the indices (ranks) and values of the elements in the symbols list:
      Indices: 0 1 2 3 4 5 6 7
      Values: "" "" "2" "3" "4" "5" "6" "7"
      Indices: 8 9 10 11 12 13 14
      Values: "8" "9" "10" "J" "Q" "K" "A"
      The values for the indices 0 and 1 are empty strings ("") because no card has rank 0 or 1. You can use this __str__ method for the Card class:
      def __str__(self): symbols = ["", "", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"] return symbols[self.rank] + self.suit 
    5. The output of the statement
      c = Card(11, "S") print(c) 
      is JS, where "J" is obtained from the symbols list and "S" is the suit.
    6. The name of the file that implements the Card class is card.py.
    7. Submit two test scripts test1.py and test2.py.
      1. test1.py tests the Card class in the traditional way using print statements. Test both instance variables (rank and suit) and the methods (Card, suit, __str__). Print a Card object c1 like this
        print(c1) 
        to test the __str__ method.
      2. test2.py tests the Card class using unit tests. Test the rank and suit instance variables; also test the color method. Finally test the __str__ method like this:
        c1 = Card(12, "S") self.assertEqual(str(c1), "QS")
Card rank: int suit: str init (sel ank: int, suit: str) color(self: Card: str -str (sel) . Str Deck _cards Cardll _init_(self: Deck) str (sel:st deal self Deck) Card add_to_top(self: Deck, c Card) +add to_bottom(self: Deck, c: Card) +count(self: Deck): int is_empty(self: Deck):bool +shufme self: Deck)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David J. Auer David M. Kroenke

13th Edition

B01366W6DS, 978-0133058352

More Books

Students also viewed these Databases questions

Question

What did they do? What did they say?

Answered: 1 week ago

Question

2. Do you find change a. invigorating? b. stressful? _______

Answered: 1 week ago