all should run as the output shown in attachment without any errors Modify homework2 to include additional
Question:
all should run as the output shown in attachment without any errors
Modify homework2 to include additional functionalities:
Modify the existing program.
1. Bank account client
a. When creating an account, the user will not be prompted for the account number. The account number will now be generated in the BankAccount class when the constructor is invoked while an account is being crd.
b. The program will allow multiple accounts to be crd. Each account will be tracked in the accounts database. More details to come later.
c. When creating an account, the account will either be crd as a regular account (BankAccount) or a youth account (YouthAccount)
d. Additional menu options
i. Search for an account
ii. Delete an account.
iii. Display total number of accounts.
iv. Display all accounts.
2. Modify the BankAccount class.
a. The account number will not be passed into the class constructor. Only the first name, last name, and starting balance will be passed as parameters. Within the constructor, an account number will be crd using a concatenation of the account owner's initials and a randomly generated 5-digit integer.
b. Overload dunder __str__ and __repr__ functions in the class. Both methods will return the account owner's first name, last name, account number, and account balance.
c. Replace getters and setters for the first and last name with properties!
Additional/New Functionalities
1. Add an accounts_database module (accounts_database.py) which will include the AccountsDatabase class. This class will allow the user to add an account to the database (a dictionary), search for an account in the database, update an account in the database, delete and account from the database, list all accounts in the database, and display the total number of accounts in the database. See details class later.
2. Add a youth_account module (youth_account.py) which will include the class YouthAccount. This class will be a sub/child class of BankAccount. See details about the class later.
Update the program menu
1. cr customer bank account.
a. Add options to cr regular account or youth account.
2. Perform account deposit.
3. Perform account withdraw.
4. Display account balance.
5. Display transactions.
6. Search for an account
7. Delete an account.
8. Display total number of accounts.
9. Display all accounts.
10. Exit (wr accounts details to a file and then exit)
BankAccount Class Details
The program will include a class, BankAccount, defined in a module name bank_account.py. The Bank account class will contain the following attributes:
Data attributes (instance variables must be crd as private):
- account_number: int
- account_balance: float
- first_name: str
- last_name: str
- tranactions: list
Method attributes:
- Constructor (__init__) that takes the first name, last name, and starting balance as parameters. These parameters will be used to initialize instance variables listed under Data attributes (except the account number) above. The account number will be generated as a concatenation of the account holder/owner's initials and a 5-digit randomly generated integer.
Note: The transactions instance variable should be initialized to a blank/empty list
- cr properties (read and wr) for the instance variables.
- deposit(): This method takes the deposit amount, updates the account balance and adds a transaction to the list of transactions.
- withdraw(): This method takes the debit amount, updates the account balance, and adds a transaction to the list of transactions.
Note: Withdraw amount cannot be greater than the account balance. Display an error if the account balance is less than the withdraw amount. Do not update the account balance or transactions list.
- display_tranactions(): This method takes no argument. It displays the transactions: Display each transaction on a separate line. Display "No transactions" if there are no transactions on the account.
- display_balance(): This method takes no argument. It displays the current account balance.
- display_details(): The method takes no argument. It displays the account owner first and last name, the account number, and the current account balance.
YouthAccount Class Details
The program will include a class, YouthAccount, defined in a module name youth_account.py. The YouthAccount is a sub class of BankAccount. bank_account module will need to be imported in the youth_account module because YouthAccount is a sub class of BankAccount.
YouthAccount will contain the following attributes:
Data attributes (instance variables must be crd as private):
- guardian_name: str
- withdraw_limit: float
- account_owner_age: int
Method attributes:
- constructor (__init__) that takes the first name, last name, starting balance, guardian name, withdraw limit, and account owner age as parameters. BankAccount constructor will be invoked and passed the first name, last name, starting balance. Guardian age, withdraw limit, and account owner age will be used to initialize the instance variables listed under Data attributes above.
- cr properties (read and wr) for the instance variables in the class.
- Overload the str and repr functions to display all data attributes (attributes inherited from the BankAccount class and attributes of the YouthAccount class)
- display_details(): Display the BankAccount details plus the data attributes for YouthAccount
AccountsDatabase Class Details
The program will include a class, AccountsDatabase, defined in a module named accounts_database.py. The Account Database class will contain the following attributes:
Data attributes (instance variable must be crd as private):
- accounts: dictionary
Method attributes:
- constructor (__init__) takes no parameters. Initializes the accounts instance variable to an empty dictionary.
- add_account(): Takes a bank account object (YouthAccount or regular account BankAccount) object as parameter and adds the object to the accounts dictionary. The account number serves as the key.
- update_account(): Takes a bank account object (YouthAccount or regular account BankAccount) object as parameter, finds the object in the accounts dictionary using the account number and replaces the existing object with the object passed in. If the account is not found, display a message indicating the account was not found.
- search_account(): Takes an account number as parameter. Searches the accounts database (dictionary) for the account, displays the account details, and return true if the object is found, or false if the account was not found.
Note: When displaying the object, pass the object to the print function.
- delete_account(): Takes a bank account number (YouthAccount or regular account BankAccount) as parameter. Search for the account using the search_account() method. If the account is found, delete it.
- display_total_accounts(): This method takes no parameters. It displays a count of the objects in the accounts dictionary.
- get_account(): Takes a bank account number (YouthAccount or regular account BankAccount) as parameter, searches for the account, and returns the account.
- display_all_accounts(): Takes no parameters. It displays details for each object in the accounts dictionary.
Main program
The main program will be written in a module named bank_account_client.py. This module will contain code that uses the YouthAccount and AccountsDatabase classes. The code in this module will present the user with the program options and allow interaction via the menu options. Once the user selects an option, the program will execute logic associated with the option and return to the list of options. Selecting the exit option will cause the program to wr the accounts in the database to file. Each account details will be written to a line in the file. Name the file bank_accounts.txt
The program will first cr an instance of the AccountsDatabase class.
Program Menu details:
1. cr customer bank account: If selected, the program will prompt for the type of account (1. Regular Account or 2. Youth Account). If creating Regular Account, the program will prompt for the customer first name, last name, account number, and starting balance. The program will cr a BankAccount object. If creating Youth Account, the program will prompt for the same information required to cr a regular account plus the guardian's name, withdraw limit, and account owner age. The program will cr a YouthAccount object. Once the account is crd (Regular or Youth account), the program will call the add_account() method from the AccountsDatabase class to add the account to the database. The program will also call the display_details() method to display the account details.
2. Perform deposit: If selected, the program will prompt for the account number and the deposited. The program will invoke the get_account() method from the AccountsDatabase class - passing in the account number - to get the account. The program will use the deposit() method to update the account balance and transactions. Once the account is updated, the program will call the update_account() method from the AccountsDatabase class to store the updated account
Note: Deposit amount cannot be negative. Do not run the deposit logic if an account does not exist.
3. Perform withdraw: The program will prompt the user for the account number and the amount to withdraw. The program will invoke the get_account() method from the AccountsDatabase class to find the return the account- passing in the account number. The program will use the withdraw() method to debit the account balance and update the transactions list. The updated balance will be displayed.
Note: Amount must be positive. Do not run the debit logic if an account does not exist.
4. Display bank account balance: This option will prompt for the account number. The program will invoke the get_account() method from the AccountsDatabase class - passing in the account number. The program will display the account balance using the display_balance() method.
Note: Do not run the display balance logic if an account does not exist.
5. Display transactions: The program prompt for the account number. The program will invoke the get_account() method from the AccountsDatabase class - passing in the account number. The program will use the display_transactions() method to display all transactions for the account.
Note: Do not run the display transactions logic if an account does not exist.
6. Search for an account: The program will prompt for the account number and invoke the search_account() method from the AccountsDatabase class to find and display the account.
7. Delete account: The program will prompt for the account number and invoke the delete_account() from the AccountsDatabase class to delete the account.
8. Display total accounts: The program will invoke the display_total_accounts() method from the AccountsDatabase class and display the total number of objects.
9. Display all accounts: The program will invoke the display_all_accounts() method from the AccountsDatabase class
10. Exit: The program will wr all accounts details to a file (accounts_datails.txt), display a goodbye message and exit
Include the following in your program:
1. Youth Account and Accounts Database modules are imported into the bank account client module.
2. Accounts Database module is imported into the bank account client module and object of the AccountsDatabase class is crd.
3. BankAccount or YouthAccount object is crd based on the user selection 2pt.
4. Newly crd account is added to the accounts database 2pts.
5. Get Account method (from the AccountsDatabase class) is called when appropriate. Object return by the method is stored and used correctly 2pts.
6. Search accounts
7. while loop is used with the menu options
8. Program includes menu options for each banking operation. Each menu option is functional.
a. cr a customer bank account.
b. Perform deposit.
c. Perform withdraw!
d. Display bank account balance
e. Display transactions
f. Search account searches and display the account 2pts.
g. Delete Account deletes the accounts 2pts
h. Display total number of accounts displays count 2pts.
i. Display accounts displays details for all accounts 2pts.
j. Exit. wrs the accounts details to file and exits the program 2.5pts.
9. BankAccount Class
a. Contains constructor with the correct number of parameters and initialization logic. 1pt
b. Properties crd for instance variables 2pts.
c. deposit(): method correctly updates the balance and transactions list
d. withdraw(): method correctly updates the balance and transactions list
e. display_transactions(): displays each transaction on a separate line. Deposit lines preceded by "Deposit:". Withdraws lines preceded by "Withdraw:"
f. display_balance(): Displays the balance accurately
g. display_details(): Displays the account details correctly
h. Dunder str and repr are crd for the class. 2pts
10. YouthAccount Class
a. Constructor contains the correct code and parameters 2pts.
b. Instance variables are crd and initialized correctly 1pts.
c. Properties are crd for instance variables 2pts.
d. Dunder str and repr are crd for the class 2.5pts.
11. AccountsDatabase class
a. Constructor crd with correct code and parameters 2pts.
b. search_account(): contains correct code 2.5pts
c. delete_account(): contains correct code 2pts
d. get_account(): contains correct code that gets and returns the account 2pts.
e. display_total_accounts(): contains correct code 2pts
f. display_accounts(): contains correct code 2pts
homewrk 2 code for bank_account_client
from bank_account import BankAccount
def create_account(): while True: first_name = input("Enter first name: ") last_name = input("Enter last name: ") account_number = input("Enter account number that must be at least 5 digits): ") if len(account_number) < 5 or not first_name or not last_name: print("Invalid account details.") else: try: starting_balance = float(input("Enter starting balance: ")) if starting_balance < 0: print("Starting balance must be positive!") else: account = BankAccount(first_name, last_name, starting_balance, account_number) print("Account created successfully!") account.display_details() return account except ValueError: print("Starting balance must be a valid number.")
def perform_deposit(account): if not account: print("No account exists!") return while True: try: deposit_amount = float(input("Enter deposit amount: ")) if deposit_amount < 0: print("Deposit amount must be positive.") else: account.deposit(deposit_amount) print("Deposit successful. Your updated balance is:") account.display_balance() break except ValueError: print("Deposit amount must be a valid number.")
def perform_withdraw(account): if not account: print("No account exists. Please cre account first.") return while True: try: withdraw_amount = float(input("Enter withdraw amount: ")) if withdraw_amount < 0: print("Withdraw amount must be positive.") elif withdraw_amount > account.account_balance: print("Withdraw amount cannot be greater than account balance. Please try again.") else: account.withdraw(withdraw_amount) print("Withdraw successful. Updated balance:") account.display_balance() break except ValueError: print("Withdraw amount must be a valid number. Please try again.")
def display_balance(account): if not account: print("No account exists. Please cre account first.") else: account.display_balance()
def display_transactions(account): if not account: print("No account exists. Please cre account first.") else: account.display_transactions()
def display_menu(): print(" Bank Account Menu:") print("1. Create customer bank account") print("2. Perform account deposit") print("3. Perform account withdraw") print("4. Display account balance") print("5. Display transactions") print("6. Exit")
def main(): account = None while True: display_menu() choice = input("Enter your choice: ") if choice == '1': account = create_account() elif choice == '2': perform_deposit(account) elif choice == '3': perform_withdraw(account) elif choice == '4': display_balance(account) elif choice == '5': display_transactions(account) elif choice == '6': print("Thank you have a nice day!") break else: print("Invalid choice.")
if __name__ == '__main__': main() homework 2 code for bank_account
class BankAccount: def __init__(self, first_name, last_name, starting_balance, account_number): self.first_name = first_name self.last_name = last_name self.account_balance = starting_balance self.account_number = account_number self.transactions = []
def deposit(self, deposit_amount): if deposit_amount < 0: print("Deposit amount cannot be negative.") else: self.account_balance += deposit_amount self.transactions.append(("Deposit", deposit_amount))
def withdraw(self, withdraw_amount): if withdraw_amount < 0: print("Withdraw amount cannot be negative.") elif withdraw_amount > self.account_balance: print("Insufficient funds.") else: self.account_balance -= withdraw_amount self.transactions.append(("Withdraw", withdraw_amount))
def display_transactions(self): if not self.transactions: print("No transactions.") else: for transaction in self.transactions: print(f"{transaction[0]}: {transaction[1]}")
def display_balance(self): print(f"Current balance: {self.account_balance}")
def display_details(self): print(f"Account owner: {self.first_name} {self.last_name}") print(f"Account number: {self.account_number}") print(f"Current balance: {self.account_balance}")
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill