-
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
Bank Accounts Wave 3 + Optional #61
base: dfcp/master
Are you sure you want to change the base?
Changes from all commits
b79bdfe
a69eb2e
adbada6
5947081
7f3283a
0c8a748
18ecd24
5e3b7da
4d4e789
2709c44
d1feeb9
c853854
23ab329
aa012fd
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,18 @@ | ||
require "pry" | ||
require "./bankaccounts.rb" | ||
require "./savings.rb" | ||
require "./checking.rb" | ||
require "./moneymarket.rb" | ||
|
||
|
||
|
||
# Savings Account tests | ||
# s = Bank::SavingsAccount.new("1212","10000","1999-03-27 11:30:09 -0800") | ||
# s2 = Bank::SavingsAccount.new("4444","99999999","1999-03-27 11:30:09 -0800") | ||
|
||
# Checking Account tests | ||
# c = Bank::CheckingAccount.new("5555","10000","1999-03-27 11:30:09 -0800") | ||
|
||
# MoneyMarketAccount tests | ||
# m = Bank::MoneyMarketAccount.new("666","10000000","1999-03-27 11:30:09 -0800") | ||
# m2 = Bank::MoneyMarketAccount.new("777","500","1999-03-27 11:30:09 -0800") # this should fail |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,24 +6,23 @@ class Account | |
attr_reader :id, :balance, :open_date | ||
attr_accessor :owner | ||
|
||
def initialize(id, initial_balance, open_date, owner = nil) | ||
def initialize(id, initial_balance, open_date) | ||
@balance = initial_balance.to_i | ||
if initial_balance.to_i < 0 | ||
raise ArgumentError, "Invalid Balance: Balance may not be negative." | ||
end | ||
@id = id.to_i | ||
@open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %z") | ||
@owner = owner | ||
@owner = nil | ||
end | ||
|
||
def withdraw(withdraw_amount) | ||
if withdraw_amount > @balance | ||
puts "Warning: Can not withdraw more than is in account. Transaction terminated." | ||
return @balance | ||
else | ||
@balance -= withdraw_amount | ||
return @balance | ||
end | ||
return @balance | ||
end | ||
|
||
def deposit(deposit_amount) | ||
|
@@ -32,12 +31,9 @@ def deposit(deposit_amount) | |
end | ||
|
||
def self.all | ||
accounts_array = [] | ||
CSV.read('support/accounts.csv').map do |account| | ||
x = Bank::Account.new(account[0],account[1],account[2]) | ||
accounts_array.push(x) | ||
end | ||
return accounts_array | ||
accounts_array = CSV.read('support/accounts.csv').map do |account| | ||
Bank::Account.new(account[0],account[1],account[2]) | ||
end | ||
end | ||
|
||
def self.find(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. Nice job using the |
||
|
@@ -88,5 +84,4 @@ def self.find(id) | |
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. In the |
||
|
||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
module Bank | ||
class CheckingAccount < Account | ||
attr_reader :checks_used | ||
|
||
def initialize(id, initial_balance, open_date) | ||
super(id, initial_balance, open_date) | ||
@checks_used = 0 | ||
end | ||
|
||
def withdraw(withdraw_amount) | ||
fee = 100 | ||
if withdraw_amount > (@balance + 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. It seems like you'd want to use the |
||
puts "Warning: Can not withdraw more than is in account. Transaction terminated." | ||
return @balance | ||
else | ||
@balance -= (withdraw_amount + fee) | ||
puts "There is a transaction fee of $1.00." | ||
return @balance | ||
end | ||
end | ||
|
||
def withdraw_using_check(withdraw_amount) | ||
fee = 200 | ||
if withdraw_amount > (@balance + 1000) | ||
puts "Warning: Can not overdraft account more than $10.00. Transaction terminated." | ||
elsif @checks_used < 3 | ||
@balance -= withdraw_amount | ||
@checks_used += 1 | ||
else | ||
puts "You have used up your 3 free check withdrawals this month." | ||
puts "There is a transaction fee of $2.00" | ||
@balance -= (withdraw_amount + fee) | ||
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. Can this fee take the account negative? |
||
@checks_used += 1 | ||
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,60 @@ | ||
module Bank | ||
class MoneyMarketAccount < SavingsAccount | ||
MAX_TRANSACTIONS = 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. Nice use of the constant! |
||
def initialize(id, initial_balance, open_date) | ||
super(id, initial_balance, open_date) | ||
@current_transactions = 0 | ||
@transaction_ban = false | ||
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 use this boolean to handle the ability to execute a transaction or not |
||
@min_balance = 1000000 | ||
if initial_balance.to_i < @min_balance | ||
raise ArgumentError, "Invalid Balance: Balance may not be less than $10,000.00" | ||
end | ||
end | ||
|
||
def withdraw(withdraw_amount) | ||
fee = 10000 | ||
if @current_transactions >= MAX_TRANSACTIONS | ||
puts "You have already used up your maximum amount of transactions this month. Transaction terminated." | ||
elsif @transaction_ban == true | ||
puts "Transaction denied. Balance must be increased with a deposit before further transactions." | ||
elsif (@balance - withdraw_amount) < @min_balance | ||
puts "A $100.00 fee will be incurred for balance going below $10,000.00." | ||
puts "No more transactions allowed until the balance is increased." | ||
@transaction_ban = true | ||
@balance -= (withdraw_amount + fee) | ||
@current_transactions += 1 | ||
else | ||
@balance -= withdraw_amount | ||
@current_transactions += 1 | ||
end | ||
return @balance | ||
end | ||
|
||
def deposit(deposit_amount) | ||
if @balance < @min_balance | ||
@balance += deposit_amount | ||
if @balance > @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. This would be a good place to use one of our "new" single-line conditionals |
||
@transaction_ban = false | ||
end | ||
else | ||
@balance += deposit_amount | ||
@current_transactions += 1 | ||
end | ||
return @balance | ||
end | ||
|
||
def add_interest(rate) | ||
if @transaction_ban == true | ||
puts "Transaction's banned until balance is at a minimum of $10,000." | ||
else | ||
super(rate) | ||
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 super here |
||
end | ||
end | ||
|
||
def reset_transactions | ||
@current_transactions = 0 | ||
end | ||
|
||
|
||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
module Bank | ||
|
||
class SavingsAccount < Account | ||
FEE = 200 | ||
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 a constant for this |
||
def initialize(id, initial_balance, open_date) | ||
super(id, initial_balance, open_date) | ||
@min_balance = 1000 | ||
if initial_balance.to_i < @min_balance | ||
raise ArgumentError, "Invalid Balance: Balance may not be less than $10.00" | ||
end | ||
end | ||
|
||
def withdraw(withdraw_amount) | ||
if (@balance - withdraw_amount) < @min_balance | ||
puts "Warning: Balance may not go under $10.00. Transaction terminated." | ||
else | ||
@balance -= (withdraw_amount + FEE) | ||
puts "There is a transaction fee of $#{FEE/100}.00." | ||
end | ||
return @balance | ||
end | ||
|
||
def add_interest(rate) | ||
interest = @balance * (rate.to_f / 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.
Nice job moving the return to outside of the
if
statement since it applies to both conditions