The BankAccount class in bankaccount.py
The assignment involves writing python program in three python files namely the bankaccount.py, main.py and testbankaccount.py.
bankaccount.py:
The code in bankaccount.py defines the class named BankAccount. The class is defined with multiple function like deposit_funds(), withdraw_funds() etc. to perform the transaction with the bank account.
The structure of the class is defined asThe account_number member stores the account number of the bank account The pin_number member stores the pin number of the bank account The balance member stores the current balance of the bank account The interest_rate stores the interest rate of the account The transcation_list is the list of twin tuple, which stores the list of transactions performed in the account. On performing withdraw it is stored for example as (“Deposit”, 300.0) or (“Withdrawal”, 100.0).
The deposit_funds member function is used to deposit the amount passed as parameter to the bank account. Before adding the amount to balance the amount is converted to float. If the amount is not valid an exception is thrown.
The withdraw_funds member function is used to withdraw the specified amount passed as parameter from the bank account. Before reducing the amount from balance, the amount is converted to float. If the amount is not valid an exception is thrown. It is also checked that the amount is less than the available balance in the account. If it conflicts the exception is raised.
The get_transaction_string member function is used to convert the tuples in the transcation_list to string with one line specifying the transaction type and the next line denoting the amount involved in the transaction.
The save_to_file() is used to save the account information to the file whose filename is same as the account number. In the file the first line specifies the account number, second line specifies the pin number, third the balance and fourth the interest rate and finally it appends the string from get_transaction_string
testbankaccount.py
The code in testbankaccount.py is the unit test code. It tests the functions of class in the bankaccount.py. The code contains the function that tests the working of the deposit_funds and withdraw_funds of the BankAccount class. The deposit_funds() is tested with valid and invalid amount. The withdraw_funds() is tested with the valid and invalid amount and with valid amount greater and lesser the available balance
main.py:
The code in main.py is the driver program for the GUI interface and for performing action specified by the user through GUI.
On executing the program, the main.py displays the Login screen similar to one shown below
The design of the login screen is defined in the create_login_screen(). The window is designed with the Grid structure. Then the labels and buttons are created and placed in their respective position. The buttons are used to enter the pin number and the number is added to the pin entry via the handle_pin_button() function. On clicking the cancel/clear button is used to clear the entries in the pin field this task is performed in the clear_pin_entry().
The user on clicking the Login in button calls the log_in(). In the log_in(), the particular account file is specified via the account_number is opened, and the pin details are read and then the entered pin number are checked against the pin number specified in the file. If it matches the account screen is how to the user. If the specified account file does not exist or if the pin number is not matched appropriate error message is displayed via the message box.
The account screen is displayed to the user via the create_account_screen(). The account screen is shown as below
It is noted that the account screen is also a grid structure with 5 rows and 5 columns. The balance label is updated dynamically on performing the transactions whereas the other labels are static. The Deposit button on clicking calls the perform_deposit() which calls the deposit_funds() of the account class. On clicking the withdraw button calls the withdraw_funds () of the account class. In case if any exception is raised in these two-function appropriate error message is displayed. On successful completion of the transaction appropriate balance and transaction details are updated. On clicking the log out button the transactions are written back to the file using the save_to_file () of the account class and the login screen is displayed.