Skip to content
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
8273a43
Created a Bank Module, Created an Account Class which has different m…
dri19tcc Feb 29, 2016
21d59cc
Working on one method at a time. Have the math working correctly in …
dri19tcc Feb 29, 2016
8090a24
Added in account balance instance variable that is an empty array. S…
dri19tcc Mar 1, 2016
329291a
updated initial balance to account balance. generated ID in initiali…
dri19tcc Mar 1, 2016
1413038
Added Owner Class. Must make an owner, before you make an account Cl…
dri19tcc Mar 1, 2016
ddcf13e
Added unique account ids by using an infinite loop. Added a Class Va…
dri19tcc Mar 1, 2016
c1a0e79
Added type of account to account ex checking, savings. added more id…
dri19tcc Mar 1, 2016
b630936
updated attr reader to get ready for a csv file. added to initialize…
dri19tcc Mar 1, 2016
484fe2f
put in my methods that I need to get the initial balance, account_id,…
dri19tcc Mar 2, 2016
247fd50
added tests at the bottom, trying to get csv files into self.all, mad…
dri19tcc Mar 2, 2016
d959eea
updated my initializer, added the self.all method so that it reads a …
dri19tcc Mar 2, 2016
e460aa7
added the method self.find(id). updated that if a file isn't given, …
dri19tcc Mar 2, 2016
39bd7cf
Added self.all method to Owner Class. Reorganized instances in Owner …
dri19tcc Mar 2, 2016
31d0199
Made account_id and owner_id floats. Updated self.find methods in bo…
dri19tcc Mar 2, 2016
29b2795
Updated Bank::Owner.find method to be more grammatically correct
dri19tcc Mar 2, 2016
6436ec3
Adding method in Class Account to connect (self.connect) up accounts …
dri19tcc Mar 2, 2016
65c353b
inside loop inside of self.connect method, used methods to add the ow…
dri19tcc Mar 3, 2016
f163377
retry connect method, not as a self method. updated owner_id = nil a…
dri19tcc Mar 3, 2016
3d81da7
added a connect method in Account Class that would find the account, …
dri19tcc Mar 3, 2016
0758b96
Putting off connecting files, going to start inheritance
dri19tcc Mar 3, 2016
3867d04
Added a SavingsAccount class that inherits from Account Class. Have …
dri19tcc Mar 4, 2016
8d70d51
Added Checking Account Class which inherits behavior from Account
dri19tcc Mar 4, 2016
0db8594
added a checks_used instance variable. updated withdraw method, upda…
dri19tcc Mar 4, 2016
154c914
Added a check counter that went up and added to whenever a check was …
dri19tcc Mar 4, 2016
6e4e14b
added reset_checks method
dri19tcc Mar 4, 2016
6906940
Added in to make my connect file work
dri19tcc Mar 4, 2016
7a06142
Added a MoneyMarket Class that inherits from the Account Class. Work…
dri19tcc Mar 4, 2016
54d44bb
Added so you only can do 6 transactions a month. Adding a deposit me…
dri19tcc Mar 4, 2016
4b70777
Added a deposit function that inherits from the AccountClass but does…
dri19tcc Mar 4, 2016
645c91e
Added that if balance is <10_000, then it does not add to your number…
dri19tcc Mar 4, 2016
6577877
renamed reset_transactions method
dri19tcc Mar 4, 2016
7a7c1ea
added super to my accounts that were subclasses of AccountClass. Had…
dri19tcc Mar 4, 2016
bba4f9f
updated deposit in MoneyMarketAccount to get it to work correctly
dri19tcc Mar 4, 2016
122e892
updated deposit method in MarketAccount Class so that it worked corre…
dri19tcc Mar 4, 2016
66de008
Added a money_pp method that converts the display version into a user…
dri19tcc Mar 5, 2016
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
302 changes: 302 additions & 0 deletions bank_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,302 @@
require "CSV"
require "money"
I18n.enforce_available_locales = false

module Bank
class Account
attr_reader :account_id, :account_balance, :owner_id, :open_date
attr_writer :owner_id

def initialize(initial_balance, account_id, open_date, owner_id = nil)#owner_id = 0 by default
if initial_balance < 0
raise ArgumentError, "Initial balance must be greater than $0.00."
end
@account_id = account_id.to_f
@account_balance = initial_balance
@open_date = open_date
@owner_id = owner_id #need to add an owner to the account during initialize
end

def self.all(file = "support/accounts.csv")
accounts = CSV.read(file)
account_list = []
accounts.each do |acct|
#puts acct[0]
account_list << self.new(acct[1].to_f, acct[0], acct[2])
#puts new_account.balance
end
return account_list
end

def self.find(id)
accounts = self.all
accounts.each do |account|
if account.account_id == id
return account
end
end
return nil
end

def connect(file = "./support/account_owners.csv")
CSV.read(file).each do |acct_id, own_id|
#puts acct_id
#puts own_id
if @account_id == acct_id.to_i
@owner_id = own_id
#puts "Found matching id"
end
end
return @owner_id
end

def owner
puts Bank::Owner.find(connect)
end

#Find an account by id, add owner to that account, add to mates array

# def self.connect(file = "support/account_owners.csv") #does all or none
# mates = CSV.read(file) #csv reading file
# mates.each do |account, owner| #need 2 arguments for each key/value
# Bank::Account.find(account).add_owner(owner) #this is a method, so you need to pass the value to the method
# end#loop that takes owner_id and connects it to the corresponding account using 2 methods
# end
#puts mates
#if you have a self method, do not call it with an object/instance of that account

