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

Completed Wave 3 Bank Accounts #58

Open
wants to merge 5 commits into
base: rmt/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
Binary file added .DS_Store
Binary file not shown.
4 changes: 4 additions & 0 deletions Bank.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require './BankAccounts.rb'
require './Savings.rb'
require './Checking.rb'
require 'pry'
5 changes: 4 additions & 1 deletion BankAccounts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def initialize(id, balance, open_date)
@id = id
@balance = balance
@open_date = open_date
raise ArgumentError.new("Permission Denied") if balance < "0"
raise ArgumentError.new("Permission Denied") if balance < 0

Choose a reason for hiding this comment

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

Nice use of the single line conditional

end

# Once a new Owner is created, the variable holding the hash is passed in as 'person parameter'
Expand All @@ -19,15 +19,18 @@ def assign_owner(person)
def withdrawl(amnt_withdrawn)
if amnt_withdrawn > @balance
puts "You can't take out more than #{@balance}"
return @balance
else
@balance = @balance - amnt_withdrawn # Return the updated account balance.
puts "Your current balance is: #{@balance}" # The updated balance
end
return @balance
end

def deposit(amnt_deposited)
@balance = @balance + amnt_deposited #Return the updated account balance.
puts "Your current balance is: #{@balance}"
return @balance
end

# This method returns all of the accounts in one array as Account instances.

Choose a reason for hiding this comment

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

I can't comment on the lines below, but I would recommend using a more "useful" variable name rather than l in your each loop below in lines 43-47

Expand Down
43 changes: 43 additions & 0 deletions Checking.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module Bank
# this will inherit behavior from Account class with '<'
class CheckingAccount < Account

attr_reader :checks

Choose a reason for hiding this comment

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

Are you using this attribute to tie to the @checks_used variable anywhere or is this separate?

def initialize(id, balance, open_date)
super
@checks_used = 0
end

def withdrawl(amnt_withdrawn) # add withdrawl functionality
fee_and_withdrawl = amnt_withdrawn + 100 # subtract $2 from balance (add to amnt_withdrawn)
if @balance - fee_and_withdrawl < 0 # Can't go negative.
# Outputs warning and un-modified balance
puts "You can't take out more $$ than you have ($#{@balance})! Don't forget, there is a $1 transaction fee."
return @balance
else
super(fee_and_withdrawl)
end
return @balance

Choose a reason for hiding this comment

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

I think the super method should return the @balance variable so I don't necessarily think you need to return it here again

end

def withdrawl_using_check(amount)
if @checks_used >= 3 # Can use 3 checks for free
check_fee = 200
else
check_fee = 0 # No fee for less than three checks
@checks_used += 1
end
if amount + check_fee <= @balance + 1000

Choose a reason for hiding this comment

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

Watch your indentation here - you don't need an additional indent for the second if statement

@balance = @balance - (amount + check_fee) # Input is taken out of balance
puts "Now you have $#{@balance/100} in your account" # so it shows up as dollars, not cents.
else
"We only let you overdraft up to $10. Write a smaller check."
end
return @balance
end

def reset_checks
@checks_used = 0
end
end
end
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
-->
28 changes: 28 additions & 0 deletions Savings.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Bank
# This will inherit behavior from Account class
class SavingsAccount < Account
def initialize(id, balance, open_date)
super
# if initial balance is < $10, raise ArgumentError
raise ArgumentError.new("Not Allowed") if balance < 1000
end

def withdrawl(amnt_withdrawn) # add withdrawl functionality
fee_and_withdrawl = amnt_withdrawn + 200 # subtract $2 from balance (add to amnt_withdrawn)
if @balance - fee_and_withdrawl < 1000 # can't leave your account with less than $10 in it
# warning message includes untouched balance.
puts "Don't take out all your money! You gotta keep $10 or more in your savings account. Your balance is #{@balance}."
else
super(fee_and_withdrawl) # if 'if' condition is false, run this
end
end

def add_interest(rate)
interest = @balance * (rate/100) # Calculate interest on the balance
@balance = @balance + interest # adds interest to 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 a +=

# puts the amount earned in a dollar (not cents) format.
puts "You earned a measly $#{interest/100} in interest."
return interest
end
end
end