Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
d7417a8
Created module of Bank, class Account
ltrickey Feb 21, 2017
41b83ad
Initialize Bank::Account with Id & Balance
ltrickey Feb 21, 2017
196a3ff
Cannot initialize with Negative Bal
ltrickey Feb 21, 2017
5dfdf17
Creating method withdraw for class Account
ltrickey Feb 21, 2017
038cea7
withdrawl returns updated balance
ltrickey Feb 21, 2017
6fbb0be
Outputs an error if balance is going negative.
ltrickey Feb 21, 2017
ecb4b4e
Doesn't modify balance if withdrawl would make it go negative.
ltrickey Feb 21, 2017
2a47fc2
Allows withdrawal ammount to = balance, taking balance to 0.
ltrickey Feb 21, 2017
f2a4678
withdrawal must be > 0
ltrickey Feb 21, 2017
a8c0232
Add deposit method
ltrickey Feb 21, 2017
2434062
deposit adds to balance
ltrickey Feb 21, 2017
c8807a3
Raise argument if deposit is not positive
ltrickey Feb 21, 2017
c40d49b
Add Owner class
ltrickey Feb 21, 2017
8cc4450
Adding test to make sure Owner can be initialized
ltrickey Feb 22, 2017
7d7aec9
initialize class Owner with Name and Phone Number
ltrickey Feb 22, 2017
fe8c680
Updated test and account to make sure Owner responded to name and pho…
ltrickey Feb 22, 2017
a871c20
Starting a test to check if a new Owner can be assigned to an Account
ltrickey Feb 22, 2017
d6ea6ef
Added @owner attribute to Account class. Tested that it is accessible
ltrickey Feb 22, 2017
0de7ef1
Adding owner of object Owner, modifying test to reflect
ltrickey Feb 22, 2017
5a31f07
Create test to check that owner parameter when calling add_owner on a…
ltrickey Feb 22, 2017
ce6f236
owner parameter must be class Owner when calling add_owner on Account…
ltrickey Feb 22, 2017
d8b8b00
Adding stubs of .all class method for Account
ltrickey Feb 22, 2017
cdc812f
change account.initialize to take in third parameter of opendate
ltrickey Feb 22, 2017
b4037b3
Modifying specs to work with new three parameters required to initial…
ltrickey Feb 22, 2017
5010f43
Change default initial value of datetime to nodate so tests still work
ltrickey Feb 22, 2017
5d11fbe
wrote test to verify .add returns array
ltrickey Feb 22, 2017
912cf0d
adding before do block to Account.all test portion
ltrickey Feb 22, 2017
38abc1b
created test to verify that every item in array returned with .all me…
ltrickey Feb 22, 2017
b9c04aa
completed test that made sure first id in CSV matched first id in .al…
ltrickey Feb 22, 2017
efe448e
added check balance to last spec
ltrickey Feb 22, 2017
aeaa3a2
created test to return an existing account class account
ltrickey Feb 22, 2017
393e1f6
Create Self method to return object of account when specific id is ca…
ltrickey Feb 23, 2017
216b8ca
created and passed tests for finding first and last account from CSV
ltrickey Feb 23, 2017
0aa8c67
edited .find class method to raise error if searching for id that doe…
ltrickey Feb 23, 2017
55ab30c
updating Owner class to take inputs available in CSV file
ltrickey Feb 23, 2017
7aedbd8
Updated Owner class to have default values of nil, wrote test for Own…
ltrickey Feb 23, 2017
e567bd6
Created and passed test to verify Owner class method .all returns array.
ltrickey Feb 23, 2017
d1ed52a
Added stumps for further .all tests
ltrickey Feb 23, 2017
3638954
updating Owner tests. Working through line 208 which is commented out…
ltrickey Feb 23, 2017
fc909b2
add test to check first and last street_address & pass
ltrickey Feb 23, 2017
31adb29
added .find(id) class method for Owner & test
ltrickey Feb 23, 2017
158f632
Adding argument error if Owner ID does not exist for Owner.find. Cre…
ltrickey Feb 23, 2017
f311fbf
Calling .length on CSV read file instead of creating variable to coun…
ltrickey Feb 23, 2017
23ab6cc
set up stubs for CheckingAccount and SavingsAccount classes
ltrickey Feb 23, 2017
abb53f1
Add Savings account functionality that intial balance must be > 10
ltrickey Feb 23, 2017
fb8fa1b
Add fee for each withdrawal
ltrickey Feb 23, 2017
e062ad2
Outputs warning if withdrawal will take Savings Account balance below…
ltrickey Feb 23, 2017
9c207c5
create withdrawal for savings that does not withdraw if fee will take…
ltrickey Feb 23, 2017
f72b5f2
define add interest method
ltrickey Feb 24, 2017
cf30c41
Updated method of add_interest to take parameter of interest rate
ltrickey Feb 24, 2017
5fbc907
Interest rate must be positive.made all required edits
ltrickey Feb 24, 2017
5fea827
Add dollar fee for withdrawals from checking account
ltrickey Feb 24, 2017
c78c827
Doesn't modify balance if fee would take it under 0, test works
ltrickey Feb 24, 2017
3c0614b
Created basic check_withdrawal method
ltrickey Feb 24, 2017
c4371ff
Make sure withdraw_with_check returns balance
ltrickey Feb 24, 2017
99db3d4
allows check withdrawals to go up to -10
ltrickey Feb 24, 2017
b01fad3
Won't allow more than -10 balance, outputs message for check withdrawals
ltrickey Feb 24, 2017
5419107
check withdrawals must be positive
ltrickey Feb 24, 2017
aa8601f
WIP - working on adding the class var @@check_withdrawals. Code curre…
ltrickey Feb 24, 2017
1e56388
Just adding everything so I'm up to date. Still WIP
ltrickey Feb 24, 2017
649ec52
fixed var check_withdrawals to be instance variable NOT class v.
ltrickey Feb 24, 2017
af30766
created and tested reset-checks method
ltrickey Feb 24, 2017
8ef02b9
Added set_balance method to start. Trying to turn instance vars of @…
ltrickey Feb 24, 2017
d7b5061
Adding files and stumps of Money Market account & spec files
ltrickey Feb 24, 2017
b4a13e3
Money Market account initialize & set balance methods done
ltrickey Feb 24, 2017
4f4d00e
got total transactions for Money Market to stop after 6
ltrickey Feb 24, 2017
92f50fb
edited withdraw method for MMarket, preventing any withdrawals if bal…
ltrickey Feb 24, 2017
88221b9
Added test for counting total transactions. Failing
ltrickey Feb 24, 2017
11a61ed
Passing total transactions test
ltrickey Feb 24, 2017
a2ddadf
created reset transactions method & tested
ltrickey Feb 24, 2017
12b55a5
created add interest for money market account
ltrickey Feb 24, 2017
78e4fe2
trying to dry up code w/ argument method
ltrickey Feb 24, 2017
970e88c
pulling out fees for withdrawals and creating them as their own methods
ltrickey Feb 24, 2017
1754f3b
Added in Interest module to practice Object Comparison
ltrickey Feb 27, 2017
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
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require 'rake/testtask'