def add_owner(id) #account.add_owner(number that you get from Bank::Owner.new)
@owner_id = id #adriana_account.add_owner(adriana_owner.user_id)
end

def balance
return @account_balance
end

def withdraw(money)
balance = @account_balance - money
if balance < 0
puts "You do not have enough money."
return @account_balance #puts "You don't have enough money!"
end
@account_balance = balance
return @account_balance
end

def deposit(money)
@account_balance = @account_balance + money
return @account_balance
end

def money_pp
puts Money.new(@account_balance * 100, "USD").format
end
end

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

def initialize(owner_id, last_name, first_name, street_address, city, state)
@owner_id = owner_id.to_f
@last_name = last_name
@first_name = first_name
@street_address = street_address
@city = city
@state = state
end

def self.all(file = "support/owners.csv")
owners = CSV.read(file)
owner_list = []
owners.each do |owner|
#puts acct[0]
owner_list << self.new(owner[0], owner[1], owner[2], owner[3], owner[4],owner[5])
#puts new_account.balance
end
return owner_list
end

def self.find(id)
owners = self.all
owners.each do |owner|
if owner.owner_id == id
return owner
end
end
#puts owners
return nil
end

end

class SavingsAccount < Account
attr_reader :initial_balance, :account_balance

def initialize(initial_balance)
if initial_balance < 10
raise ArgumentError, "Initial balance must be greater than $10.00."
end
@account_balance = initial_balance
end

def withdraw(money)
balance = @account_balance - money - 2
if balance < 10
puts "Your balance cannot go below $10.00."
return @account_balance
end
@account_balance = balance
return @account_balance
end

def add_interest(rate = 0.25)
interest = @account_balance * (rate / 100)
@account_balance = @account_balance + interest
end
end

class CheckingAccount < Account
attr_reader :account_balance, :initial_balance, :checks_used

def initialize(initial_balance, account_id, open_date, owner_id = nil)
if initial_balance < 0
raise ArgumentError, "Initial balance must be greater than $0.00."
end
super
@account_balance = initial_balance
@checks_used = 0
end

def withdraw(money)
balance = @account_balance - money - 1
if balance < 0
puts "Your balance cannot go below $0.00."
return @account_balance
end
@account_balance = balance
return @account_balance
end

def withdraw_using_check(amount)
balance = @account_balance - amount
if balance < -10
puts "Your balance cannot go below -$10.00."
return @account_balance
end
if @checks_used >= 3
@account_balance = balance - 2
@checks_used += 1
return @account_balance
end
@account_balance = balance
@checks_used += 1
return @account_balance
end

def reset_checks
@checks_used = 0
end
end

class MoneyMarketAccount < Account
attr_reader :account_balance, :initial_balance, :transactions

def initialize(initial_balance, account_id, open_date, owner_id = nil)
if initial_balance < 10_000
raise ArgumentError, "Initial balance must be greater than $10,000.00."
end
super
@account_balance = initial_balance
@transactions = 0
end

def withdraw(money)
balance = @account_balance - money
if @transactions >= 6
puts "You have already used your 6 monthly transactions."
return @account_balance
#puts balance
#puts @account_balance
end
if balance < 9_900 && @account_balance > 10_000
puts "You do not have enough money in your account."
return @account_balance
end
if balance < 9_900
puts "All transactions are suspended until balance is $10,000.00."
return @account_balance
elsif balance < 10_000
puts "Taking out money will incur a $100.00 fee, do you want to continue (y or n)?"
continue = gets.chomp.downcase
if continue == "y"
@account_balance = balance - 100
@transactions += 1
end
return @account_balance
end
@account_balance = balance
@transactions += 1
return @account_balance
end

def deposit(money)
if @account_balance < 10_000
@account_balance = @account_balance + money
return @account_balance
end
if @transactions >= 6
puts "You have already used your 6 monthly transactions."
return @account_balance
end
@account_balance = @account_balance + money
@transactions += 1
return @account_balance
end

def add_interest(rate = 0.25)
interest = @account_balance * (rate / 100)
@account_balance = @account_balance + interest
end

def reset_transactions
@transactions = 0
end

end

end

puts "I am the Batman."
#--------------------------TESTS-----------------------------------

#account_connect = Bank::Account.connect("support/account_owners.csv")

#account = Bank::Account.all("support/accounts.csv")

#owner = Bank::Owner.all("support/owners.csv") #this is a method inside a class inside a module

#account_owner = Bank::Account.connect("support/account_owners.csv")

#puts y
#x = Bank::Owner.find(14)
#puts x
#x = Bank::Owner.find(24)
#puts x
#account = Bank::Account.all("support/accounts.csv") #this is a method inside a class inside a module
#puts z[0].balance #this prints out the first array bank account and then the balance using the balance method
#a = Bank::Account.find(1217)
#puts a
#adriana_owner = Bank::Owner.new("adriana", "cannon", "el paso", "texas")
# adriana_account.deposit(200)
# #adriana_account.withdraw(100)

#Adriana_account = { account_id: 1234, balance: 12345, owner_id: 0}
# Adriana_owner = { owner_id: 12, first_name: "A" }
# owner_id 12 owns account_id 1234

#a = Bank::Account.find(1234)
#a.add_owner(12)

# 1234, 12
# 2345, 14
# 9999, 23