Answered step by step
Verified Expert Solution
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
- 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 lowest to highest:
2 3 4 5 6 7 8 9 10 11 (Jack) 12 (Queen) 13 (King) 14 (Ace)
- The order of the suits from lowest to highest:
"C" (Club) "D" (Diamond) "H" (Heart) "S" (Spade)
- The color method returns "black" if the suit is "C" or "S"; it returns "red" otherwise (if the suit is "D" or "H").
- 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" def __str__(self): symbols = ["", "", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"] return symbols[self.rank] + self.suit
- 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. - The name of the file that implements the Card class is card.py.
- Submit two test scripts test1.py and test2.py.
- 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. - 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")
- 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
- The ranks of the cards from lowest to highest:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started