Skip to content
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

Open
wants to merge 14 commits into
base: dfcp/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,23 @@ Create an `Account` class which should have the following functionality:
**Account ID** - (Fixnum) a unique identifier corresponding to an account
**Owner ID** - (Fixnum) a unique identifier corresponding to an owner

<!--
## Wave 3
Create a `SavingsAccount` class which should inherit behavior from the `Account` class. It should include updated logic with the following functionality:
- An updated `initialize` method:
- The initial balance cannot be less than $10. If it is, this will `raise` an `ArgumentError`
- An updated `withdraw` method:
Create a `SavingsAccount` class which should inherit behavior from the `Account` class. It should include the following updated functionality:
- The initial balance cannot be less than $10. If it is, this will `raise` an `ArgumentError`
- Updated withdrawal functionality:
- Each withdrawal 'transaction' incurs a fee of $2 that is taken out of the balance.
- Does not allow the account to go below the $10 minimum balance - Will output a warning message and return the original un-modified balance

It should include the following new methods:
It should include the following new method:
- `#add_interest(rate)`: Calculate the interest on the balance and add the interest to the balance. Return the **interest** that was calculated and added to the balance (not the updated balance).
- Input rate is assumed to be a percentage (i.e. 0.25).
- The formula for calculating interest is `balance * rate/100`
- Example: If the interest rate is 0.25% and the balance is $10,000, then the interest that is returned is $25 and the new balance becomes $10,025.

Create a `CheckingAccount` class which should inherit behavior from the `Account` class. It should include updated logic with the following functionality:
- `#withdraw(amount)`: The input amount gets taken out of the account as result of an ATM transaction. Each withdrawal 'transaction' incurs a fee of $1 that is taken out of the balance. Returns the updated account balance.
- Does not allow the account to go negative. Will output a warning message and return the original un-modified balance.
Create a `CheckingAccount` class which should inherit behavior from the `Account` class. It should include the following updated functionality:
- Updated withdrawal functionality:
- Each withdrawal 'transaction' incurs a fee of $1 that is taken out of the balance. Returns the updated account balance.
- Does not allow the account to go negative. Will output a warning message and return the original un-modified balance.
- `#withdraw_using_check(amount)`: 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
Expand All @@ -101,16 +100,15 @@ Create a `CheckingAccount` class which should inherit behavior from the `Account

## Optional:

Create a `MoneyMarketAccount` class with a minimum of 6 specs. The class should inherit behavior from the `Account` class.
Create a `MoneyMarketAccount` class which should inherit behavior from the `Account` class.
- A maximum of 6 transactions (deposits or withdrawals) are allowed per month on this account type
- `self.new(id, initial_balance)`: creates a new instance with the instance variable `id` and 'initial_balance' assigned
- The initial balance cannot be less than $10,000 - this will `raise` an `ArgumentError`
- `#withdraw(amount)`: The input amount gets taken out of the account as result of an ATM transaction. Returns the updated account balance.
- The initial balance cannot be less than $10,000 - this will `raise` an `ArgumentError`
- Updated withdrawal logic:
- If a withdrawal causes the balance to go below $10,000, a fee of $100 is imposed and no more transactions are allowed until the balance is increased using a deposit transaction.
- Each transaction will be counted against the maximum number of transactions
- `#deposit(amount)`. Returns the updated account balance.
- Updated deposit logic:
- Each transaction will be counted against the maximum number of transactions
- Exception to the above: A deposit performed to reach or exceed the minimum balance of $10,000 is not counted as part of the 6 transactions.
- `#add_interest(rate)`: Calculate the interest on the balance and add the interest to the balance. Return the interest that was calculated and added to the balance (not the updated balance). Note** This is the same as the `SavingsAccount` interest.
- `#add_interest(rate)`: Calculate the interest on the balance and add the interest to the balance. Return the interest that was calculated and added to the balance (not the updated balance).
- Note** This is the same as the `SavingsAccount` interest.
- `#reset_transactions`: Resets the number of transactions to zero
-->
18 changes: 18 additions & 0 deletions bank.rb
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
17 changes: 6 additions & 11 deletions bankaccounts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

end

def deposit(deposit_amount)
Expand All @@ -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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job using the all method to accomplish the goal of the find

Expand Down Expand Up @@ -88,5 +84,4 @@ def self.find(id)
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the all method above, I'd use a more explicit variable name rather than o in your map method call


end

end
44 changes: 44 additions & 0 deletions checking.rb
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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like you'd want to use the fee variable in this calculation rather than a hard-coded 100

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)

Choose a reason for hiding this comment

The 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
60 changes: 60 additions & 0 deletions moneymarket.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
module Bank
class MoneyMarketAccount < SavingsAccount
MAX_TRANSACTIONS = 6

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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)

Choose a reason for hiding this comment

The 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
31 changes: 31 additions & 0 deletions savings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Bank

class SavingsAccount < Account
FEE = 200

Choose a reason for hiding this comment

The 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