Skip to content

Commit 9ac0c98

Browse files
authored
Merge pull request #139 from PdxCodeGuild/daniel-lab10-atm
Daniel lab10 atm
2 parents 930218b + aa6583d commit 9ac0c98

File tree

1 file changed

+156
-0
lines changed

1 file changed

+156
-0
lines changed

code/daniel/lab10-atm/lab10-atm.py

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#=====================================================
2+
#Version1
3+
#=====================================================
4+
5+
6+
# class ATM:
7+
8+
# def __init__(self, balance=0, interest_rate=.001):
9+
# self.balance = balance
10+
# self.interest_rate = interest_rate
11+
12+
# def check_balance(self):
13+
# return self.balance
14+
15+
# def deposit(self, amount):
16+
# self.balance += amount
17+
18+
# def check_withdraw(self, amount):
19+
# if self.balance - amount >= 0:
20+
# return True
21+
# else:
22+
# return False
23+
24+
# def withdraw(self, amount):
25+
# self.balance -= amount
26+
27+
# def calc_interest(self):
28+
# return self.balance * self.interest_rate
29+
30+
31+
# #=======================
32+
33+
34+
# atm = ATM() # create an instance of our class
35+
# print('Welcome to the ATM')
36+
# while True:
37+
# command = input('Enter a command: ')
38+
# if command == 'balance':
39+
# balance = atm.check_balance() # call the check_balance() method
40+
# print(f'Your balance is ${balance}')
41+
# elif command == 'deposit':
42+
# amount = float(input('How much would you like to deposit? '))
43+
# atm.deposit(amount) # call the deposit(amount) method
44+
# print(f'Deposited ${amount}')
45+
# elif command == 'withdraw':
46+
# amount = float(input('How much would you like? '))
47+
# if atm.check_withdraw(amount): # call the check_withdrawal(amount) method
48+
# atm.withdraw(amount) # call the withdraw(amount) method
49+
# print(f'Withdrew ${amount}')
50+
# else:
51+
# print('Insufficient funds')
52+
# elif command == 'interest':
53+
# amount = atm.calc_interest() # call the calc_interest() method
54+
# atm.deposit(amount)
55+
# print(f'Accumulated ${amount} in interest')
56+
# elif command == 'help':
57+
# print('Available commands:')
58+
# print('balance - get the current balance')
59+
# print('deposit - deposit money')
60+
# print('withdraw - withdraw money')
61+
# print('interest - accumulate interest')
62+
# print('exit - exit the program')
63+
# elif command == 'exit':
64+
# break
65+
# else:
66+
# print('Command not recognized')
67+
68+
69+
#=====================================================
70+
#Version2
71+
#=====================================================
72+
73+
74+
class ATM:
75+
76+
def __init__(self, balance=0, interest_rate=.001):
77+
self.balance = balance
78+
self.interest_rate = interest_rate
79+
self.transactions = []
80+
81+
def check_balance(self):
82+
return self.balance
83+
84+
def deposit(self, amount):
85+
self.balance += amount
86+
self.transactions.append(f'User deposited ${amount}')
87+
88+
def check_withdraw(self, amount):
89+
if self.balance - amount >= 0:
90+
return True
91+
else:
92+
return False
93+
94+
def withdraw(self, amount):
95+
self.balance -= amount
96+
self.transactions.append(f'User withdrew ${amount}')
97+
98+
def calc_interest(self):
99+
return self.balance * self.interest_rate
100+
101+
def print_transactions():
102+
return self.transactions
103+
104+
105+
#=======================
106+
107+
108+
atm = ATM() # create an instance of our class
109+
print('Welcome to the ATM')
110+
while True:
111+
command = input('Enter a command: ')
112+
if command == 'balance':
113+
balance = atm.check_balance() # call the check_balance() method
114+
print(f'Your balance is ${balance}')
115+
elif command == 'deposit':
116+
amount = float(input('How much would you like to deposit? '))
117+
atm.deposit(amount) # call the deposit(amount) method
118+
print(f'Deposited ${amount}')
119+
elif command == 'withdraw':
120+
amount = float(input('How much would you like? '))
121+
if atm.check_withdraw(amount): # call the check_withdrawal(amount) method
122+
atm.withdraw(amount) # call the withdraw(amount) method
123+
print(f'Withdrew ${amount}')
124+
else:
125+
print('Insufficient funds')
126+
elif command == 'interest':
127+
amount = atm.calc_interest() # call the calc_interest() method
128+
atm.deposit(amount)
129+
print(f'Accumulated ${amount} in interest')
130+
elif command == 'transactions':
131+
for transaction in atm.transactions:
132+
print(f'${transaction}')
133+
elif command == 'help':
134+
print('Available commands:')
135+
print('balance - get the current balance')
136+
print('deposit - deposit money')
137+
print('withdraw - withdraw money')
138+
print('interest - accumulate interest')
139+
print('exit - exit the program')
140+
elif command == 'exit':
141+
break
142+
else:
143+
print('Command not recognized')
144+
145+
146+
147+
148+
149+
150+
151+
152+
153+
154+
155+
156+

0 commit comments

Comments
 (0)