Design and Implementation of a Banking System (1) ANISH assignment

docx

School

Federation University *

*We aren’t endorsed by this school

Course

2002

Subject

Computer Science

Date

Oct 30, 2023

Type

docx

Pages

16

Uploaded by MasterSummer4547

Report
NIT5150 – Advanced Object- Oriented Programming STUDENT NAME: ANISH SHARMA NATH STUDENT ID: s8106903 0
Introduction In the world's financial system, the banking industry is essential. A strong and adaptable banking system is needed to effectively manage numerous account types, including current accounts, deposit accounts, limited accounts, and overdraft accounts. The design and implementation of a banking system in Python that takes into consideration the various types of accounts and their functionality are shown in this study. Problem Analysis and Design Considerations This project's goal was to create and put into operation a banking system that could manage various account types, including current accounts, deposit accounts, restricted accounts, and accounts with overdraft facilities. The following were the main design considerations: Establishing a class hierarchy to represent different sorts of accounts. Using polymorphism to enable consistent management of various account types. Offering menu-driven user interface for user interaction. A table-format display of account information to enhance user experience. Preserving account data to a file in order to ensure data permanence. 1
UML Class Diagram The basic class is called account, and it has standard characteristics like name, account number, and amount. Subclasses, which sprang from the Account class and included particular features and behaviours, were CurrentAccount, DepositAccount, RestrictedAccount, and OverdraftAccount. The Bank class has methods for adding, removing, depositing, and locating accounts while managing a list of accounts. Figure 1: Class Diagram of Bank Implementation of Account Classes Each sort of account was developed as a Python class. Withdrawals and deposits were handled via the 'Account' class's fundamental functionality, which was expanded by subclasses to accommodate particular needs. As an illustration, the 'CurrentAccount' class added a chequebook capability, and the 'DepositAccount' class added interest rates. class CurrentAccount(Account): 2
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
class CurrentAccount ( Account ): def __init__ ( self , name , account_number , balance ): super (). __init__ ( name , account_number , balance ) self . cheque_book = self . generate_cheque_book () def generate_cheque_book ( self ): # Generate a random chequebook of 10 random characters return '' . join ( random . choices ( string . ascii_uppercase + string . digits , k = 10 )) class DepositAccount(Account): class DepositAccount ( Account ): def __init__ ( self , name , account_number , balance , withdrawal_limit , interest_rate ): super (). __init__ ( name , account_number , balance ) self . withdrawal_limit = withdrawal_limit self . interest_rate = interest_rate class RestrictedAccount(CurrentAccount): class RestrictedAccount ( CurrentAccount ): def __init__ ( self , name , account_number , balance , max_withdrawal_limit ): super (). __init__ ( name , account_number , balance ) self . max_withdrawal_limit = max_withdrawal_limit def withdraw ( self , amount ): if amount <= self . balance and amount <= self . max_withdrawal_limit : self . balance -= amount return f "Withdrawal successful. Remaining balance: { self . balance } " else : return "Withdrawal limit exceeded or insufficient funds." class OverdraftAccount(CurrentAccount): class OverdraftAccount ( CurrentAccount ): def __init__ ( self , name , account_number , balance , overdraft_limit ): super (). __init__ ( name , account_number , balance ) self . overdraft_limit = overdraft_limit def withdraw ( self , amount ): if amount <= self . balance + self . overdraft_limit : self . balance -= amount 3
return f "Withdrawal successful. Remaining balance: { self . balance } " else : return "Withdrawal amount exceeds overdraft limit." Polymorphism in Action Polymorphism is one of the important design ideas we used in our approach. We can treat objects with various account types consistently thanks to polymorphism. Any account type is accepted by the 'withdraw_from_account' method in the 'Bank' class, which then runs the proper 'withdraw' function based on the account type. def withdraw_from_account ( self , account_number , amount ): account = self . find_account ( account_number ) if account : return account . withdraw ( amount ) else : return "Account not found." def deposit_to_account ( self , account_number , amount ): account = self . find_account ( account_number ) if account : return account . deposit ( amount ) else : return "Account not found." …. Difficulties Polymorphism Implementation It was difficult to implement polymorphism to handle various account types. It needed creating a flexible framework so that the Bank class could easily interact with any sort of account. To get around this problem, careful design and attention to object-oriented concepts were required. User Interface 4
While adding more code for input validation and error handling was necessary, creating a user-friendly menu-driven interface was crucial. It was difficult to maintain a positive customer experience while managing different account activities. Solutions Polymorphism Each account type was inherited from the main Account class, which offered a uniform interface for withdrawals and deposits, to support polymorphism. Any account type could be used using the withdraw_from_account method in the Bank class, which is called the appropriate withdraw method based on the actual account type. User Interface We overcame the user interface difficulty by developing a simple menu system that led users through various financial processes. The user experience was improved with the implementation of input validation and error alerts. Testing Testing Account Operations To ensure that account transactions were done correctly, we performed rigorous testing. This involved setting up various sorts of accounts, making deposits and withdrawals, ensuring that interest rates and withdrawal limitations were properly applied, and confirming that account balances had been updated accurately. 5
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Show Account Information We checked to make sure the table-based display of account information functioned as planned. This required making sure the table structure was aesthetically pleasing and that the account types, account numbers, names, and balances were all accurate. 6
Data Retention By utilizing the pickle module to save account data to a file and confirming that accounts could be loaded from the file upon program restart, data durability was confirmed. Account data was appropriately serialized and deserialized, according to this verification. 7
Conclusion The objectives and requirements of the project were effectively satisfied in the design and execution of the banking system. Polymorphism was used to streamline the code and make it flexible. The usability of the user interface was enhanced, and data persistence made sure that account information was kept even when the software was closed. Overall, this project successfully used the principles of object-oriented design, producing a practical and user-friendly financial system. Appendix: import pickle import random import string from prettytable import PrettyTable class Account: def __init__(self, name, account_number, balance): self.name = name self.account_number = account_number self.balance = balance def withdraw(self, amount): if amount <= self.balance: self.balance -= amount return f"Withdrawal successful. Remaining balance: {self.balance}" else: return "Insufficient funds." 8
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
def deposit(self, amount): self.balance += amount return f"Deposit successful. New balance: {self.balance}" class CurrentAccount(Account): def __init__(self, name, account_number, balance): super().__init__(name, account_number, balance) self.cheque_book = self.generate_cheque_book() def generate_cheque_book(self): # Generate a random checkbook of 10 random characters return ''.join(random.choices(string.ascii_uppercase + string.digits, k=10)) class DepositAccount(Account): def __init__(self, name, account_number, balance, withdrawal_limit, interest_rate): super().__init__(name, account_number, balance) self.withdrawal_limit = withdrawal_limit self.interest_rate = interest_rate def withdraw(self, amount): if amount <= self.balance and amount <= self.withdrawal_limit: self.balance -= amount return f"Withdrawal successful. Remaining balance: {self.balance}" else: return "Withdrawal limit exceeded or insufficient funds." class RestrictedAccount(CurrentAccount): def __init__(self, name, account_number, balance, max_withdrawal_limit): super().__init__(name, account_number, balance) self.max_withdrawal_limit = max_withdrawal_limit 9
def withdraw(self, amount): if amount <= self.balance and amount <= self.max_withdrawal_limit: self.balance -= amount return f"Withdrawal successful. Remaining balance: {self.balance}" else: return "Withdrawal limit exceeded or insufficient funds." class OverdraftAccount(CurrentAccount): def __init__(self, name, account_number, balance, overdraft_limit): super().__init__(name, account_number, balance) self.overdraft_limit = overdraft_limit def withdraw(self, amount): if amount <= self.balance + self.overdraft_limit: self.balance -= amount return f"Withdrawal successful. Remaining balance: {self.balance}" else: return "Withdrawal amount exceeds overdraft limit." class Bank: def __init__(self): self.accounts = [] def add_account(self, account): self.accounts.append(account) def find_account(self, account_number): for account in self.accounts: if account.account_number == account_number: return account return None 10
def withdraw_from_account(self, account_number, amount): account = self.find_account(account_number) if account: return account.withdraw(amount) else: return "Account not found." def deposit_to_account(self, account_number, amount): account = self.find_account(account_number) if account: return account.deposit(amount) else: return "Account not found." def save_accounts_to_file(accounts, filename): with open(filename, 'wb') as file: pickle.dump(accounts, file) def load_accounts_from_file(filename): try: with open(filename, 'rb') as file: accounts = pickle.load(file) return accounts except FileNotFoundError: return [] def display_account_table(accounts): table = PrettyTable() table.field_names = ["Account Type", "Account Number", "Name", "Balance"] for account in accounts: 11
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
table.add_row([type(account).__name__, account.account_number, account.name, account.balance]) return table def display_account_by_name(accounts, name): found_accounts = [account for account in accounts if account.name == name] if found_accounts: table = PrettyTable() table.field_names = ["Account Type", "Account Number", "Name", "Balance"] for account in found_accounts: table.add_row([type(account).__name__, account.account_number, account.name, account.balance]) return table else: return "No accounts found with that name." if __name__ == "__main__": bank = Bank() filename = "accounts.pkl" # File to save account information # Load accounts from file if available bank.accounts = load_accounts_from_file(filename) while True: print("\nBanking System Menu:") print("1. Add Account") print("2. Withdraw from Account") print("3. Deposit to Account") 12
print("4. Display Accounts") print("5. Display Account by Name") print("6. Save Accounts to File") print("7. Exit") choice = input("Enter your choice: ") if choice == '1': account_type = input("Enter account type (Current/Deposit/Restricted/Overdraft): ") name = input("Enter account holder name: ") account_number = input("Enter account number: ") balance = float(input("Enter initial balance: ")) if account_type == 'Current': account = CurrentAccount(name, account_number, balance) elif account_type == 'Deposit': withdrawal_limit = float(input("Enter withdrawal limit: ")) interest_rate = float(input("Enter interest rate: ")) account = DepositAccount(name, account_number, balance, withdrawal_limit, interest_rate) elif account_type == 'Restricted': max_withdrawal_limit = float(input("Enter max withdrawal limit: ")) account = RestrictedAccount(name, account_number, balance, max_withdrawal_limit) elif account_type == 'Overdraft': overdraft_limit = float(input("Enter overdraft limit: ")) account = OverdraftAccount(name, account_number, balance, overdraft_limit) else: print("Invalid account type.") continue 13
bank.add_account(account) print("Account added successfully.") elif choice == '2': account_number = input("Enter account number: ") amount = float(input("Enter withdrawal amount: ")) result = bank.withdraw_from_account(account_number, amount) print(result) elif choice == '3': account_number = input("Enter account number: ") amount = float(input("Enter deposit amount: ")) result = bank.deposit_to_account(account_number, amount) print(result) elif choice == '4': print("\n--- All Accounts ---") print(display_account_table(bank.accounts)) elif choice == '5': search_name = input("Enter account holder name to search: ") search_result = display_account_by_name(bank.accounts, search_name) print(search_result) elif choice == '6': # Save accounts to a file save_accounts_to_file(bank.accounts, filename) print("Accounts saved to file.") elif choice == '7': break 14
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
else: print("Invalid choice. Please choose a valid option.") 15

