-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbank.rb
115 lines (102 loc) · 2.96 KB
/
bank.rb
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
class BankAccount
def initialize
@balance = 0.00
puts "What is the first name on this account?"
@first_name = gets.chomp
puts "What is the last name on this account?"
@last_name = gets.chomp
puts "Please deposit money into this account."
@available_credit = 10000.00
@credit_balance = 0.00
end
def deposit(amount)
if amount > 0
@balance = @balance + amount
else
puts "Please enter a positive number."
end
end
def withdraw(amount)
if amount > 0
if @balance < amount
puts "You are attempting to withdraw more funds than you have available. You will be charged a $10 fee."
@balance = @balance - 10.00
puts "Remaining balance: #{@balance}"
else
@balance = @balance - amount
puts "Remaining balance: #{@balance}"
end
else
puts "Please enter a positive number."
end
end
def use_credit_card
puts "What is the purchase amount you would like to put on your credit card?"
purchase = gets.chomp.to_f
if purchase > @available_credit
puts "Decline. Credit available: #{@available_credit}"
else
@credit_balance = @credit_balance + purchase
@available_credit = @available_credit - purchase
puts "Your credit debt is now #{@credit_balance} and your available credit is #{@available_credit}."
end
end
def pay_credit_card_bill
puts "How much would you like to pay to your credit card bill?"
bill_pay = gets.chomp.to_f
if bill_pay < @balance && bill_pay > 0
@balance = @balance - bill_pay
@credit_balance = @credit_balance - bill_pay
@available_credit = @available_credit + bill_pay
elsif bill_pay < 0
puts "Please enter a positive amount."
else
puts "You do not have #{bill_pay} funds available in your account."
end
end
def balance_check
puts "This account belongs to #{@first_name} #{@last_name} and has $#{@balance} available."
puts "You have a balance of $#{@credit_balance} on your credit card and $#{@available_credit} available credit."
end
def interest
accrued_interest = @credit_balance * 0.015
puts "Your interest is #{accrued_interest}"
end
end
#menu
account = BankAccount.new()
command = "active"
while command != "q"
puts "__________________________"
puts "What would you like to do?"
puts "Commands: int = calculate interest"
puts "pay = pay credit card bill."
puts "bc = balance check"
puts "use = use credit card"
puts "dep = deposit"
puts "with = withdraw"
puts "q = quit"
command = gets.chomp.downcase
case command
when command = "pay"
account.pay_credit_card_bill
when command = "int"
account.interest
when command = "bc"
account.balance_check
when command = "use"
account.use_credit_card
when command = "dep"
puts "How much would you like to deposit?"
amount=gets.chomp.to_f
account.deposit(amount)
when command = "with"
puts "How much would you like to withdraw?"
amount=gets.chomp.to_f
account.withdraw(amount)
when "q"
break
else
puts "input not understood"
end
end