Answer To: A Python program that simulates an ATM. GUI interface that prompts for a User Id and PIN. The...
Aditya answered on Dec 07 2021
import tkinter
from tkinter import *
from tkinter import messagebox
import time
import random
accountInformation = []
# defines the class BankAccount
def name_class_time():
print("\nIan Fordyce")
print("CIS 110 Program 10")
print(time.asctime(time.localtime(time.time())))
print()
name_class_time()
class BankAccount:
# defining account instance variables.
def __init__(self,userID, pin, savingBalance, checkingBalance ):
self.userID = userID
self.pin = pin
self.savingBalance = savingBalance
self.checkingBalance = checkingBalance
def getUserID(self):
return self.userID
def getPin(self):
return self.pin
def getSavingBalance(self):
return self.savingBalance
def getCheckingBalance(self):
return self.checkingBalance
# class function to calculate difference between the balance and the amount withdrawn.
def withdrawSavingBalance(self, amount):
self.savingBalance -= amount
def withdrawCheckingBalance(self, amount):
self.checkingBalance -= amount
def setSavingBalance(self, amount):
self.savingBalance = amount
def setCheckingBalance(self, amount):
self.checkingBalance = amount
# class function to calculate the sum between the balance and the amount deposited.
def depositSaving(self, amount):
self.savingBalance += amount
def depositChecking(self, amount):
self.checkingBalance += amount
def writeFile(self):
return str(self.userID)+','+str(self.pin)+','+str(self.savingBalance)+','+str(self.checkingBalance)
# class function to return the account balance
# class function to determine the balance transfer
def transfer(self, amount, ID):
self.total = self.balance - amount
ID.balance = ID.balance + amount
return ID.balance()
def updateAccount(bankAccount):
for i in accountInformation:
if i.getUserID() == bankAccount.userID:
i.setSavingBalance(bankAccount.getSavingBalance())
i.setCheckingBalance(bankAccount.getCheckingBalance())
break
def readDataFromFile():
rd = open("bankAcoountData.txt", "r")
bankData = []
while True:
line = rd.readline()
if not line:
break;
data = line.split(",")
userID = int(data[0])
pin = int(data[1])
savingBalance = float(data[2])
checkingBalance = float(data[3])
account = BankAccount(userID, pin, savingBalance, checkingBalance)
bankData.append(account)
rd.close()
return bankData
def writeToFile():
file = open('bankAcoountData.txt', 'w')
for i in accountInformation:
file.write(i.writeFile())
file.write('\n')
file.close()
accountInformation = readDataFromFile()
def login():
root = tkinter.Tk()
root.title("ATM")
root.wm_minsize(250, 200)
def close():
writeToFile()
root.destroy()
def checkAccount():
try:
userID = int(userIDtextBox.get())
pin = int(pinTextBox.get())
found = 0
for i in accountInformation:
if i.getUserID() == userID and i.getPin() == pin:
root.destroy()
mainScreen(i)
found = found + 1
break
if found == 0:
tkinter.messagebox.showerror('ATM', 'Incorrect Credentials')
userIDtextBox.delete(0, "end")
userIDtextBox.insert(0, "")
pinTextBox.delete(0, "end")
pinTextBox.insert(0, "")
except ValueError:
tkinter.messagebox.showerror('ATM', 'Incorrect Format Enter Digits Only')
userIDtextBox.delete(0, "end")
userIDtextBox.insert(0, "")
pinTextBox.delete(0, "end")
pinTextBox.insert(0, "")
userIDlabel = tkinter.Label(text="Enter User ID: ", width=25)
userIDlabel.grid(column=0, row=0, padx=10, pady=10)
userIDtextBox = tkinter.Entry(width=25, relief="raised")
userIDtextBox.grid(column=1, row=0, padx=10, pady=10)
pinLabel = tkinter.Label(text="Enter PIN: ", width=25)
pinLabel.grid(column=0, row=1, padx=10, pady=10)
pinTextBox = tkinter.Entry(width=25, relief="raised")
pinTextBox.grid(column=1, row=1, padx=10, pady=10)
exitbutton = tkinter.Button(text="Exit", command=close, width=15, relief="raised")
exitbutton.grid(column=0, row=6, padx=10, pady=10)
checkbutton = tkinter.Button(text="Enter", command=checkAccount, width=15, relief="raised")
checkbutton.grid(column=1, row=6, padx=10, pady=10, sticky=W)
root.mainloop()
def mainScreen(bankAccount):
root = tkinter.Tk()
root.title("ATM")
root.wm_minsize(400, 150)
def...