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

Wave 3 #59

Open
wants to merge 15 commits into
base: jmn/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
-->
12 changes: 7 additions & 5 deletions bank-accounts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
module Bank

class Account
@@min_balance = 0

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


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

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 drive the find method's functionality

Choose a reason for hiding this comment

The 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

Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions bank-master.rb
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"
35 changes: 35 additions & 0 deletions checking-account.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)

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

Nice use of the += and the -= operators

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
58 changes: 58 additions & 0 deletions money-market.rb
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

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

The 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