Focus on classes, objects, methods and good programming style 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.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
**Focus on classes, objects, methods and good programming style**

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.
Transcribed Image Text:**Focus on classes, objects, methods and good programming style** 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.
The text is about implementing a simple bank account class in a programming context with specific functions to manage account actions. Below is the transcription, organized for educational use:

---

### Bank Account Class Implementation

The bank account class supports the following methods:

- **check_pin(pin)**: Validates the provided `pin` against the stored value. Returns `True` if they match, `False` otherwise.

- **deposit(amount)**: Accepts an `amount` as an argument, updates the account balance by adding the `amount`, and returns the new balance.

- **withdraw(amount)**: Verifies if the specified `amount` can be withdrawn (ensuring it does not exceed the current balance). If the transaction is successful, the `amount` is deducted, and the new balance is returned. Returns `False` if not successful.

- **get_balance()**: Returns the current account balance.

### Main Function Demonstration

A `main()` function is suggested to demonstrate the usage of the bank account class by implementing a simple menu interface that allows the following actions, with PIN verification where necessary:

1. **New Account**:
   - When selected, creates a new account and informs the user of their PIN.

2. **Deposit**:
   - Prompts the user to enter the PIN. If correct, asks for the deposit amount. Processes the deposit and displays the updated balance.

3. **Withdraw**:
   - Prompts the user to enter the PIN. If correct, asks for the withdrawal amount. Processes the transaction, displays the updated balance or an error message if unsuccessful.

4. **Check Balance**:
   - Prompts the user to enter the PIN. If correct, uses `get_balance` to display the current balance.

### Output Specifications

- All printed output should be handled within the `main()` function, not within individual methods.

--- 

This structured overview provides a foundation for users to explore basic banking operations programmatically.
Transcribed Image Text:The text is about implementing a simple bank account class in a programming context with specific functions to manage account actions. Below is the transcription, organized for educational use: --- ### Bank Account Class Implementation The bank account class supports the following methods: - **check_pin(pin)**: Validates the provided `pin` against the stored value. Returns `True` if they match, `False` otherwise. - **deposit(amount)**: Accepts an `amount` as an argument, updates the account balance by adding the `amount`, and returns the new balance. - **withdraw(amount)**: Verifies if the specified `amount` can be withdrawn (ensuring it does not exceed the current balance). If the transaction is successful, the `amount` is deducted, and the new balance is returned. Returns `False` if not successful. - **get_balance()**: Returns the current account balance. ### Main Function Demonstration A `main()` function is suggested to demonstrate the usage of the bank account class by implementing a simple menu interface that allows the following actions, with PIN verification where necessary: 1. **New Account**: - When selected, creates a new account and informs the user of their PIN. 2. **Deposit**: - Prompts the user to enter the PIN. If correct, asks for the deposit amount. Processes the deposit and displays the updated balance. 3. **Withdraw**: - Prompts the user to enter the PIN. If correct, asks for the withdrawal amount. Processes the transaction, displays the updated balance or an error message if unsuccessful. 4. **Check Balance**: - Prompts the user to enter the PIN. If correct, uses `get_balance` to display the current balance. ### Output Specifications - All printed output should be handled within the `main()` function, not within individual methods. --- This structured overview provides a foundation for users to explore basic banking operations programmatically.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 17 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY