-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Completed Wave 3 Bank Accounts #58
base: rmt/master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require './BankAccounts.rb' | ||
require './Savings.rb' | ||
require './Checking.rb' | ||
require 'pry' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ def initialize(id, balance, open_date) | |
@id = id | ||
@balance = balance | ||
@open_date = open_date | ||
raise ArgumentError.new("Permission Denied") if balance < "0" | ||
raise ArgumentError.new("Permission Denied") if balance < 0 | ||
end | ||
|
||
# Once a new Owner is created, the variable holding the hash is passed in as 'person parameter' | ||
|
@@ -19,15 +19,18 @@ def assign_owner(person) | |
def withdrawl(amnt_withdrawn) | ||
if amnt_withdrawn > @balance | ||
puts "You can't take out more than #{@balance}" | ||
return @balance | ||
else | ||
@balance = @balance - amnt_withdrawn # Return the updated account balance. | ||
puts "Your current balance is: #{@balance}" # The updated balance | ||
end | ||
return @balance | ||
end | ||
|
||
def deposit(amnt_deposited) | ||
@balance = @balance + amnt_deposited #Return the updated account balance. | ||
puts "Your current balance is: #{@balance}" | ||
return @balance | ||
end | ||
|
||
# This method returns all of the accounts in one array as Account instances. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't comment on the lines below, but I would recommend using a more "useful" variable name rather than |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module Bank | ||
# this will inherit behavior from Account class with '<' | ||
class CheckingAccount < Account | ||
|
||
attr_reader :checks | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you using this attribute to tie to the |
||
def initialize(id, balance, open_date) | ||
super | ||
@checks_used = 0 | ||
end | ||
|
||
def withdrawl(amnt_withdrawn) # add withdrawl functionality | ||
fee_and_withdrawl = amnt_withdrawn + 100 # subtract $2 from balance (add to amnt_withdrawn) | ||
if @balance - fee_and_withdrawl < 0 # Can't go negative. | ||
# Outputs warning and un-modified balance | ||
puts "You can't take out more $$ than you have ($#{@balance})! Don't forget, there is a $1 transaction fee." | ||
return @balance | ||
else | ||
super(fee_and_withdrawl) | ||
end | ||
return @balance | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the |
||
end | ||
|
||
def withdrawl_using_check(amount) | ||
if @checks_used >= 3 # Can use 3 checks for free | ||
check_fee = 200 | ||
else | ||
check_fee = 0 # No fee for less than three checks | ||
@checks_used += 1 | ||
end | ||
if amount + check_fee <= @balance + 1000 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Watch your indentation here - you don't need an additional indent for the second |
||
@balance = @balance - (amount + check_fee) # Input is taken out of balance | ||
puts "Now you have $#{@balance/100} in your account" # so it shows up as dollars, not cents. | ||
else | ||
"We only let you overdraft up to $10. Write a smaller check." | ||
end | ||
return @balance | ||
end | ||
|
||
def reset_checks | ||
@checks_used = 0 | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Bank | ||
# This will inherit behavior from Account class | ||
class SavingsAccount < Account | ||
def initialize(id, balance, open_date) | ||
super | ||
# if initial balance is < $10, raise ArgumentError | ||
raise ArgumentError.new("Not Allowed") if balance < 1000 | ||
end | ||
|
||
def withdrawl(amnt_withdrawn) # add withdrawl functionality | ||
fee_and_withdrawl = amnt_withdrawn + 200 # subtract $2 from balance (add to amnt_withdrawn) | ||
if @balance - fee_and_withdrawl < 1000 # can't leave your account with less than $10 in it | ||
# warning message includes untouched balance. | ||
puts "Don't take out all your money! You gotta keep $10 or more in your savings account. Your balance is #{@balance}." | ||
else | ||
super(fee_and_withdrawl) # if 'if' condition is false, run this | ||
end | ||
end | ||
|
||
def add_interest(rate) | ||
interest = @balance * (rate/100) # Calculate interest on the balance | ||
@balance = @balance + interest # adds interest to balance | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be a good place to use a |
||
# puts the amount earned in a dollar (not cents) format. | ||
puts "You earned a measly $#{interest/100} in interest." | ||
return interest | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice use of the single line conditional