Focus on classes, objects, methods and good programming style. Program has to be written in basic python.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter11: Inheritance And Composition
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question

Focus on classes, objects, methods and good programming style.

Program has to be written in basic python.

Your task is to create a BankAccount class.

Class name                 BankAccount

Attributes                  __balance float
                                  __pin integer

Methods                     __init_()
                                   get_pin()
                                   check_pin()
                                   deposit()
                                   withdraw()
                                  get_balance()

The bank account will be protected by a 4-digit pin number (i.e. between 1000 and 9999). The
pin should be generated randomly when the account object is created. The initial balance should
be 0.
get_pin()should return the pin.
check_pin(pin) should check the argument against the saved pin and return True if it
matches, False if it does not.
deposit(amount) should receive the amount as the argument, add the amount to the account
and return the new balance.
withraw(amount) should check if the amount can be withdrawn (not more than is in
the account), If so, remove the argument amount from the account and return the new balance if
the transaction was successful. Return False if it was not.
get_balance() should return the current balance.
Finally, write a main() to demo your bank account class. Present a menu offering a few actions and
perform the action the user requests, checking the pin where appropriate.
1. New Account – if selected, create a new account and tell the user the pin.
2. Deposit – if selected, prompt the user to input the pin, check the pin and then, if correct,
prompt for the amount to deposit. Process the deposit and report the new balance
3. Withdraw – if selected, prompt the user to input the pin, check the pin and then, if correct,
prompt for the amount to withdraw. Process the withdrawal and report the new balance or a
message if the transaction was not successful.
4. Check balance – if selected, prompt the user to input the pin, check the pin and then, if correct,
call the get_balance method and report the balance.
All printed output should be done in main(), not the methods.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Reference Types in Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT