Question: python work - Casino Night Overview In this lab, you will be creating a set of classes that model objects you might find used in

python work - Casino Night

Overview

In this lab, you will be creating a set of classes that model objects you might find used in a casino. The first of these classes is the Card class, representing a standard playing card from a 52 card deck. The second will be a ChipBank, representing a collection of chips for wagering. Once we have these classes, we can use them in the future to make casino games much easier. Cards will have the ability to be hidden, and information about the card will be easy to extract. ChipBank will hold a balance for us, and will display the balance using counts of different chips (e.g., 1 black, 2 red). Each of these method implementations should be short, and some methods can be easily implemented by calling other methods on the same object.

write programs that utilize object-oriented programming, use classes and be able to create objects; use method calls

Restrictions :

These restrictions apply only to the code contained in the classes. In your test code outside the classes, you may ignore these requirements

-These requirements must be met without using any while loops or for loops.

-The strings Ace, King, Queen, Jack, Spades, Hearts, Clubs and Diamonds may only appear once in the lab.

Card:

Write and test a class called Card that works according to the following spec-ifications. Each instance of this class represents a single card. Just like real cards, you can create multiple card objects with the same rank and suit if you chose to do so. In fact, youll create 52 to represent a deck of cards. Following is a list of the methods that the Card class must implement:

__init__(card_num)

The __init__() method always contains code that runs when an object is created (or initialized). This is a good place to store initial values. You may add to this method as needed later in the assignment, as you decide you need additional variables to work with. This method accepts a card_num parameter indicating which of the 52 cards we mean to create. This method will need to set one or more instance variables (e.g., suit, and rank) to record which card is being represented in this specific card object.

parameters

-card_num - between 0 and 51, indicating which card in the deck it is. The first thirteen represent the ace of spades through the king of spades, the next thirteen represent the hearts, then clubs and diamonds.

get_suit()

This method returns the suit of the card as a string and should contain Spades, Hearts, Clubs or Diamonds depending on the card.

return:

-This method should return a string containing the name of the suit. Example: Diamonds or Spades

get_rank()

This method returns the rank of the card as a string and should contain Ace, Jack, Queen, King or the number of the card.

return

This method should return a string containing the rank of the card. Either a number or title. Example: 7 or King

get_value()

This method returns a numeric value depending on the point value of the card at hand. Face cards have a value of 10, Aces are valued at 11 and other cards are valued at their numeric rank.

return

This method should return a numeric value for the card. Example: 7 or 10.

face_down()

This method flips the card face-down, as cards are initialized they should be facedown by default. The class variable set by this method should be accessible in the __str__() method. This method has no parameters or return values.

face_up()

This method does the opposite of face_down(). If a card is hidden and you callface_up() it should no longer be hidden. The class variable set by this method should be accessible in the __str__() method. This method has no parameters or return values.

__str__()

This method returns the card in string representation if the card is face-up.example: King of Hearts or 4 of Clubs. If the card is face-down, it should return no matter what card it is.

return

Should return a string representing the full name of the card. Example: 7 of Diamonds or King of Spades

ChipBank:

Write and test a class called ChipBank that works according to the following specifications. Following is a list of the methods and instance variables that the ChipBank class must implement:

__init__(value)

Creates a new ChipBank object with an initial monetary balance eqaul to the value passed in via the parameter. The instance variable balance will be used to record the current value of the ChipBank class and should be an integer.

parameters

-value - Numeric value to start the ChipBank balance at.

withdraw(amount)

Reduces the balance of the ChipBank by the given amount (passed in via the parameter). If the balance of the ChipBank is lower than the amount requested for withdrawal, the balance drops to zero. The function should return the amount actually withdrawn (i.e., the amount passed in, or the drained balance).

parameters

-amount - Numeric amount to withdraw. Example: 100 or 0.

return

Numeric value actually withdrawn.

Examples:If the remaining balance is 57 and amount is 100, the returned value is 57.

After this call, the remaining balance is 0.

If the remaining balance is 100, and the amount is 40, the returned value is 40.

After this call, the remaining balance is 60.

deposit(amount)

Increases the balance of the ChipBank by the given amount. Does not return a value.

parameters

-amount - Numeric amount to deposit. Example: 70.

get_balance()

The only functionality of this method is to see the current balance of the Chip-Bank.

parameters

None.

return

Numeric balance currently held in ChipBank.

__str__()

Returns the object as a string describing the different chips held as well as the total balance. The number of chips listed should be the minimum number to represent the total balance. You should list the number of black, green, red, and blue chips where black chips are worth 100, green are worth 25, red are worth5, and blues are worth 1.

return

Example: a ChipBank with a balance of 163 would be represented as 1 blacks, 2 greens, 2 reds, 3 blues - totaling $163.

record(handle) - implementing additional functionality for theChipBank class .

By calling this function with a file handle as a parameter, the ChipBank begins to log deposits and withdraws. Each time a deposit or withdraw is made aline should be written to the file handle showing the remaining value, and the change in balance separated by a tab. By calling this function again and passingNone as a parameter, logging is disabled. You should include code to capture the changes being made in the test code to output to a file. Example file output:

245 -5

255 10

355 100

305 -50

testing:

test your code using the following code, following your class definitions

#### DO NOT CHANGE TEST CODE #### import random if __name__ == "__main__": # Lets make a deck of cards deck = [] for i in range(52): my_card = Card(i) deck.append(my_card) #flip over each card my_card.face_up() #print each card as we add them print(my_card)

#print a random card from the deck print(random.choice(deck)) #in my implementation. card number 37 is the queen of clubs card = Card(37) print(card) #Queen of Clubs print(card.get_value()) #10 print(card.get_suit()) #Clubs print(car.get_rank()) #Queen card.face_down() print(card) # card.face_up() print(card) #queen of Clubs cs = ChipBank(149) print(cs) #1 black, 1 greens, 4 reds, 4 blues - totaling $149 cs.deposit(7) print(cs.get_balance()) #156 print(cs) #1 blacks, 2 greens, 1 reds, 1 blue - totaling $156 print(cs.withdraw(84)) # 8445 print(cs) #0 blacks, 2 greens, 4 reds, 2 blues totaling $72 cs.deposit(120) print(cs) #1 blacks ,3 greens ,3 reds ,2 blues totaling $192 print(cs.withdraw(300)) #192

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!