-
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 #59
base: jmn/master
Are you sure you want to change the base?
Wave 3 #59
Changes from all commits
b79bdfe
8a3641f
7267a0d
cdbd578
e0d00be
e3227df
7b8cbc9
f6dd3e8
ea664de
e1cdc2d
a21b14a
a3a89da
e1ed3be
fe6b90f
054a156
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 |
---|---|---|
|
@@ -6,13 +6,15 @@ | |
module Bank | ||
|
||
class Account | ||
@@min_balance = 0 | ||
|
||
attr_reader :balance, :owner, :open_date, :ident | ||
|
||
def initialize(ident, balance, open_date) | ||
def initialize(ident, open_date, balance) | ||
@ident = ident | ||
@balance = balance | ||
raise ArgumentError.new("Your intial balance can't be negative") if balance < 0 | ||
@open_date = DateTime.strptime(open_date, '%Y-%m-%d %H:%M:%S %z') | ||
@balance = balance | ||
raise ArgumentError.new("Insufficient initial balance") if balance < @@min_balance | ||
end | ||
|
||
def self.all | ||
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 job using the 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 job using the account and owner methods to drive your ultimate list functionality as well |
||
|
@@ -53,8 +55,8 @@ def assign_to_owner(person) # pass in an instance of Owner | |
end | ||
|
||
def withdraw(withdraw_amount) | ||
if @balance - withdraw_amount < 0 | ||
puts "Insufficient funds. Withdraw denied." | ||
if @balance - withdraw_amount < @@min_balance | ||
puts "Insufficient new balance. Withdraw denied." | ||
@balance | ||
else | ||
@balance -= withdraw_amount | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require "./bank-accounts.rb" | ||
require "./savings-account.rb" | ||
require "./checking-account.rb" | ||
require "./money-market.rb" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Bank | ||
class CheckingAccount < Account | ||
attr_reader :used_checks | ||
|
||
def initialize(ident, open_date, balance) | ||
super | ||
@used_checks = 0 | ||
end | ||
|
||
def withdraw(withdraw_amount) | ||
super(withdraw_amount + 100) | ||
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! Awesome use of the original account method to take care of this functionality for you |
||
end | ||
|
||
def withdraw_using_check(amount) | ||
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 use of the |
||
if @balance - amount < -1000 | ||
puts "Insufficient new balance. Check denied." | ||
@balance | ||
else | ||
@used_checks += 1 | ||
if @used_checks > 3 | ||
@balance = @balance - amount - 200 | ||
else | ||
@balance -= amount | ||
end | ||
end | ||
end | ||
|
||
def reset_checks | ||
@used_checks = 0 | ||
end | ||
|
||
|
||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
module Bank | ||
class MoneyMarketAccount < Account | ||
attr_reader :transactions_permitted, :transaction_count, :balance | ||
|
||
@@min_balance = 1000000 | ||
|
||
def initialize(ident, open_date, balance) | ||
super | ||
@transaction_count = 0 | ||
@transactions_permitted = true # this only refers to minimum balance concerns, not to transaction count | ||
end | ||
|
||
def withdraw(withdraw_amount) | ||
if @balance - withdraw_amount < 0 # balance can never go negative | ||
puts "Insufficient new balance. Withdraw denied." | ||
@balance | ||
elsif @balance - withdraw_amount < @@min_balance && @transactions_permitted | ||
@transactions_permitted = false | ||
@balance = @balance - withdraw_amount - 10000 | ||
elsif | ||
@transaction_count < 6 && @transactions_permitted | ||
@transaction_count += 1 | ||
@balance -= withdraw_amount | ||
else | ||
@balance | ||
end | ||
end | ||
|
||
def deposit(deposit_amount) | ||
if !@transactions_permitted | ||
@balance += deposit_amount | ||
if @balance >= @@min_balance | ||
@transactions_permitted = true | ||
@balance | ||
else | ||
@transactions_permitted = false | ||
@balance | ||
end | ||
elsif @transaction_count < 6 | ||
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. You use the max transaction count of 6 in a few different places so this may be a good place to sue a constant |
||
@transaction_count += 1 | ||
@balance += deposit_amount | ||
else | ||
@balance | ||
end | ||
end | ||
|
||
def reset_transaction_count | ||
@transaction_count = 0 | ||
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,16 @@ | ||
module Bank | ||
class SavingsAccount < Account | ||
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! The minimal amount of code you have here shows that you used the inheritance concept quite well |
||
@@min_balance = 1000 | ||
|
||
def withdraw(withdraw_amount) | ||
super(withdraw_amount + 200) | ||
end | ||
|
||
def add_interest(rate) | ||
interest = @balance * rate/100 | ||
@balance += 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.
I like that you used a separate variable for this! It's great to keep it separate