-
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
Wave 3 Bank Accounts #57
base: erg/master
Are you sure you want to change the base?
Changes from all commits
b79bdfe
727ab55
da785da
b61e8ae
55a79d4
1fa4f42
ac85c88
5b06c7f
8e5508c
4c38e8e
eadcaca
96671b8
0370adb
09a2ddf
ccd7afc
d3dc103
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 |
---|---|---|
|
@@ -5,6 +5,9 @@ module Bank | |
|
||
class Account | ||
|
||
MIN_BALANCE = 0 | ||
FEE = 0 | ||
|
||
attr_reader :balance, :owner, :account_id | ||
|
||
def initialize(account_id, initial_balance, open_date) | ||
|
@@ -14,8 +17,8 @@ def initialize(account_id, initial_balance, open_date) | |
end | ||
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. Nice! Using your gem knowledge 👍 |
||
|
||
def withdraw(amount) | ||
if amount <= @balance | ||
@balance -= amount | ||
if amount <= @balance - self.class::MIN_BALANCE - self.class::FEE | ||
@balance -= (amount + self.class::FEE) | ||
else | ||
puts "Your balance is #{@balance}. You cannot withdraw #{amount} at this time." | ||
return @balance | ||
|
@@ -27,8 +30,8 @@ def deposit(amount) | |
end | ||
|
||
def check_initial_balance(initial_balance) | ||
if initial_balance < 0 | ||
raise ArgumentError.new("Your initial balance must be positive!") | ||
if initial_balance < self.class::MIN_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. Awesome awesome awesome awesome |
||
raise ArgumentError.new("Your initial balance must be more than #{self.class::MIN_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. YES! |
||
else | ||
return initial_balance | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Bank | ||
|
||
class CheckingAccount < Account | ||
|
||
FEE = 100 | ||
|
||
def initialize (account_id, initial_balance, open_date) | ||
super | ||
@free_check = 3 | ||
end | ||
|
||
def withdraw_using_check(amount) | ||
if @free_check > 0 | ||
check_fee = 0 | ||
else | ||
check_fee = 200 | ||
end | ||
|
||
if (amount + check_fee) <= (@balance + 1000) | ||
@balance -= (amount + check_fee) | ||
@free_check -= 1 | ||
else | ||
puts "Your account cannot overdraft by more than 1000. Your balance is #{@balance} so you cannot write a check for #{amount} at this time." | ||
end | ||
return @balance | ||
end | ||
|
||
def reset_checks | ||
@free_check = 3 | ||
end | ||
|
||
|
||
|
||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module Bank | ||
|
||
class MoneyMarketAccount < SavingsAccount | ||
|
||
MIN_BALANCE = 1000000 | ||
|
||
attr_reader :transaction_count | ||
|
||
def initialize (account_id, initial_balance, open_date) | ||
super | ||
@transaction_count = 0 | ||
end | ||
|
||
def withdraw(amount) | ||
if account_frozen? || transaction_count_exceeded? | ||
return @balance | ||
elsif amount <= @balance - self.class::MIN_BALANCE | ||
@balance -= amount | ||
else | ||
@balance -= (amount + 10000) | ||
end | ||
@transaction_count += 1 | ||
return @balance | ||
end | ||
|
||
def deposit(amount) | ||
if transaction_count_exceeded? | ||
return @balance | ||
elsif account_frozen? && (@balance + amount) >= self.class::MIN_BALANCE | ||
else | ||
@transaction_count += 1 | ||
end | ||
super | ||
end | ||
|
||
def account_frozen? | ||
@balance < self.class::MIN_BALANCE | ||
end | ||
|
||
def transaction_count_exceeded? | ||
@transaction_count >= 6 | ||
end | ||
|
||
def reset_transactions | ||
@transaction_count = 0 | ||
end | ||
|
||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Bank | ||
|
||
class SavingsAccount < Account | ||
|
||
MIN_BALANCE = 1000 | ||
FEE = 200 | ||
|
||
def initialize (account_id, initial_balance, open_date) | ||
super | ||
end | ||
|
||
def add_interest(rate) | ||
interest = @balance * (rate/100) | ||
@balance += interest | ||
return interest | ||
end | ||
|
||
|
||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require "./BankAccounts.rb" | ||
require "./SavingsAccount.rb" | ||
require "./CheckingAccount.rb" | ||
require "./MoneyMarketAccount.rb" |
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.
Yes! nice constants!