Browse Popular Homework Q&A

Q: What are the premises and conclusion of the following argument? "If x = 9, then x + 4 = 13."…
Q: 150 125 100 75+ 50 1 25
Q: Identify the relational keys for each table. List each relational key in a separate line. Candidate…
Q: 2. For F(x, y, z) = (6xsin y+10x=' )i + (3x² cos y-4ye* −2y²z³)j + (-2y³e² +15x²2²)k, find a…
Q: Organotin compounds play a significant role in diverse industrial applications. They have been used…
Q: 2. Use the method of undetermined coefficients in section 3.5 to find the form of a particular…
Q: Find the vertex, focus, and directrix for the parabola. (y + 3)2 = 8(x − 2) Vertex:…
Q: A semicircular gate with a diameter of 6 ft is installed at 50º as shown below. The top of the gate…
Q: 2-Sided CI, a 95, Sample Average  100, Population St Dev, s    5,  15…
Q: Describe the similarities between risk transfer and risk sharing.
Q: To induce a current in a wire coil, a magnet must be spinning at rest moving O strong
Q: 2 3
Q: C. Logarithmic on one side 6. log, x+log,2(x-3)=2 D. Logarithmic on both sides. 7. In(3x+8) =…
Q: A foreign key is the candidate key that is selected to identify tuples. True or False.
Q: What is the approximate concentration of free Al³+ ion at equilibrium when 1.86x10-² mol aluminum…
Q: a. $600 interest from a savings account at a Florida bank. b. $5,000 dividend from U.S. Flower…
Q: 7. Solve the system of equations. You may use any method (elimination, substitution, matrices,…
Q: Solve the system by back substitution. -4x-8y-2z - 6w = -5 -5y-30z-10w = -40 - 5z-5w = - 10 - 5w=…
Q: 5 m 5 m A D G H 0.6 m B 0.2 m E 0.4 m C F 12 kN 6 kN
Q: Give an
Q: and
Q: reater than 30, the Poisson distribution begins to be very similar to the normal with both a mean…