@@ -2,7 +2,9 @@ class ATM:
2
2
def __init__ (self , balance_arg = 0 , intrest_rate_arg = .001 ): #positional arguments. a method. a more flexable way to do it
3
3
self .balance = balance_arg #balance_arg are local varable
4
4
self .intrest_rate = intrest_rate_arg
5
-
5
+ self .transactions = []
6
+
7
+
6
8
# def __init__(self): #positional arguments. a method
7
9
# self.balance = 0 one way to do it
8
10
# self.intrest_rate = .001
@@ -12,15 +14,25 @@ def check_balance(self): # going into self to retrieve balance from what you hav
12
14
13
15
def deposit (self , amount ):
14
16
self .balance += amount
17
+ self .transactions .append (f'user deposited { amount } ' )
18
+
15
19
16
20
def check_withdrawal (self , amount ): #using self to get balance and amount since thats what we're checking
17
21
if self .balance >= amount :
18
22
return True
19
23
else :
20
24
return False
25
+
21
26
def withdraw (self , amount ):
22
- self .balance -= amount
27
+ self .balance -= amount
28
+ self .transactions .append (f'user withdrew { amount } ' )
23
29
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 )
24
36
25
37
26
38
# atm = ATM(5, .001) #putting the values for the initializer.its an object
@@ -51,18 +63,21 @@ def withdraw(self, amount):
51
63
print (f'Withdrew ${ amount } ' )
52
64
else :
53
65
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