forked from karan/Projects
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathbank_account_manager.py
301 lines (228 loc) · 11 KB
/
bank_account_manager.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
295
296
297
298
299
300
301
"""
Title: Bank Account Manager ATM
Author: Ryan Gilera
"""
class Account:
def __init__(self, cust_id):
self.cust_id = cust_id
class CheckingAccount(Account):
def __init__(self, cust_id, deposit_amount):
Account.__init__(self, cust_id)
self.amount = deposit_amount
self.withdraw_whole = 0
self.withdraw_part = 0
# returns a string, formatted up to 2 decimal places
self.numstr = "%.2f" % deposit_amount
# pulls the whole number from amount as integer
self.amount_whole = int(self.numstr[:self.numstr.find('.')])
# pulls the decimal value from amount as integer
self.amount_part = int(self.numstr[self.numstr.find('.') + 1:])
def deposit(self, deposit_amount):
self.amount += deposit_amount
def withdraw(self, withdraw_amount):
# debugging purposes only
# print "self whole", self.amount_whole
# print "self part", self.amount_part
# separates the whole number from decimal number of the amount to withdraw
self.withdraw_whole = int(withdraw_amount[:withdraw_amount.find('.')])
numstr = str(withdraw_amount)
self.withdraw_part = int(numstr[numstr.find('.') + 1:])
# debugging purposes only
# print "whole", self.withdraw_whole
# print "part", self.withdraw_part
# if the amount in the account is greater than the requested amount,
# then it is allowed to withdraw that amount
if self.amount > float(withdraw_amount):
self.amount_whole -= self.withdraw_whole
# if the decimal value of requested amount is greater than the
# decimal value of the amount in the account, then 1 dollar is taken out
# and then calculates the remaining decimal value
if self.withdraw_part > self.amount_part:
self.amount_part = self.withdraw_part - self.amount_part
self.amount_whole -= 1
self.amount_part = 100 - self.amount_part
else:
self.amount_part -= self.withdraw_part
# puts back together the whole number and decimal value as one but as a string
new_amount = str(self.amount_whole) + "." + str(self.amount_part)
# debugging purposes only
# print "\nnew whole", self.amount_whole
# print "new part", self.amount_part
# print "new amount", new_amount
# type cast the value back to floating point value
self.amount = round(float(new_amount), 2)
else:
print "Error! Cannot withdraw larger than what you have."
def display_amount(self):
print self.amount
def get_amount(self):
return self.amount
class SavingsAccount(Account):
def __init__(self, cust_id, deposit_amount):
Account.__init__(self, cust_id)
self.amount = deposit_amount
self.withdraw_whole = 0
self.withdraw_part = 0
# returns a string, formatted up to 2 decimal places
self.numstr = "%.2f" % deposit_amount
# pulls the whole number from amount as integer
self.amount_whole = int(self.numstr[:self.numstr.find('.')])
# pulls the decimal value from amount as integer
self.amount_part = int(self.numstr[self.numstr.find('.') + 1:])
def deposit(self, deposit_amount):
self.amount += deposit_amount
def withdraw(self, withdraw_amount):
# debugging purposes only
# print "self whole", self.amount_whole
# print "self part", self.amount_part
# separates the whole number from decimal number of the amount to withdraw
self.withdraw_whole = int(withdraw_amount[:withdraw_amount.find('.')])
numstr = str(withdraw_amount)
self.withdraw_part = int(numstr[numstr.find('.') + 1:])
# debugging purposes only
# print "whole", self.withdraw_whole
# print "part", self.withdraw_part
# if the amount in the account is greater than the requested amount,
# then it is allowed to withdraw that amount
if self.amount > float(withdraw_amount):
self.amount_whole -= self.withdraw_whole
# if the decimal value of requested amount is greater than the
# decimal value of the amount in the account, then 1 dollar is taken out
# and then calculates the remaining decimal value
if self.withdraw_part > self.amount_part:
self.amount_part = self.withdraw_part - self.amount_part
self.amount_whole -= 1
self.amount_part = 100 - self.amount_part
else:
self.amount_part -= self.withdraw_part
# puts back together the whole number and decimal value as one but as a string
new_amount = str(self.amount_whole) + "." + str(self.amount_part)
# debugging purposes only
# print "\nnew whole", self.amount_whole
# print "new part", self.amount_part
# print "new amount", new_amount
# type cast the value back to floating point value
self.amount = round(float(new_amount), 2)
else:
print "Error! Cannot withdraw larger than what you have."
def display_amount(self):
print self.amount
def get_amount(self):
return self.amount
class BusinessAccount(Account):
def __init__(self, cust_id, deposit_amount):
Account.__init__(self, cust_id)
self.amount = deposit_amount
self.withdraw_whole = 0
self.withdraw_part = 0
# returns a string, formatted up to 2 decimal places
self.numstr = "%.2f" % deposit_amount
# pulls the whole number from amount as integer
self.amount_whole = int(self.numstr[:self.numstr.find('.')])
# pulls the decimal value from amount as integer
self.amount_part = int(self.numstr[self.numstr.find('.') + 1:])
def deposit(self, deposit_amount):
self.amount += deposit_amount
def withdraw(self, withdraw_amount):
# debugging purposes only
# print "self whole", self.amount_whole
# print "self part", self.amount_part
# separates the whole number from decimal number of the amount to withdraw
self.withdraw_whole = int(withdraw_amount[:withdraw_amount.find('.')])
numstr = str(withdraw_amount)
self.withdraw_part = int(numstr[numstr.find('.') + 1:])
# debugging purposes only
# print "whole", self.withdraw_whole
# print "part", self.withdraw_part
# if the amount in the account is greater than the requested amount,
# then it is allowed to withdraw that amount
if self.amount > float(withdraw_amount):
self.amount_whole -= self.withdraw_whole
# if the decimal value of requested amount is greater than the
# decimal value of the amount in the account, then 1 dollar is taken out
# and then calculates the remaining decimal value
if self.withdraw_part > self.amount_part:
self.amount_part = self.withdraw_part - self.amount_part
self.amount_whole -= 1
self.amount_part = 100 - self.amount_part
else:
self.amount_part -= self.withdraw_part
# puts back together the whole number and decimal value as one but as a string
new_amount = str(self.amount_whole) + "." + str(self.amount_part)
# debugging purposes only
# print "\nnew whole", self.amount_whole
# print "new part", self.amount_part
# print "new amount", new_amount
# type cast the value back to floating point value
self.amount = round(float(new_amount), 2)
else:
print "Error! Cannot withdraw larger than what you have."
def display_amount(self):
print self.amount
def get_amount(self):
return self.amount
if __name__ == '__main__':
isSessionOn = True
isCustomer = False
def initialise_objects():
global sally_checking, paolo_business, paolo_savings, master_list
sally_checking = CheckingAccount(1, 2567.50)
paolo_savings = SavingsAccount(2, 12890.01)
paolo_business = BusinessAccount(2, 14500.40)
master_list = [[sally_checking, 1, 1], [paolo_savings, 2, 2], [paolo_business, 2, 3]]
return None
initialise_objects()
while isSessionOn is True:
print "Welcome to 24-hour ATM service."
print "Insert your card."
# Card reading the customer info representation
customerID = input("Enter your customer id number: ")
print "\n"
cust_accounts = []
for i in master_list:
if i[1] == customerID:
cust_accounts.append(i[2])
isCustomer = True
if isCustomer is True:
isAccountSelected = False
while isAccountSelected is False:
print "Enter 1 for checking account"
print "Enter 2 for savings account"
print "Enter 3 for business account"
account_type = input("Enter which account to use: ")
if account_type in cust_accounts:
for x in master_list:
if account_type == x[2]:
objectName = x[0]
isAccountSelected = True
isAccountSessionOn = True
while isAccountSessionOn is True:
print "\nHow may I help you?"
print "Press 1 for balance view."
print "Press 2 for withdrawals"
print "Press 3 to exit."
action_value = input("Please enter your choice: ")
if action_value == 1:
objectName.display_amount()
print "\n"
if action_value == 2:
amnt_to_withdraw = input("Enter the amount to withdraw: ")
temp_str = str(amnt_to_withdraw)
adjusted_amount = "%.2f" % amnt_to_withdraw
# print "adjusted_amount:", adjusted_amount
objectName.withdraw(adjusted_amount)
print "current balance is", objectName.get_amount()
print "\n"
if action_value == 3:
isAccountSessionOn = False
print "Thank for using the 24-hour ATM service."
print "Have a pleasant day."
print "\n\n"
print "##########################################"
else:
print "Error. You don't have that account."
print "Please try again.\n"
else:
print "Cannot find your record."
print "Please get your card."
print "Exiting this session..."