Question: 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

  •  Goal: Implement and test the Card class as shown in theGoal: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!