Skip to content

Commit 0b0df06

Browse files
committed
Merge pull request #8 from lacuchilla/arh/master
Arh/master
2 parents 96d9038 + 9d04e45 commit 0b0df06

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

bankaccounttest.rb

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
module Bank
2+
class Account
3+
attr_accessor :account_id, :account_balance, :amount
4+
5+
def initialize(account_id, account_balance = 0)
6+
@account_id = account_id
7+
@account_balance = account_balance.to_i
8+
@amount = amount.to_i
9+
if @account_balance < 0
10+
raise ArgumentError.new("Cannot create a new account with a negative balance")
11+
12+
else
13+
puts "You deposited #{@amount} dollars."
14+
puts "Your new balance is #{@account_balance} dollars."
15+
end
16+
end
17+
18+
def withdraw
19+
puts "Type the amount you would like to withdraw:"
20+
@amount = gets.chomp.to_i
21+
if @account_balance - @amount < 0
22+
puts ("Cannot withdraw an amount that will make the balance negative.")
23+
puts @account_balance
24+
else
25+
@account_balance -= @amount
26+
puts "Your new balance is: #{@account_balance} dollars."
27+
end
28+
end
29+
30+
def deposit
31+
puts "Type the amount you would like to deposit:"
32+
@amount = gets.chomp.to_i
33+
@account_balance += @amount
34+
puts "Your new balance is #{@account_balance} dollars."
35+
end
36+
37+
def balance
38+
puts account_balance
39+
end
40+
41+
end
42+
end
43+
#extra code
44+
45+
46+
47+
# @default_account_amount = 0
48+
# puts "Your default account balance is $0. Please enter the amount you wish to deposit in whole dollars:"
49+
# @user_deposit = gets.chomp
50+
# @integer_user_deposit = @user_deposit.to_i
51+
# if @integer_user_deposit >= 0
52+
# beginning_account_amount = @default_deposit_amount.to_i + @integer_user_deposit
53+
# puts "You deposited #{@integer_user_deposit} dollars."
54+
# puts "Your new balance is #{beginning_account_amount} dollars."
55+
# else
56+
# raise ArgumentError, "Please enter an amount that is greater than zero."
57+
# @user_deposit = gets.chomp
58+
# end

0 commit comments

Comments
 (0)