This week you learned the basic principles of object-oriented programming, and how classes model …

This week you learned the basic principles of object-oriented programming, and how classes model real-world objects.

Now you can use this knowledge to simulate playing-cards.

Save your time - order a paper!

Get your paper written from scratch within the tight deadline. Our service is a reliable solution to all your troubles. Place an order on any task and we will take care of it. You won’t have to worry about the quality and deadlines

Order Paper Now

– Implement a class called Card to represent a playing card. The class should have the following methods:

__init__(self, rank, suit)  – to create a new card. rank is an int in the range 1-13 indicating the ranks from Ace (1) to King (13). suit is a single character – ‘d’, ‘c’, ‘h’, or ‘s’ indicating the suit (diamonds, clubs, hearts, or spades)

getRank(self) – returns the card’s rank

getSuit(self) – returns the card’s suit

BJValue(self) – returns the card’s Blackjack value (Ace = 1, face cards = 10)

__str__(self) – returns the card’s full name (e.g. “Ace of Spades”)

– Save your class in a file called card.py

– Other programs should be able to import your class and create a card like this:

from card import Card c = Card(1,”s”) print(c.getRank()) # should print 1 print(c.getSuit()) # should print ‘s’ or ‘Spades’ print(c.getBJValue()) # should print 10 for face cards & rank for others print(c) # should print ‘Ace of Spades’

Hint

Your __str__ method will need some way to match card rank and suit values with longer form values. Consider whether a lists or a dictionary is better for each.

Extra Credit

Write a function in card.py, but not part of the Card class, that asks the user whether to draw a card. If the user agrees, the function should create a new card with randomly selected value and suit. The program should display the combined total of Blackjack values after each draw, and prompt the user to draw another card until the total exceeds 21.

 

“Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!”

The post This week you learned the basic principles of object-oriented programming, and how classes model … appeared first on Nursing Assignment.

 

“Are you looking for this answer? We can Help click Order Now”

The post This week you learned the basic principles of object-oriented programming, and how classes model … first appeared on Nursing Essays Writers.