Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Lab: Casino Night: Part 2: Chip Bank Write and test a class called ChipBank that works according to the following specifications. Following is a

Python

Lab: Casino Night: Part 2: Chip Bank

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 ChipBank.

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 worth 5, 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

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

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions