From 93d2960bcccc27a3323a2301a6ebe22086e6b274 Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 29 Feb 2016 15:16:00 -0800 Subject: [PATCH 01/12] added withdraw and deposit methods withdraw method does not the balance to go negative puts a warning message --- BankAccounts.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 BankAccounts.rb diff --git a/BankAccounts.rb b/BankAccounts.rb new file mode 100644 index 00000000..88848685 --- /dev/null +++ b/BankAccounts.rb @@ -0,0 +1,26 @@ +module Bank + class Account + attr_reader :initial_balance + def initialize(id,initial_balance) + @id = id + @initial_balance = initial_balance.to_f + end + + def withdraw(withdraw) + if withdraw > @initial_balance + puts "You don't have enough money to take that out." + return @initial_balance + else + @initial_balance = @initial_balance - withdraw + return @initial_balance + end + end + + def deposit(deposit) + @initial_balance = @initial_balance + deposit + return @initial_balance + end + + + end +end From 499e6d7651b3cc03396ba71110dc53ecbb210e4a Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 29 Feb 2016 15:35:03 -0800 Subject: [PATCH 02/12] added balance method and argument error for accounts created with a negative balance --- BankAccounts.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/BankAccounts.rb b/BankAccounts.rb index 88848685..7950b9fd 100644 --- a/BankAccounts.rb +++ b/BankAccounts.rb @@ -4,6 +4,9 @@ class Account def initialize(id,initial_balance) @id = id @initial_balance = initial_balance.to_f + if @initial_balance < 1.0 + raise ArgumentError.new("Account can not start with a negative balance") + end end def withdraw(withdraw) @@ -21,6 +24,10 @@ def deposit(deposit) return @initial_balance end + def balance + @initial_balance + end + end end From 11c7e6ca90b8769be706f338bacf94a20f0a5a2d Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 29 Feb 2016 16:41:01 -0800 Subject: [PATCH 03/12] added owner class that interacts with the account class --- BankAccounts.rb | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/BankAccounts.rb b/BankAccounts.rb index 7950b9fd..1c4cf960 100644 --- a/BankAccounts.rb +++ b/BankAccounts.rb @@ -2,9 +2,10 @@ module Bank class Account attr_reader :initial_balance def initialize(id,initial_balance) + @owner = [] @id = id @initial_balance = initial_balance.to_f - if @initial_balance < 1.0 + if @initial_balance < 0.0 raise ArgumentError.new("Account can not start with a negative balance") end end @@ -28,6 +29,26 @@ def balance @initial_balance end + def owner(owner) + @owner << owner.owner_hash + return @owner + end + + def check_owner + @owner + end end + + class Owner + attr_reader :id, :name, :address, :owner_hash + def initialize(id,name,address) + @id = id + @name = name + @address = address.to_s + @owner_hash = {id: @id, name: @name, address: @address} + end + end + + end From 171b4c39a7db633bb521d79bd712610cb3169462 Mon Sep 17 00:00:00 2001 From: Sarah Date: Tue, 1 Mar 2016 20:30:56 -0800 Subject: [PATCH 04/12] finished self.all method yesss --- BankAccounts.rb | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/BankAccounts.rb b/BankAccounts.rb index 1c4cf960..1914af48 100644 --- a/BankAccounts.rb +++ b/BankAccounts.rb @@ -1,27 +1,29 @@ +require 'CSV' module Bank class Account attr_reader :initial_balance - def initialize(id,initial_balance) + def initialize(id=nil,initial_balance=nil,open_date=nil) @owner = [] @id = id @initial_balance = initial_balance.to_f + @open_date = open_date if @initial_balance < 0.0 - raise ArgumentError.new("Account can not start with a negative balance") + raise ArgumentError.new("Account can not start with a negative balance.") end end - def withdraw(withdraw) - if withdraw > @initial_balance + def withdraw(withdraw_amount) + if withdraw_amount > @initial_balance puts "You don't have enough money to take that out." return @initial_balance else - @initial_balance = @initial_balance - withdraw + @initial_balance = @initial_balance - withdraw_amount return @initial_balance end end - def deposit(deposit) - @initial_balance = @initial_balance + deposit + def deposit(deposit_amount) + @initial_balance = @initial_balance + deposit_amount return @initial_balance end @@ -29,8 +31,8 @@ def balance @initial_balance end - def owner(owner) - @owner << owner.owner_hash + def new_owner(owner) + @owner << owner return @owner end @@ -38,6 +40,20 @@ def check_owner @owner end + #Account.all + def self.all + accounts = [] + array = CSV.read("./support/accounts.csv").each do |array| + accounts << self.new(array[0],array[1],array[2]) + accounts + end + end + + def method_name + + end + + end class Owner @@ -50,5 +66,4 @@ def initialize(id,name,address) end end - end From 360fd866402e897c383ff343274ca24905dcd9ef Mon Sep 17 00:00:00 2001 From: Sarah Date: Wed, 2 Mar 2016 09:10:45 -0800 Subject: [PATCH 05/12] finished the find method last night while sitting with dad in the livingroom watching NASA on youtube --- BankAccounts.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/BankAccounts.rb b/BankAccounts.rb index 1914af48..916ba72f 100644 --- a/BankAccounts.rb +++ b/BankAccounts.rb @@ -43,17 +43,21 @@ def check_owner #Account.all def self.all accounts = [] - array = CSV.read("./support/accounts.csv").each do |array| + CSV.read("./support/accounts.csv").each do |array| accounts << self.new(array[0],array[1],array[2]) accounts end end - def method_name - + def self.find(id) + CSV.read("./support/accounts.csv").each do |csv| + csv.each do |second| + if second.include? id.to_s + return self.new(csv[0],csv[1].to_f / 100,csv[2]) + end + end + end end - - end class Owner From d37ea20ede99466e767c29744172c494d4c5f0c2 Mon Sep 17 00:00:00 2001 From: Sarah Date: Thu, 3 Mar 2016 14:43:03 -0800 Subject: [PATCH 06/12] wave 2 added savings account withdraw and add_interest method --- BankAccounts.rb | 75 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 67 insertions(+), 8 deletions(-) diff --git a/BankAccounts.rb b/BankAccounts.rb index 916ba72f..5374472a 100644 --- a/BankAccounts.rb +++ b/BankAccounts.rb @@ -1,21 +1,25 @@ require 'CSV' module Bank class Account - attr_reader :initial_balance + FEE = 0.0 + INITIAL_BALANCE = 0.0 + attr_reader :initial_balance, :owner, :open_date, :id + attr_accessor def initialize(id=nil,initial_balance=nil,open_date=nil) @owner = [] @id = id @initial_balance = initial_balance.to_f @open_date = open_date - if @initial_balance < 0.0 + if @initial_balance > INITIAL_BALANCE raise ArgumentError.new("Account can not start with a negative balance.") end end + def withdraw(withdraw_amount) if withdraw_amount > @initial_balance puts "You don't have enough money to take that out." - return @initial_balance + return @initial_balance - FEE else @initial_balance = @initial_balance - withdraw_amount return @initial_balance @@ -45,8 +49,8 @@ def self.all accounts = [] CSV.read("./support/accounts.csv").each do |array| accounts << self.new(array[0],array[1],array[2]) - accounts end + return accounts #just as a reminder end def self.find(id) @@ -61,13 +65,68 @@ def self.find(id) end class Owner - attr_reader :id, :name, :address, :owner_hash - def initialize(id,name,address) + attr_reader :id, :first_name, :last_name, :address, :city, :state + def initialize(id=nil,first_name=nil,last_name=nil,address=nil,city=nil,state=nil) @id = id - @name = name + @last_name = first_name + @first_name = last_name @address = address.to_s - @owner_hash = {id: @id, name: @name, address: @address} + @city = city + @state = state + #@owner_hash = {id: @id, name: @name, address: @address} + end + + def self.all + accounts = [] + CSV.read("./support/owners.csv").each do |array| + accounts << self.new(array[0],array[1],array[2],array[3],array[4],array[5]) + end + return accounts #just as a reminder + end + + def self.find(id) + CSV.read("./support/owners.csv").each do |csv| + csv.each do |second| + if second.include? id.to_s + return self.new(csv[0],csv[1],csv[2],csv[3],csv[4],csv[5]) + end + end + end + end + + def account + CSV.read("./support/account_owners.csv").each do |i| + return Account.new(i[0]) + end end + + + + end + + + class SavingsAccount < Account + FEE = -12 + INITIAL_BALANCE = 12 #this inludes the 2 dollar transaction fee and the 10 minimum balance + def initialize + super + end + + def withdraw(withdraw_amount) + super + end + + def add_interest(rate) + interest = @initial_balance * rate.to_f/100 + interest_added = interest + @initial_balance + interest_added + end + + + + + + end end From ba7795e23f0046f556aed33d6bc9960d0d3320b4 Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 4 Mar 2016 10:11:33 -0800 Subject: [PATCH 07/12] I think I got the min balance to work in the checking account. not banking on it though lol --- BankAccounts.rb | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/BankAccounts.rb b/BankAccounts.rb index 5374472a..2f1d4fe7 100644 --- a/BankAccounts.rb +++ b/BankAccounts.rb @@ -1,25 +1,26 @@ require 'CSV' module Bank class Account - FEE = 0.0 - INITIAL_BALANCE = 0.0 - attr_reader :initial_balance, :owner, :open_date, :id + #FEE = 0.0 + #INITIAL_BALANCE = 0.0 + attr_reader :initial_balance, :owner, :open_date, :id, :fee attr_accessor - def initialize(id=nil,initial_balance=nil,open_date=nil) + def initialize(id=nil,initial_balance=nil,open_date=nil,fee = nil) + @fee = 0.0.to_f @owner = [] @id = id - @initial_balance = initial_balance.to_f + @initial_balance = 0.0.to_f @open_date = open_date - if @initial_balance > INITIAL_BALANCE + if @initial_balance < 0.0 raise ArgumentError.new("Account can not start with a negative balance.") end end def withdraw(withdraw_amount) - if withdraw_amount > @initial_balance + if withdraw_amount > @initial_balance + @fee puts "You don't have enough money to take that out." - return @initial_balance - FEE + return @initial_balance else @initial_balance = @initial_balance - withdraw_amount return @initial_balance @@ -106,10 +107,11 @@ def account class SavingsAccount < Account - FEE = -12 - INITIAL_BALANCE = 12 #this inludes the 2 dollar transaction fee and the 10 minimum balance + #FEE = -12 + #INITIAL_BALANCE = 12 #this inludes the 2 dollar transaction fee and the 10 minimum balance def initialize - super + super(fee) + @fee = -12 end def withdraw(withdraw_amount) @@ -122,11 +124,20 @@ def add_interest(rate) interest_added end + end + class CheckingAccount < Account + INITIAL_BALANCE = 0.0 + FEE = 1 + def initialize + super + end + def withdraw(withdraw_amount) + super + end - end end From a65987af690b20de34ffb330d983e0940733b4aa Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 4 Mar 2016 10:44:53 -0800 Subject: [PATCH 08/12] seperated fee and min balance everything looks good fingers crossed --- BankAccounts.rb | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/BankAccounts.rb b/BankAccounts.rb index 2f1d4fe7..21b4d176 100644 --- a/BankAccounts.rb +++ b/BankAccounts.rb @@ -3,9 +3,10 @@ module Bank class Account #FEE = 0.0 #INITIAL_BALANCE = 0.0 - attr_reader :initial_balance, :owner, :open_date, :id, :fee + attr_reader :initial_balance, :owner, :open_date, :id, :fee, :min_amount attr_accessor - def initialize(id=nil,initial_balance=nil,open_date=nil,fee = nil) + def initialize(id=nil,initial_balance=nil,open_date=nil,fee = nil,min_amount=nil) + @min_amount = 0.0 @fee = 0.0.to_f @owner = [] @id = id @@ -18,12 +19,12 @@ def initialize(id=nil,initial_balance=nil,open_date=nil,fee = nil) def withdraw(withdraw_amount) - if withdraw_amount > @initial_balance + @fee + if withdraw_amount > @initial_balance + @min_amount puts "You don't have enough money to take that out." - return @initial_balance + return @initial_balance else @initial_balance = @initial_balance - withdraw_amount - return @initial_balance + return @initial_balance = @initial_balance - @fee end end @@ -107,11 +108,10 @@ def account class SavingsAccount < Account - #FEE = -12 - #INITIAL_BALANCE = 12 #this inludes the 2 dollar transaction fee and the 10 minimum balance def initialize - super(fee) - @fee = -12 + super(fee,min_amount) + @fee = 2 + @min_amount = -10 end def withdraw(withdraw_amount) @@ -128,10 +128,9 @@ def add_interest(rate) class CheckingAccount < Account - INITIAL_BALANCE = 0.0 - FEE = 1 def initialize - super + super(fee) + @fee = -1 end def withdraw(withdraw_amount) From 547d3708b8ab9f2bfbee0d2abbd57a2d7498c7a6 Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 4 Mar 2016 11:05:24 -0800 Subject: [PATCH 09/12] got the min balance of checks to work --- BankAccounts.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/BankAccounts.rb b/BankAccounts.rb index 21b4d176..cec23c4b 100644 --- a/BankAccounts.rb +++ b/BankAccounts.rb @@ -21,7 +21,7 @@ def initialize(id=nil,initial_balance=nil,open_date=nil,fee = nil,min_amount=nil def withdraw(withdraw_amount) if withdraw_amount > @initial_balance + @min_amount puts "You don't have enough money to take that out." - return @initial_balance + return @initial_balance else @initial_balance = @initial_balance - withdraw_amount return @initial_balance = @initial_balance - @fee @@ -130,13 +130,25 @@ def add_interest(rate) class CheckingAccount < Account def initialize super(fee) - @fee = -1 + @fee = 1 end def withdraw(withdraw_amount) super end + + def check(amount) + + if amount > @initial_balance + 10 + puts "You don't have enough money to take that out." + return @initial_balance + else + @initial_balance = @initial_balance - amount + return @initial_balance = @initial_balance - @fee + end + end + end end From a6da16e64441c7a397f74e09634e5b4ec1e8f4dd Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 4 Mar 2016 13:30:06 -0800 Subject: [PATCH 10/12] fixed problems with fee min balance for checks_withdraw method, i hope it won't break again --- BankAccounts.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/BankAccounts.rb b/BankAccounts.rb index cec23c4b..24094cae 100644 --- a/BankAccounts.rb +++ b/BankAccounts.rb @@ -129,7 +129,7 @@ def add_interest(rate) class CheckingAccount < Account def initialize - super(fee) + super(fee,min_amount) @fee = 1 end @@ -138,14 +138,13 @@ def withdraw(withdraw_amount) end - def check(amount) - - if amount > @initial_balance + 10 + def withdraw_using_check(amount) + if amount + @fee > @initial_balance + 10 puts "You don't have enough money to take that out." return @initial_balance else - @initial_balance = @initial_balance - amount - return @initial_balance = @initial_balance - @fee + @initial_balance = @initial_balance - amount - @fee + return @initial_balance = @initial_balance end end From 0b925cde1aaafe78857553332f4b57e534c97c77 Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 4 Mar 2016 14:53:27 -0800 Subject: [PATCH 11/12] finished the extra fee for using more than three checks --- BankAccounts.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/BankAccounts.rb b/BankAccounts.rb index 24094cae..af73f80c 100644 --- a/BankAccounts.rb +++ b/BankAccounts.rb @@ -131,6 +131,8 @@ class CheckingAccount < Account def initialize super(fee,min_amount) @fee = 1 + @checks_used = 0 + @counter = 0 end def withdraw(withdraw_amount) @@ -142,12 +144,22 @@ def withdraw_using_check(amount) if amount + @fee > @initial_balance + 10 puts "You don't have enough money to take that out." return @initial_balance - else - @initial_balance = @initial_balance - amount - @fee - return @initial_balance = @initial_balance + elsif @checks_used > 3 + @initial_balance = @initial_balance - amount - 2 + return @initial_balance + + else @initial_balance = @initial_balance - amount - @fee + @checks_used = @checks_used + 1 + return @initial_balance = @initial_balance + end end + + + end + + end From 8b0dd4c736131db22cc67fa1f6429a9f7cc75b2d Mon Sep 17 00:00:00 2001 From: Sarah Date: Fri, 4 Mar 2016 16:06:03 -0800 Subject: [PATCH 12/12] added reset_checks method. I hope it works if not.. i'll fix it later --- BankAccounts.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/BankAccounts.rb b/BankAccounts.rb index af73f80c..088165de 100644 --- a/BankAccounts.rb +++ b/BankAccounts.rb @@ -156,7 +156,12 @@ def withdraw_using_check(amount) end - + def reset_checks + if @checks_used > 3 + return @checks_used = @checks_used = 0 + end + end + end