Focus on classes, objects, methods and good programming style Your task is to create a BankAccount class(See the pic attached) 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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Focus on classes, objects, methods and good programming style

Your task is to create a BankAccount class(See the pic attached)

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.

 

Sample run.
Choose: (N) New account, (D) Deposit, (W) withdraw, (C) Check Balance (S) Stop
>n
You have a new bank account with PIN 4863 and balance $0.00
Choose: (N) New account, (D) Deposit, (W) Withdraw, (C) Check Balance (S) Stop
>d
Enter PIN: 4865
Bad PIN. Transaction canceled.
Choose: (N) New account, (D) Deposit, (W) Withdraw, (C) Check Balance (S) Stop
>d
Enter PIN: 4863
Depositing
Amount to deposit: 54
New balance $54.00
Choose: (N) New account, (D) Deposit, (W) Withdraw, (C) Check Balance (S) Stop
>W
Enter PIN: 4863
Withdrawing
Amount to withdraw: 176
Cannot withdraw that amount.
Choose: (N) New account, (D) Deposit, (W) Withdraw, (C) Check Balance (S) Stop
>W
Enter PIN: 4863
Withdrawing
Amount to withdraw: 17
New balance $37.00
Choose: (N) New account, (D) Deposit, (W) Withdraw, (C) Check Balance (S) Stop
Enter PIN: 4863
Balance $37.00
Choose: (N) New account, (D) Deposit, (W) Withdraw, (C) Check Balance (S) Stop
>S
Thank you for banking with CSIT 512. Come back again.
Transcribed Image Text:Sample run. Choose: (N) New account, (D) Deposit, (W) withdraw, (C) Check Balance (S) Stop >n You have a new bank account with PIN 4863 and balance $0.00 Choose: (N) New account, (D) Deposit, (W) Withdraw, (C) Check Balance (S) Stop >d Enter PIN: 4865 Bad PIN. Transaction canceled. Choose: (N) New account, (D) Deposit, (W) Withdraw, (C) Check Balance (S) Stop >d Enter PIN: 4863 Depositing Amount to deposit: 54 New balance $54.00 Choose: (N) New account, (D) Deposit, (W) Withdraw, (C) Check Balance (S) Stop >W Enter PIN: 4863 Withdrawing Amount to withdraw: 176 Cannot withdraw that amount. Choose: (N) New account, (D) Deposit, (W) Withdraw, (C) Check Balance (S) Stop >W Enter PIN: 4863 Withdrawing Amount to withdraw: 17 New balance $37.00 Choose: (N) New account, (D) Deposit, (W) Withdraw, (C) Check Balance (S) Stop Enter PIN: 4863 Balance $37.00 Choose: (N) New account, (D) Deposit, (W) Withdraw, (C) Check Balance (S) Stop >S Thank you for banking with CSIT 512. Come back again.
Class name
Attributes
Methods
BankAccount
balance
pin
_init_()
get pin ()
check_pin ()
deposit ()
withdraw()
get_balance ()
float
integer
Transcribed Image Text:Class name Attributes Methods BankAccount balance pin _init_() get pin () check_pin () deposit () withdraw() get_balance () float integer
Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Unreferenced Objects
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education