-
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 Program #63
base: rrs/master
Are you sure you want to change the base?
Wave 3 Program #63
Changes from all commits
b79bdfe
69d44c2
c9e1d9e
01dbe36
8a3540e
754b98d
6a9a01a
6bdd69f
36e40ab
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,10 +6,14 @@ module Bank | |
class Account | ||
attr_reader :balance, :owner, :account_id, :owner_id | ||
|
||
MIN_BALANCE = 0 | ||
WITHDRAWAL_FEE = 0 | ||
|
||
def initialize (id, initial_balance, open_date) | ||
@account_id = id | ||
raise ArgumentError.new("You can't start an account with a negative balance.") if initial_balance <= 0 | ||
raise ArgumentError.new("That's not enough money to start your account.") 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. Nice job using the class info to retrieve the relevant constant |
||
@balance = initial_balance # in cents | ||
open_date = open_date.to_s | ||
@open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %z") | ||
end | ||
|
||
|
@@ -44,10 +48,10 @@ def withdraw(amount) | |
new_balance = @balance - 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. On line 36 above it seems like you should re-use the |
||
if amount < 0 | ||
puts "You can't withdraw a negative amount." | ||
elsif new_balance < 0 | ||
puts "You don't have that much money. You can withdraw up to #{@balance} dollars." | ||
elsif new_balance < self.class::MIN_BALANCE | ||
puts "You don't have that much money. You can withdraw up to #{@balance - self.class::MIN_BALANCE - self.class::WITHDRAWAL_FEE} cents." | ||
else | ||
@balance = new_balance | ||
@balance = new_balance - self.class::WITHDRAWAL_FEE | ||
return @balance | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module Bank | ||
class CheckingAccount < Account | ||
attr_reader :used_checks, :balance, :account_id, :owner_id | ||
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 don't think you need all of these readers in this class since some of them are already in the |
||
|
||
MIN_BALANCE = 0 | ||
WITHDRAWAL_FEE= 100 | ||
|
||
def initialize(id, initial_balance, open_date) | ||
super | ||
@used_checks = 0 | ||
end | ||
|
||
# The input amount gets taken out of the account as a result of a check withdrawal. Returns the updated account balance. | ||
# Allows the account to go into overdraft up to -$10 but not any lower | ||
# The user is allowed three free check uses in one month, but any subsequent use adds a $2 transaction fee | ||
#reset_checks: Resets the number of checks used to zero | ||
|
||
def withdraw_using_check(amount) | ||
if @used_checks >= 3 | ||
@balance = @balance - 200 | ||
end | ||
new_balance = @balance - amount | ||
raise ArgumentError.new("You don't have enough money for that.") if new_balance <= @balance - 1000 | ||
@used_checks += 1 | ||
@balance = new_balance | ||
end | ||
|
||
def reset_checks | ||
@used_checks = 0 | ||
end | ||
|
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module Bank | ||
|
||
class MoneyMarketAccount < Account | ||
attr_reader :balance, :owner, :account_id, :owner_id, :good_standing, :max_trans | ||
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. Same comment re: |
||
|
||
MIN_BALANCE = 1000000 | ||
|
||
def initialize(id, initial_balance, open_date) | ||
super | ||
@max_trans = 0 | ||
@good_standing = true | ||
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 like that you're using this boolean to track this concept |
||
end | ||
|
||
def withdraw(amount) | ||
new_balance = @balance - amount | ||
if @max_trans >= 6 || @good_standing == false | ||
puts "No more transactions available." | ||
elsif amount < 0 | ||
puts "You can't withdraw a negative amount." | ||
elsif new_balance < self.class::MIN_BALANCE | ||
@balance = @balance - amount - 10000 | ||
@good_standing = false | ||
puts "Next time you need to deposit enough money to bring your account up to #{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. Nice use of this constant! |
||
@max_trans += 1 | ||
elsif new_balance < 0 | ||
puts "That will make your balance negative. Please try a smaller amount." | ||
return @balance | ||
else | ||
@max_trans += 1 | ||
@balance = new_balance | ||
return @balance | ||
end | ||
end | ||
|
||
def deposit(amount) | ||
if @balance < 1000000 | ||
super(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. Since both of these conditionals are doing |
||
else | ||
super(amount) | ||
@max_trans += 1 | ||
end | ||
if @balance > 1000000 | ||
@good_standing == true | ||
end | ||
end | ||
|
||
def reset_transactions | ||
@max_trans | ||
end | ||
|
||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require "./bank.rb" | ||
require "./savings_account.rb" | ||
require "./checking_account.rb" | ||
require "./money_market_account.rb" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
module Bank | ||
|
||
class SavingsAccount < Account | ||
attr_reader :balance, :owner, :account_id, :owner_id | ||
|
||
MIN_BALANCE = 1000 | ||
WITHDRAWAL_FEE = 200 | ||
|
||
def add_interest(rate) | ||
if rate < 0 | ||
puts "Please select a positive interest rate." | ||
else | ||
@interest = @balance * rate/100 | ||
@balance += @interest | ||
return @interest | ||
end | ||
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 constants for this purpose