ReadingTransactions/123456.txt
123456
7890
1000
0.33
Deposit
300
Deposit
800
Withdrawal
200
ReadingTransactions
eading_transactions.py
# NOTE: Put a '123456.txt' bank account file in the same directory as this script.
# XXXXXXXXXXFinding transactions - version 1 ----------
''' Because we know the format of the file, we can read the entire thing and
then do a little counting to figure out how many transactions we have. '''
account_file = open('123456.txt', 'r') # Open the file
file_lines = account_file.readlines() # Read the contents into a list of lines
account_file.close() # Close the file
num_lines = len(file_lines) # How many lines do we have?
num_transactions = (num_lines - 4)
2 # The first 4 lines are account details, every other 'pair' is a transaction
# Print account details
print('Account Number:', file_lines[0])
print('Pin Number :', file_lines[1])
print('Balance :', file_lines[2])
print('Interest Rate :', file_lines[3])
# Print transaction details, starting from line 4 and 'moving in steps of 2'
for loop in range(4, num_lines, 2):
trans_type = file_lines[loop]
trans_amount = file_lines[loop+1]
print('Transaction: {} - {}'.format(trans_type, trans_amount))
# --------------------------------------------------------------------
print()
print('*' * 50) # Waka-waka-waka-waka....
print()
# --------------------------------------------------------------------
# XXXXXXXXXXFinding transactions - version 2 ----------
''' Another way we can do this is to use our knowledge of the file format and
read the first four lines then just KEEP ON READING lines until we fail
to read another line. '''
account_file = open('123456.txt', 'r')
# Get the four known properties
account_number = account_file.readline()
account_pin = account_file.readline()
account_balance = account_file.readline()
account_interest = account_file.readline()
print(account_number)
print(account_pin)
print(account_balance)
print(account_interest)
# Loop to read lines from the file
while True:
XXXXXXXXXXline = account_file.readline() # Attempt to read a line
XXXXXXXXXXif not line: # If we failed, then exit
XXXXXXXXXXprint('End of file!')
eak
# If we did NOT fail, then the 'line' we read will be the transaction
# type, so the line below it will be the transaction amount.
XXXXXXXXXXamount = account_file.readline()
XXXXXXXXXXprint('Transaction:', line, amount)
# Always close your file to release file handles and associated resources
account_file.close()
# --------------------------------------------------------------------
# IMPORTANT
# --------------------------------------------------------------------
# Notice that this program prints each line separated by a blank line...
# This is because we read in the line from the file, and the line that
# we read INCLUDES the '\n' or 'new line' character. To strip this from
# the input you can use [:-1] as the 'substring' - which means "go from
# the beginning up to but NOT including the very last character".
#
# For example, print(account_number) will print precisely:
#
# 123456
# <---- This is an empty line because of the '\n'
#
# While calling print(account_number[:-1]) will print precisely:
#
# 123456
# [No blank line here because we did not include it when we printed the line]
ITECH1400_Assignment_2/123456.txt
123456
7890
5000.0
0.33
Deposit
3000.0
Deposit
4000.0
Withdrawal
2000.0
ITECH1400_Assignment_2
ankaccount.py
class BankAccount():
def __init__(self):
'''Constructor to set account_number to '0', pin_number to an empty string,
XXXXXXXXXXbalance to 0.0, interest_rate to 0.0 and transaction_list to an empty list.'''
def deposit_funds(self, amount):
'''Function to deposit an amount to the account balance. Raises an
XXXXXXXXXXexception if it receives a value that cannot be cast to float.'''
def withdraw_funds(self, amount):
'''Function to withdraw an amount from the account balance. Raises an
XXXXXXXXXXexception if it receives a value that cannot be cast to float. Raises
XXXXXXXXXXan exception if the amount to withdraw is greater than the available
XXXXXXXXXXfunds in the account.'''
def get_transaction_string(self):
'''Function to create and return a string of the transaction list. Each transaction
XXXXXXXXXXconsists of two lines - either the word "Deposit" or "Withdrawal" on
XXXXXXXXXXthe first line, and then the amount deposited or withdrawn on the next line.'''
def save_to_file(self):
'''Function to overwrite the account text file with the cu
ent account
XXXXXXXXXXdetails. Account number, pin number, balance and interest (in that
XXXXXXXXXXprecise order) are the first four lines - there are then two lines
XXXXXXXXXXper transaction as outlined in the above 'get_transaction_string'
XXXXXXXXXXfunction.'''
ITECH1400_Assignment_2/ITECH1400_Assignment_2_FedUni_Banking.pdf
ITECH1400 – Foundations of Programming
School of Science, Engineering and Information Technology
CRICOS Provider No. 00103D Page 1 of 10
ITECH1400 - Assignment 2 – FedUni Banking
Due Date: 5pm, Friday of Week 11
This assignment will test your skills in designing and programming applications to specification and is worth
20% of your non-invigilated (type A) marks for this course. This is an INDIVIDUAL ASSIGNMENT – and while
you may discuss it with your fellow students, you must not share designs or code or you will be in
each of
the university plagiarism rules. This assignment should take you approximately 20 hours to complete.
Assignment Overview
You are tasked with creating an application that uses a GUI that simulates a simple banking interface similar to
an ATM / online banking using the Python 3 programming language.
The assignment is
oken up into five main components:
1.) The ability to provide an account number and a PIN
(Personal Identification Number) to sign into a bank
account,
2.) The ability to view the balance of the bank account and
to deposit and withdraw virtual money into and out
from the account,
3.) The ability to save transactions via file storage so that
you can log in, deposit some money and then log out –
and when you log back in that money is still there, and
finally
4.) The ability to display a graph of projected earnings on
the bank account via the compound interest accrued
over a variable amount of time.
5.) A Test Case that ensures your BankAccount's deposit and withdraw functionality operates co
ectly.
Your submission should consist of three Python scripts that implement this application as described in the
following pages: bankaccount.py, main.py along with a testbankaccount.py which contains a small test case
with a few simple unit tests than ensure that your bank accounts deposit_funds and withdraw_funds methods
operate co
ectly.
You are provided with a 'stub' of each of these files which contain all the function declarations and comments
which describe the role of the function and how it can be put together, but you will have to write the code for
vast majority of the functions yourself. You are also provided with a stub of the bankaccounttestcase.py file.
Your final submission should be a zipped archive (i.e. ‘zip file’) containing your completed Python scripts.
There is no word processed component to this second assignment.
ITECH1400 – Foundations of Programming
School of Science, Engineering and Information Technology
CRICOS Provider No. 00103D Page 2 of 10
Bank Account Class Design
The design for a BankAccount object is laid out in the following class diagram:
As you might imagine, the deposit_funds(amount) function adds that money to the cu
ent balance of the
account, and the withdraw_funds(amount) function removes (i.e. subtracts) money from the cu
ent balance
of the account. Each transaction in the transaction_list is a tuple containing either the word Deposit or the word
Withdrawal followed by an amount, for example: ("Deposit", XXXXXXXXXXor ("Withdrawal", 100.0).
The bank accounts in our program do not have an overdraft facility so the user cannot withdraw money they
do not have – that is, if they had $200 in their account and they tried to withdraw more than $200 then the
operation should fail and the withdraw_funds function should raise an Exception with a suitable e
or message
which is caught and displayed in the main.py file where the operation was attempted.
All e
or messages such as those from exceptions should be displayed in a pop-up messagebox.
The get_transaction_string method should loop over all the transactions in the transaction_list creating a string
version (with newline characters) of all the transactions associated with the account.
The save_to_file function should save the account_number, pin_number, balance, and interest_rate in that
order to a file called
.txt followed by the transaction list string generated from the
get_transaction_string() method. The name of the account file is NOT '
.txt' - the name of
the file is the ACTUAL ACCOUNT NUMBER followed by ".txt", so for an account with account_number 123456
the name of the account file would be 123456