Skip to content

Commit 62c55fb

Browse files
committed
almost done
1 parent 6637498 commit 62c55fb

File tree

1 file changed

+32
-17
lines changed

1 file changed

+32
-17
lines changed

code/Andy/python/andy_lab10_atm_v1.py

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ class ATM:
22
def __init__(self, balance_arg = 0, intrest_rate_arg = .001): #positional arguments. a method. a more flexable way to do it
33
self.balance = balance_arg #balance_arg are local varable
44
self.intrest_rate = intrest_rate_arg
5-
5+
self.transactions = []
6+
7+
68
# def __init__(self): #positional arguments. a method
79
# self.balance = 0 one way to do it
810
# self.intrest_rate = .001
@@ -12,15 +14,25 @@ def check_balance(self): # going into self to retrieve balance from what you hav
1214

1315
def deposit(self, amount):
1416
self.balance += amount
17+
self.transactions.append(f'user deposited {amount}')
18+
1519

1620
def check_withdrawal(self, amount): #using self to get balance and amount since thats what we're checking
1721
if self.balance >= amount:
1822
return True
1923
else:
2024
return False
25+
2126
def withdraw(self, amount):
22-
self.balance -= amount
27+
self.balance -= amount
28+
self.transactions.append(f'user withdrew {amount}')
2329

30+
def calc_interest(self):
31+
interest = self.balance * self.intrest_rate * .01
32+
return interest
33+
34+
def print_transactions(self):
35+
print(self.transactions)
2436

2537

2638
# atm = ATM(5, .001) #putting the values for the initializer.its an object
@@ -51,18 +63,21 @@ def withdraw(self, amount):
5163
print(f'Withdrew ${amount}')
5264
else:
5365
print('Insufficient funds')
54-
# elif command == 'interest':
55-
# amount = atm.calc_interest() # call the calc_interest() method
56-
# atm.deposit(amount)
57-
# print(f'Accumulated ${amount} in interest')
58-
# elif command == 'help':
59-
# print('Available commands:')
60-
# print('balance - get the current balance')
61-
# print('deposit - deposit money')
62-
# print('withdraw - withdraw money')
63-
# print('interest - accumulate interest')
64-
# print('exit - exit the program')
65-
# elif command == 'exit':
66-
# break
67-
# else:
68-
# print('Command not recognized')
66+
elif command == 'interest':
67+
amount = atm.calc_interest() # call the calc_interest() method
68+
atm.deposit(amount)
69+
print(f'Accumulated ${amount} in interest')
70+
elif command == "transactions":
71+
atm.print_transactions()
72+
elif command == 'help':
73+
print('Available commands:')
74+
print('balance - get the current balance')
75+
print('deposit - deposit money')
76+
print('withdraw - withdraw money')
77+
print('interest - accumulate interest')
78+
print('transactions - view transactions')
79+
print('exit - exit the program')
80+
elif command == 'exit':
81+
break
82+
else:
83+
print('Command not recognized')

0 commit comments

Comments
 (0)