-
Notifications
You must be signed in to change notification settings - Fork 0
/
bank_system.py
executable file
·294 lines (249 loc) · 10.6 KB
/
bank_system.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
from customer import Customer
from admin import Admin
from account import Account
from person import Person
import pickle
customers_list = []
admins_list = []
class BankSystem(object):
def __init__(self):
self.customers_list = []
self.admins_list = []
self.load_bank_data()
def load_bank_data(self):
customer_1 = Customer("Adam", "1234", ["14", "Wilcot Street", "Bath", "B5 5RT"])
account_no = 1234
account_1 = Account(5000.00, account_no)
customer_1.open_account(account_1)
self.customers_list.append(customer_1)
customer_2 = Customer("David", "password", ["60", "Holborn Viaduct", "London", "EC1A 2FD"])
account_no+=1
account_2 = Account(3200.00,account_no)
customer_2.open_account(account_2)
self.customers_list.append(customer_2)
customer_3 = Customer("Alice", "MoonLight", ["5", "Cardigan Street", "Birmingham", "B4 7BD"])
account_no+=1
account_3 = Account(18000.00,account_no)
customer_3.open_account(account_3)
self.customers_list.append(customer_3)
customer_4 = Customer("Ali", "150A",["44", "Churchill Way West", "Basingstoke", "RG21 6YR"])
account_no+=1
account_4 = Account(40.00,account_no)
customer_4.open_account(account_4)
self.customers_list.append(customer_4)
admin_1 = Admin("Julian", "1441", True, ["12", "London Road", "Birmingham", "B95 7TT"])
self.admins_list.append(admin_1)
admin_2 = Admin("Eva", "2222", False, ["47", "Mars Street", "Newcastle", "NE12 6TZ"])
self.admins_list.append(admin_2)
def customer_login(self, name, password):
#STEP A.1
found_customer = self.search_customers_by_name(name)
if found_customer == None:
return("\n The customer has not been found! \n")
else:
if (found_customer.check_password(password)==True):
self.run_customer_options(found_customer)
else:
return("You have input a wrong password")
#pass
def search_customers_by_name(self, customer_name):
#STEP A.2
found_customer = None
for a in self.customers_list:
name = a.get_name()
if name == customer_name:
found_customer = a
break
if found_customer == None:
print("\n The customer %s does not exist! Try again... \n"%customer_name)
return found_customer
#pass
def main_menu(self):
#print the options you have
print()
print()
print ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print ("Welcome to the Python Bank System")
print ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print ("1) Admin login")
print ("2) Customer login")
print ("3) Quit Python Bank System")
print (" ")
option = int(input ("Choose your option: "))
return option
def run_main_option(self):
loop = 1
while loop == 1:
choice = self.main_menu()
if choice == 1:
name = input ("\nPlease input admin name: ")
password = input ("\nPlease input admin password: ")
msg = self.admin_login(name, password)
print(msg)
elif choice == 2:
name = input ("\nPlease input customer name: ")
password = input ("\nPlease input customer password: ")
msg = self.customer_login(name, password)
print(msg)
elif choice == 3:
loop = 0
print ("Thank-You for stopping by the bank!")
def transferMoney(self, sender_account, receiver_name, receiver_account_no, amount):
pass
#-------------Customer Section-----------#
def customer_menu(self, customer_name):
#print the options you have
print (" ")
print ("Welcome %s : Your transaction options are:" %customer_name)
print ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print ("1) Transfer money")
print ("2) Other account operations")
print ("3) profile settings")
print ("4) Sign out")
print (" ")
option = int(input ("Choose your option: "))
return option
def run_customer_options(self, customer):
account = customer.get_account()
loop = 1
while loop == 1:
choice = self.customer_menu(customer.get_name())
if choice == 1:
customer_name =input ('Please enter recipents\'s name >> ')
trans_amount = float(input('How much do you wan to transfer? >> '))
toCustomer = self.search_customers_by_name(customer_name)
transferToAccount = toCustomer.get_account()
account.withdraw(trans_amount)
transferToAccount.deposit(trans_amount)
print("Transfer Complete")
transferToAccount.print_balance()
elif choice == 2:
account.run_account_options()
elif choice == 3:
customer.run_profile_options()
elif choice == 4:
loop = 0
print ("Exit account operations")
def admin_login(self, name, password):
# STEP A.3
found_admin = self.search_admin_by_name(name)
if found_admin == None:
return("\n The administrator has not been found! \n")
else:
if (found_admin.check_password(password)==True):
self.run_admin_options(found_admin)
else:
return("You have input a wrong password")
#pass
def search_admin_by_name(self, admin_name):
# STEP A.4
found_admin = None
for a in self.admins_list:
name = a.get_name()
if name == admin_name:
found_admin = a
break
if found_admin == None:
print("\n The admin %s does not exist! Try again... \n"%admin_name)
return found_admin
#pass
def search_customer_by_name(self, customer_name):
# STEP A.4
found_customer = None
for a in self.customers_list:
name = a.get_name()
if name == customer_name:
found_customer = a
break
if found_customer == None:
print("\n The admin %s does not exist! Try again... \n"%customer_name)
return found_customer
#pass
def admin_menu(self, admin_name):
#print the options you have
print (" ")
print ("Welcome Admin %s : Avilable options are:" %admin_name)
print ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print ("1) Transfer money")
print ("2) Customer account operations")
print ("3) Customer profile settings")
print ("4) Admin profile settings")
print ("5) Delete customer")
print ("6) Print all customers detail")
print ("7) Sign out")
print (" ")
option = int(input ("Choose your option: "))
return option
def run_admin_options(self, admin):
loop = 1
while loop == 1:
choice = self.admin_menu(admin.get_name())
if choice == 1:
sender = input("\nPlease input sender's name :\n")
senderName = self.search_customers_by_name(sender)
send = senderName.get_account()
customer_name =input ('Please enter recipents\'s name >> ')
trans_amount = float(input('How much do you wan to transfer? >> '))
toCustomer = self.search_customers_by_name(customer_name)
transferToAccount = toCustomer.get_account()
send.withdraw(trans_amount)
transferToAccount.deposit(trans_amount)
print("Transfer Complete")
transferToAccount.print_balance()
elif choice == 2:
#STEP A.5
customer_name = input("\nPlease input customer name : \n")
customer = self.search_customer_by_name(customer_name)
if customer != None:
account= customer.get_account()
if account != None:
account.run_account_options()
#pass
elif choice == 3:
#STEP A.6
customer_name = input("\nPlease input customer name :\n")
customer = self.search_customers_by_name(customer_name)
if customer != None:
customer.run_profile_options()
#pass
elif choice == 4:
#STEP A.7
admin.run_profile_options()
#pass
elif choice == 5:
#STEP A.8
if admin.has_full_admin_right() == True:
customer_name = input("\nPlease input customer name you want to delete :\n")
customer_account = self.search_customers_by_name(customer_name)
if customer_account != None:
self.customers_list.remove(customer_account)
print("\nCustomer had been deleted\n")
else:
print("\nOnly administrators with full admin rights can remove a customer from the bank system!\n")
#pass
elif choice == 6:
#STEP A.9
self.print_all_accounts_details()
#pass
elif choice == 7:
loop = 0
print ("Exit account operations")
def print_all_accounts_details(self):
# list related operation - move to main.py
i = 0
for c in self.customers_list:
i+=1
print('\n %d. ' %i, end = ' ')
c.print_details()
print("------------------------")
def call (self):
pickle_in = open("data.file","rb")
self.customers_list = pickle.load(pickle_in)
def save (self):
pickle_out = open("data.file","wb")
pickle.dump(self.customers_list, pickle_out)
pickle_out.close()
app = BankSystem()
app.call()
app.run_main_option()
app.save()