Answer To: ITECH1400 – Foundations of Programming School of Science, Engineering and Information Technology...
Tanya answered on Sep 26 2020
Assignment_2/__pycache__/bankaccount.cpython-36.pyc
Assignment_2/1.txt
1
1
2584.0
('Withdraw\n', '87.0\n', 'Deposit\n', '87.0\n', 'Deposit\n', '87.0\n', 'Withdraw\n', '87.0\n', 'Deposit\n', '87.0\n', 'Deposit\n', '87.0\n')
Assignment_2/123456.txt
123456
7890
5195.0
('Deposit\n', '65.0\n', 'Deposit\n', '65.0\n', 'Deposit\n', '65.0\n')
Assignment_2/bankaccount.py
from tkinter import messagebox
class BankAccount():
def __init__(self):
'''Constructor to set account_number to '0', pin_number to an empty string,
balance to 0.0, interest_rate to 0.0 and transaction_list to an empty list.'''
self.account_number = 0
self.pin_number = ""
self.balance = 0.0
interest_rate =0.0
self.transaction_list = [None]
def deposit(self, amount):
'''Function to deposit an amount to the account balance. Raises an
exception if it receives a value that cannot be cast to float.'''
try:
#print(balance)
#amount1 = (float)(amount)
self.balance = (float)(self.balance) + (float)(amount)
#messagebox.showinfo("Final Balance Now ", (str)(self.balance))
except Exception as e:
messagebox.showinfo("Exception", e)
def withdraw(self, amount):
'''Function to withdraw an amount from the account balance. Raises an
exception if it receives a value that cannot be cast to float. Raises
an exception if the amount to withdraw is greater than the available
funds in the account.'''
if((float)(amount) < self.balance):
self.balance = (self.balance) - (float)(amount)
else:
messagebox.showinfo("Exception", "Amount to be withdrwan cannot be greater than Balance")
def get_transaction_string(self):
'''Function to create and return a string of the transaction list. Each transaction
consists of two lines - either the word "Deposit" or "Withdrawal" on
the first line, and then the amount deposited or withdrawn on the next line.'''
return self.transaction_list
def export_to_file(self):
'''Function to overwrite the account text file with the current account
details. Account number, pin number, balance and interest (in that
precise order) are the first four lines - there are then two lines
per transaction as outlined in the above 'get_transaction_string'
function.'''
self.account_number = self.account_number.strip('\n')
f = open((str)(self.account_number) + ".txt", "w")
f.write((str)(self.account_number)+ "\n" )
f.write((str)(self.pin_number)+ "\n")
f.write((str)(self.balance)+ "\n")
#f.write((str)(self.interest_rate))
f.write((str)(self.transaction_list)+ "\n")
#f.write(self.account_number)
Assignment_2/FedUni Banking.mp4
Microsoft Game DVR
FedUni Banking
Assignment_2/main.py
import tkinter as tk
from pathlib import Path
from tkinter import *
from tkinter import messagebox
from tkinter.scrolledtext import ScrolledText
from pylab import plot, show, xlabel, ylabel
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
from bankaccount import BankAccount
win = tk.Tk()
win.title("FedUni Banking")
win.geometry("440x640")
# Set window size here to '440x640' pixels
# Set window title here to 'FedUni Banking'
# The account number entry and associated variable
account_number_var = tk.StringVar()
account_number_entry = tk.Entry(win, textvariable=account_number_var)
account_number_entry.focus_set()
# The pin number entry and associated variable.
# Note: Modify this to 'show' PIN numbers as asterisks (i.e. **** not 1234)
pin_number_var = tk.StringVar()
account_pin_entry = tk.Entry(win, text='PIN Number', textvariable=pin_number_var)
# The balance label and associated variable
balance_var = tk.StringVar()
balance_var.set('Balance: $0.00')
balance_label = tk.Label(win, textvariable=balance_var)
# The Entry widget to accept a numerical value to deposit or withdraw
amount_entry = tk.Entry(win)
# The transaction text widget holds text of the accounts transactions
transaction_text_widget = tk.Text(win, height=10, width=48)
# The bank account object we will work with
account = BankAccount()
# ---------- Button Handlers for Login Screen ----------
def clear():
clear_pin_entry('Button-1')
def clear_pin_entry(event):
'''Function to clear the PIN number entry when the Clear / Cancel button is clicked.'''
# Clear the pin number entry here
account_pin_entry.delete(0, END)
def handle_pin_button(event):
'''Function to add the number of the button clicked to the PIN number entry via its associated variable.'''
if len(account_number_entry.get()) < 4:
account_number_entry.insert(END, event)
# Limit to 4 chars in length
elif len(account_pin_entry.get()) < 4:
account_pin_entry.focus()
account_pin_entry.insert(END, event)
def log():
log_in('Button-1')
def log_in(event):
'''Function to log in to the banking system using a known account number and PIN.'''
global pin_num
global account_num
global interest_rate
#global balance
transaction_list = ()
#print(account_number_var.get())
my_file = Path(account_number_var.get()+".txt")
# Create the filename from the entered account number with '.txt' on the end
if my_file.is_file():
# Try to open the account file for reading
# Open the account file for reading
f = open(my_file)
# First line is account number
account_num = f.readline()
# Second line is PIN number, raise exceptionk if the PIN entered doesn't match account PIN
pin_num = f.readline()
pin_num = pin_num.strip('\n')
if(pin_number_var.get() != pin_num):
messagebox.showinfo("ErrorMessage", "The Pin Number you entered is incorrect")
f.close()
create_login_screen()
return
else:
account.account_number = account_num
account.pin_number = pin_num
# Read third and fourth lines (balance and interest rate)
account.balance = f.readline()
interest_rate = f.readline()
# Section to read account transactions from file
while True:
# Attempt to read a line from the account file, break if we've hit the end of the file. If we
# read a line then it's the transaction type, so read the next line which will be the transaction amount.
# and then create a tuple from both lines and add it to the account's transaction_list
a = (f.readline(),)
b =...