-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bank.py
96 lines (82 loc) · 3.67 KB
/
Bank.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# Bank that manages a dictionary of Account objects
from Account import *
class Bank():
def __init__(self, hours, address, phone):
self.accountsDict = {}
self.nextAccountNumber = 0
self.hours = hours
self.address = address
self.phone = phone
def askForValidAccountNumber(self):
accountNumber = input('What is your account number? ')
try:
accountNumber = int(accountNumber)
except ValueError:
raise AbortTransaction('The account number must be an integer')
if accountNumber not in self.accountsDict:
raise AbortTransaction('There is no account ' + str(accountNumber))
return accountNumber
def getUsersAccount(self):
accountNumber = self.askForValidAccountNumber()
oAccount = self.accountsDict[accountNumber]
self.askForValidPassword(oAccount)
return oAccount
def askForValidPassword(self, oAccount):
password = input('Please enter your password: ')
oAccount.checkPasswordMatch(password)
def createAccount(self, theName, theStartingAmount, thePassword):
oAccount = Account(theName, theStartingAmount, thePassword)
newAccountNumber = self.nextAccountNumber
self.accountsDict[newAccountNumber] = oAccount
# Increment to prepare for next account to be created
self.nextAccountNumber = self.nextAccountNumber + 1
return newAccountNumber
def openAccount(self):
print('*** Open Account ***')
userName = input('What is your name? ')
userStartingAmount = input('How much money to start your account ? ')
userPassword = input('What password would you like to use for this account? ')
userAccountNumber = self.createAccount(userName, userStartingAmount, userPassword)
print('Your new account number is:', userAccountNumber)
def closeAccount(self):
print('*** Close Account ***')
userAccountNumber = self.askForValidAccountNumber()
oAccount = self.accountsDict[userAccountNumber]
self.askForValidPassword(oAccount)
theBalance = oAccount.getBalance()
print('You had', theBalance, 'in your account, which is being returned to you.')
del self.accountsDict[userAccountNumber]
print('Your account is now closed.')
def balance(self):
print('*** Get Balance ***')
oAccount = self.getUsersAccount()
theBalance = oAccount.getBalance()
print('Your balance is:', theBalance)
def deposit(self):
print('*** Deposit ***')
oAccount = self.getUsersAccount()
depositAmount = input('Please enter amount to deposit: ')
theBalance = oAccount.deposit(depositAmount)
print('Deposited:', depositAmount)
print('Your new balance is:', theBalance)
def withdraw(self):
print('*** Withdraw ***')
oAccount = self.getUsersAccount()
userAmount = input('Please enter the amount to withdraw: ')
theBalance = oAccount.withdraw(userAmount)
print('Withdrew:', userAmount)
print('Your new balance is:', theBalance)
def getInfo(self):
print('Hours:', self.hours)
print('Address:', self.address)
print('Phone:', self.phone)
print('We currently have', len(self.accountsDict), 'account(s) open.')
# Special method for Bank administrator only
def show(self):
print('*** Show ***')
print('(This would typically require an admin password)')
for userAccountNumber in self.accountsDict:
oAccount = self.accountsDict[userAccountNumber]
print('Account:', userAccountNumber)
oAccount.show()
print()