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
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
-->
40 changes: 40 additions & 0 deletions lib/bank.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require "./bank_account"
require "./savings_and_checking"

# m = Bank::MoneyMarketAccount.new(1212, 1200000, "06291990")
# 6.times do
# m.withdraw(5000)
# end
#
# m.withdraw(4000)
#
# m.deposit(1000)

# #SAVINGS ACCOUNT CHECKS
# s = Bank::SavingsAccount.new(1212, 2000, "06291990")
# 2.times do
# s.withdraw(200)
# end
#
# s.add_interest(0.25)

#CHECKING ACCOUNT CHECKS
# c = Bank::CheckingAccount.new(1212, 2000, "06291990")
# c.withdraw(1000)
#
# 4. times do
# c.withdraw_using_check(300)
# end
#
# c.withdraw_using_check(600)

#MONEYMARKETACCOUNT CHECKS
m = Bank::MoneyMarketAccount.new(1212, 1000000, "06291990")
m.withdraw(5000)
m.deposit(1000000)

5.times do
m.deposit(100)
end

m.withdraw(5000)
39 changes: 24 additions & 15 deletions bank_account.rb → lib/bank_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ module Bank

class Account
attr_accessor :balance, :id, :owner, :open_date
def initialize(id, balance, open_date, owner = nil)
def initialize(id, balance, open_date)
@balance = balance.to_i
@id = 7383092
@owner = owner
@owner = nil
@open_date = open_date
if @balance < 0
raise ArgumentError, "Accounts cannot be opened with negative money"
Expand All @@ -18,7 +18,7 @@ def initialize(id, balance, open_date, owner = nil)
def withdraw(withdraw_amount)
if @balance < withdraw_amount
puts "Insufficient funds: withdraw denied. Your balance is #{@balance}."
elsif @balance >= withdraw_amount
elsif
@balance = @balance.to_i - withdraw_amount.to_i
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 - you'll want to have an additional indent within the elsif block

puts "Here is your cash monays. Your account balance is now #{@balance}"
end
Expand Down Expand Up @@ -56,26 +56,37 @@ def self.find(id)
end

def self.associate_everything
account_and_owner_csv = CSV.read("support/account_owners.csv")
everything_array = []
account_and_owner_csv.each do |line|
CSV.foreach("support/account_owners.csv") do |line|
each_account = Bank::Account.find(line[0].to_i)
each_owner = Bank::Owner.find(line[1].to_i)
each_account.add_owner(each_owner)
each_account.owner = each_owner
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since you switched to setting the owner directly, do you still need the add_owner method?

everything_array.push(each_account)
end
return everything_array
end

def self.find_owner(id)
account_and_owner_csv = CSV.read("support/account_owners.csv")
owner_csv_array = CSV.read("support/owners.csv")
found_line = account_and_owner_csv.find do |line|
line[0].to_i == id
end
found_owner = owner_csv_array.find do |line|
line[0].to_i == found_line[1].to_i
end
return found_owner
end
end

class Owner
attr_reader :account, :owner_id, :last_name, :first_name, :address, :city, :state
def initialize(id, last_name, first_name, address, city, state)
@account = account
@first_name = first_name
@last_name = last_name
@address = address
@owner_id = owner_id
#@account = account
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hmmm what happened with the owner that made you decide to comment the attributes out?

#@first_name = first_name
# @last_name = last_name
#@address = address
#@owner_id = owner_id
end

def who_da_owna
Expand All @@ -85,10 +96,8 @@ def who_da_owna
def self.all
owner_csv_array = CSV.read("support/owners.csv")
owner_array = []
owner_csv_array.each do |line|
owner_array.push(Owner.new(line[0], line[1], line[2], line[3], line[4], line[5]))
end
return owner_array
owner_array = owner_csv_array.map{ |line|
Owner.new(line[0], line[1], line[2], line[3], line[4], line[5]) }
end

def self.find(id)
Expand Down
126 changes: 126 additions & 0 deletions lib/savings_and_checking.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
module Bank
class SavingsAccount < Account
def initialize(id, balance, open_date)
super(id, balance, open_date)
if @balance < 1000
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Similar comment re: extra indentation here

raise ArgumentError, "Accounts cannot be opened with less than $10. Please try again."
end
end

def withdraw(withdraw_amount)
transaction_fee = 200
temp_balance = @balance - transaction_fee.to_i - withdraw_amount.to_i
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've used a local variable here to keep track of balance before you've decided to set it later

if temp_balance < 1000
puts "You cannot have less than $10. This withdraw has been cancelled."
else
@balance = temp_balance
puts "You new balance is #{@balance}"
end
return @balance
end

def add_interest(rate)
interest_rate = rate.to_f
added_rate = @balance * (interest_rate/100.to_f)
@balance += added_rate
puts "Your balance is #{@balance}"
return added_rate
end
end

class CheckingAccount < Account
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 good but i'd prefer if this class and the money market class were in separate files

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

def withdraw(withdraw_amount)
transaction_fee = 100
temp_balance = @balance - transaction_fee.to_i - withdraw_amount.to_i
if temp_balance < 0
puts "You cannot have less than $0. This withdraw has been cancelled."
else
@balance = temp_balance
puts "Your new balance is #{@balance} and you have used #{@check_count} checks this month."
end
return @balance
end

def withdraw_using_check(amount)
many_checks_fee = 200
temp_balance = @balance - amount.to_i
if @check_count > 2
temp_balance -= many_checks_fee
puts "You've already used your 3 free checks. This transaction will incur a penalty."
end
if temp_balance < -1000
puts "OVERDRAFT: You cannot have less than -$10. Transaction cancelled"
else
@balance = temp_balance
@check_count += 1
puts "Your new balance is #{@balance} and you have used #{@check_count}checks this month."
end
return @balance
end

def reset_checks
@check_count = 0
end
end

class MoneyMarketAccount < Account
def initialize(id, balance, open_date)
super(id, balance, open_date)
@transaction_count = 0
if @balance < 1000000
raise ArgumentError, "Accounts cannot be opened with less than $10000. Please try again."
end
end

def withdraw(withdraw_amount)
overdraft_fee = 10000
if @balance < 1000000
puts "Your account is frozen due to low funds. Deposit more to continue."
return @balance
end
if @transaction_count > 5
puts "You have used all your transactions this month."
return @balance
end
@balance = @balance - withdraw_amount
if @balance < 1000000
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You use this numeric 1000000 value a lot so this would be a great place to use a constant instead of using the same numeric value in multiple places

@balance -= overdraft_fee
puts "OVERDRAFT. Your account can not have less than $10,000. A fee of $#{overdraft_fee/100} has been imposed. Deposit more money before withdrawing again."
end
@transaction_count += 1
puts "#{@transaction_count} is the count and $#{@balance/100} dollars is your balance"
return @balance
end

def deposit(deposit_amount)
if @balance < 1000000
@balance += deposit_amount
elsif @transaction_count >5
puts "You have used all your transactions this month."
return @balance
else
@balance += deposit_amount
@transaction_count += 1
end
puts "#{@transaction_count} is the count and $#{@balance/100} dollars is the balance"
return @balance
end

def add_interest(rate)
interest_rate = rate.to_f
added_rate = @balance * (interest_rate/100.to_f)
@balance += added_rate
return added_rate
end

def reset_transactions
transaction_count = 0
puts "#{@transaction_count} is the count and #{@balance/100} is the balance"
end
end
end