Great Deal! Get Instant \$10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

# .

Answered Same Day May 27, 2020 ITECH1400

## Solution

Abr Writing answered on May 31 2020
123456.txt
123456
7890
11000.0
0.33
Deposit
3000.0
Deposit
4000.0
Withdrawal
2000.0
Deposit
4000.0
Deposit
4000.0
Withdrawal
2000.0
testbankaccount.py
import unittest
from bankaccount import BankAccount
class TestBankAcount(unittest.TestCase):
def setUp(self):
# Create a test BankAccount object
self.account = BankAccount()
# Provide it with some property values
self.account.balance = 1000.0
def test_legal_deposit_works(self):
# Your code here to test that depsositing money using the account's
# 'deposit_funds' function adds the amount to the balance.
self.account.deposit_funds(500.0)

def test_illegal_deposit_raises_exception(self):
# Your code here to test that depositing an illegal value (like 'bananas'
# or such - something which is NOT a float) results in an exception being
# raised.
self.account.deposit_funds('bananas')
def test_legal_withdrawal(self):
# Your code here to test that withdrawing a legal amount subtracts the
# funds from the balance.
self.account.withdraw_funds(500.0)

def test_illegal_withdrawal(self):
# Your code here to test that withdrawing an illegal amount (like 'bananas'
# or such - something which is NOT a float) raises a suitable exception.
self.account.withdraw_funds('bananas')
def test_insufficient_funds_withdrawal(self):
# Your code here to test that you can only withdraw funds which are available.
# For example, if you have a balance of 500.00 dollars then that is the maximum
# that can be withdrawn. If you tried to withdraw 600.00 then a suitable exception
# should be raised and the withdrawal should NOT be applied to the account balance
# or the account's transaction list.
self.account.withdraw_funds(10000.0)
# Run the unit tests in the above test case
unittest.main()
ankaccount.py
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
self.interest_rate = 0.0
self.transaction_list = []

def deposit_funds(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:
self.balance += float(amount)
self.transaction_list.append(("Deposit", amount))
except:
raise Exception('Invalid Amount. Try Again.')

def withdraw_funds(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.'''
try:
if float(amount) <= self.balance:
self.balance = self.balance - float(amount)
self.transaction_list.append(("Withdrawal", amount))
else:
raise Exception('Insufficient Money')
except:
raise Exception('Invalid Amount. Try Again.')

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 save_to_file(self):
'''Function to overwrite the account text file with the cu
ent 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.'''
with open(self.account_number+'.txt', 'w') as file:
file.write(self.account_number+'\n')
file.write(self.pin_number+'\n')
file.write(str(self.balance)+'\n')
file.write(str(self.interest_rate)+'\n')
for transaction in self.transaction_list:
file.write(transaction[0]+'\n')
file.write(transaction[1]+'\n')
main.py
import tkinter as tk
from tkinter import messagebox
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()
# Set window size here to '440x640' pixels
win.geometry('440x640')
# Set window title here to 'FedUni Banking'
win.title('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, show='*')
# The balance label and associated variable
alance_var = tk.StringVar()
alance_var.set('Balance: \$0.00')
alance_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_pin_entry(event):
'''Function to clear the PIN number entry when the Clear / Cancel button is clicked.'''
# Clear the pin number entry here
pin_number_var.set(None)
def handle_pin_button(event):
'''Function to add the number of the button clicked to the PIN number entry via its associated variable.'''
# Limit to 4 chars in length
pin_number = account_pin_entry.get()
# Set the new pin number on the...
SOLUTION.PDF