Rake::TestTask.new do |t|
t.libs = ["lib"]
t.warning = true
t.warning = false
t.test_files = FileList['specs/*_spec.rb']
end

Expand Down
152 changes: 152 additions & 0 deletions lib/account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
require 'csv'

#Adding this in after the reading this weekend.
#b/c both savings and money market have interest
#but are sisters not mother/daughter classes!
module Interest

def add_interest(rate)
argument("Interest rate >=0") if rate < 0

interest = @balance * (rate/100)
@balance += interest

return interest
end

end

module Bank

class Account
attr_accessor :balance
attr_reader :id, :owner

def initialize(id, start_balance, opendate = nil)

@id = id
@opendate = opendate
@balance = set_balance(start_balance)
end

def set_balance(start_balance)
if start_balance < 0
argument("You cannot initialize a new account with a negative balance.")
else
start_balance
end
end

def self.all
accounts = []

CSV.open("support/accounts.csv").each do |account|
accounts << Bank::Account.new(account[0].to_i, account[1].to_i, account[2])
end
return accounts
end

def self.find(id)
@account = nil

CSV.open("support/accounts.csv").each do |line|
if line[0].to_i == id
@account = Bank::Account.new(line[0].to_i, line[1].to_i, line[2])
end
end

if @account == nil
raise ArgumentError.new "This account does not exist!"
else
return @account
end
end

