Skip to content
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
31 changes: 31 additions & 0 deletions CheckingAccount.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Bank
class CheckingAccount < Account
def initialize(id, initial_balance, open_date, owner = nil)
super
@num_checks_used = 0
end

def withdraw(amount)
transaction_fee = 100
return super(amount + transaction_fee)
end

def withdraw_using_check(amount)
min_balance = -1000
if @num_checks_used >= 3
amount += 200
end
if (@balance - amount < min_balance)
puts "Your balance cannot be below the minimum amount of $#{min_balance/100}. Transaction terminated."
else
@num_checks_used += 1
@balance -= amount
end
return @balance
end

def reset_checks
@num_checks_used = 0
end
end
end
64 changes: 64 additions & 0 deletions MoneyMarketAccount.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
module Bank
class MoneyMarketAccount < Account
attr_reader :num_transactions, :transaction_allowed
def initialize(id, initial_balance, open_date, owner = nil)
@id = id
@balance = initial_balance
@min_balance = 1000000
@open_date = open_date
@owner = owner
@num_transactions = 0
@max_transactions = 6
@bal_above_min = true
check_balance
end

def withdraw(amount)
below_min_balance_fee = 10000
if @num_transactions >= @max_transactions
puts "You cannot make more than #{@max_transactions} transactions in one month. Transaction terminated."
else #number of transactions is less than the allotted maximum
if @bal_above_min
if (@balance - amount < @min_balance) #withdrawing the amount will put the account below the minimum balance
amount += below_min_balance_fee
puts "Your account is locked until you reach the minimum balance of $#{@min_balance}."
@bal_above_min = false
end
@balance -= amount
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Watch your indentation here - this code is outside of the if statement blocks so it does not need to have additional indentation

@num_transactions += 1
return @balance
else #balance is below the minimum balance
puts "You cannot make another transaction until your balance is increased to the minimum balance, $#{@min_balance}."
end
end
end

def deposit(amount)
if !@bal_above_min
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is a good use of the boolean to track whether or not the balance is within the acceptable range

if (amount + @balance >= @min_balance) #enough funds to bring balance above min balance, will deposit
super(amount)
@bal_above_min = true
else
puts "You cannot make another transaction until your balance is increased to the minimum balance, $#{@min_balance}."
end
else #balance is above the minimum balance
if @num_transactions >= @max_transactions
puts "You cannot make more than #{@max_transactions} transactions in one month. Transaction terminated."
else #number of transactions is less than the maximum allowed transactions
super(amount)
@num_transactions += 1
end
end
end

def reset_transactions
@num_transactions = 0
end

def add_interest(rate)
interest = @balance * (rate.to_f/100)
balance += interest
return interest
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
-->
24 changes: 24 additions & 0 deletions SavingsAccount.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

module Bank
class SavingsAccount < Account
def initialize(id, initial_balance, open_date, owner = nil)
@id = id
@balance = initial_balance
@min_balance = 1000
@open_date = open_date
@owner = owner
check_balance
end

def withdraw(amount)
transaction_fee = 200
return super(amount + transaction_fee)
end

def add_interest(rate)
interest = @balance * (rate.to_f/100)
balance += interest
return interest
end
end
end
22 changes: 15 additions & 7 deletions bank_accounts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ module Bank
class Account
attr_reader :balance, :owner, :id, :open_date
def initialize(id, initial_balance, open_date, owner = nil)
if(initial_balance < 0)
raise ArgumentError, "Your initial balance must be a positive value."
end
@balance = initial_balance
@id = id
@balance = initial_balance
@min_balance = 0
@open_date = open_date
@owner = owner
check_balance
end

def check_balance
if @balance < @min_balance
raise ArgumentError, "Your initial balance must be at least $#{@min_balance/100}."
end
end

def self.all
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I like the way you use the CSV file to pull out the one account match in your find method

Expand Down Expand Up @@ -43,8 +48,8 @@ def self.get_ultimate_list
end

def withdraw(amount)
if (@balance < amount)
puts "This will result in a negative account balance. Transaction terminated."
if (@balance - amount < @min_balance)
puts "Your balance cannot be below the minimum amount of $#{@min_balance/100}. Transaction terminated."
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It seems like you use the @min_balance/100 a few different times to get the "output" version of the balance so it may be worth having a separate method to do this for you so if you need to do this again later you'll be able to reuse the same functionality

else
@balance -= amount
end
Expand Down Expand Up @@ -79,6 +84,9 @@ def self.find(id)
owner = Owner.new(match[0].to_i, match[1], match[2], match[3], match[4], match[5])
return owner
end

end
end

require "./SavingsAccount.rb"
require "./CheckingAccount.rb"
require "./MoneyMarketAccount.rb"