def add_owner(owner)
if owner.class == Owner
@owner = owner
else
argument("You must add a class type of Owner.")
end
end

def withdraw(withdrawal_amount)
withdraw_positive(withdrawal_amount)

if balance - withdrawal_amount < 0
puts "You are going negative."
return balance
else
@balance -= withdrawal_amount
end
end

#Should this be private??
#b/c only used in check_withdrawals?
def withdraw_positive(withdrawal_amount)
argument("Withdrawal must be >= 0") if withdrawal_amount < 0
end

def deposit(deposit_amount)
if deposit_amount > 0
@balance += deposit_amount
else
argument("Your deposit must be greater than zero.")
end
end

def argument(output)
raise ArgumentError.new "#{ output }"
end

end

class Owner
attr_reader :last_name, :first_name, :street_address, :city, :state

def initialize(
id = nil, last_name = nil,
first_name = nil, street_address = nil,
city = nil, state = nil)
@id = id
@last_name = last_name
@first_name = first_name
@street_address = street_address
@city = city
@state = state
end

def self.all
owners = []
CSV.open("support/owners.csv").each do |owner|
owners << Bank::Owner.new(
owner[0].to_i, owner[1],
owner[2], owner[3],
owner[4], owner[5])
end

return owners
end

def self.find(id)
@owner = nil
CSV.open("support/owners.csv").each do |owner|
if owner[0].to_i == id
@owner = Bank::Owner.new(
owner[0].to_i, owner[1],
owner[2], owner[3],
owner[4], owner[5])
end
end

if @owner == nil
raise ArgumentError.new "This owner does not exist!"
else
return @owner
end

end

end

end
57 changes: 57 additions & 0 deletions lib/checking_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module Bank

class CheckingAccount < Account

def initialize(id, balance, opendate = nil)
super
@check_withdrawals = 0
end

def withdraw(withdrawal_amount)
original_balance = balance

super

if balance == original_balance
balance
elsif balance - 1 < 0
puts "This withdrawal and fee will take your balance below 0."
@balance = original_balance
else
withdrawal_fee
end
end

def withdrawal_fee
@balance -= 1
end

def withdraw_using_check(withdrawal_amount)
withdraw_positive(withdrawal_amount)

if @balance - withdrawal_amount < -10
puts "You can only go negative up to -$10"
return balance
end

@check_withdrawals += 1
@balance -= withdrawal_amount

check_fee
end

def check_fee
if @check_withdrawals > 3
@balance -= 2
else
@balance
end
end

def reset_checks
@check_withdrawals = 0
end

end

end
60 changes: 60 additions & 0 deletions lib/money_market_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
require_relative 'account'

module Bank

class MoneyMarketAccount < Bank::Account

include Interest

attr_reader :total_transactions

def initialize(id, balance, opendate = nil)
super
@total_transactions = 0
end

def set_balance(start_balance)
if start_balance < 10000
argument("You cannot initialize a new Money Market account with less than 10k.")
else
start_balance
end
end

def withdraw(withdrawal_amount)
@total_transactions += 1

if @total_transactions > 6
argument("You cannot make more than six transactions per month.")
end

if @balance < 10000
argument("You cannot make another withdrawal until you make a deposit")
end

super

if @balance < 10000
@balance -= 100
end
end

def deposit(deposit_amount)
if @balance > 10000
@total_transactions += 1
end

if @total_transactions > 6
argument("You cannot make more than six transactions per month.")
end

super
end

def reset_transactions
@total_transactions = 0
end

end

end
35 changes: 35 additions & 0 deletions lib/savings_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Bank

class SavingsAccount < Account

include Interest

def initialize(id, balance, opendate = nil)
super

if @balance < 10
argument("You must initially deposit at least $10.00")
end
end

def withdraw(withdrawal_amount)
original_balance = balance
super

if balance == original_balance
balance
elsif balance - 2 <= 10
puts "This withdrawal and fee will take your balance below $10."
@balance = original_balance
else
withdrawal_fee
end
end

def withdrawal_fee
@balance -= 2
end

end

end
Loading