From b79bdfe503a4328712f3ff1f93473a1f8a762833 Mon Sep 17 00:00:00 2001 From: Kari Bancroft Date: Thu, 8 Oct 2015 11:13:05 -0700 Subject: [PATCH 01/26] Add wave 3 --- README.md | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 25fd4d2a..b6e5c7b2 100644 --- a/README.md +++ b/README.md @@ -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 - From 8edeb3ffa97137fb1b50f1cc4887452798dcb877 Mon Sep 17 00:00:00 2001 From: noglows Date: Thu, 8 Oct 2015 14:59:33 -0700 Subject: [PATCH 02/26] Made a new bank.rb file that requires all the different account types --- bank2.rb | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 bank2.rb diff --git a/bank2.rb b/bank2.rb new file mode 100644 index 00000000..29583f30 --- /dev/null +++ b/bank2.rb @@ -0,0 +1,4 @@ +require './lib/account.rb' +require './lib/owner.rb' +require './lib/savings_account.rb' +require './lib/checking_account.rb' From c364b4f3ec90f4c027b187c3f683ecd803b5f426 Mon Sep 17 00:00:00 2001 From: noglows Date: Thu, 8 Oct 2015 14:59:58 -0700 Subject: [PATCH 03/26] Broke the accounts into different files --- lib/account.rb | 202 ++++++++++++++++++++++++++++++++++++++++ lib/checking_account.rb | 32 +++++++ lib/owner.rb | 79 ++++++++++++++++ lib/savings_account.rb | 30 ++++++ 4 files changed, 343 insertions(+) create mode 100644 lib/account.rb create mode 100644 lib/checking_account.rb create mode 100644 lib/owner.rb create mode 100644 lib/savings_account.rb diff --git a/lib/account.rb b/lib/account.rb new file mode 100644 index 00000000..42bc6a9c --- /dev/null +++ b/lib/account.rb @@ -0,0 +1,202 @@ +module Bank + class Account + + attr_reader :balance, :id + attr_accessor :owner, :min_balance, :fee + + + def initialize(id, initial_balance, open_date) + @id = id.to_i + @balance = initial_balance.to_i/100.00 + @open_date = open_date + @min_balance = 0 + @fee = 0 + #open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %z") + #@owner = nil + + # Raises an argument error if the initial balance is less than 0 + if initial_balance.to_i < @min_balance + raise ArgumentError, "The balance cannot be less than 0." + end + end + + + # Creates accounts from the accounts.csv file + def self.all + @accounts = [] + accounts_csv = CSV.read("support/accounts.csv") + accounts_csv.each do |id, balance, date| + id = Bank::Account.new(id,balance,date) + @accounts.push(id) + end + #puts @accounts + return @accounts + end + + # Finds the account with the ID that matches the passed parameter and returns the instance + def self.find(id_search) + found = @accounts.find do |account| + account.id == id_search + end + return found + end + + # Links owners with accounts + def self.link_owner + self.all + Bank::Owner.all + accounts_with_owners = [] + account_owners_csv = CSV.read("support/account_owners.csv") + account_owners_csv.each do |row| + account = self.find(row[0].to_i) + owner_account = Bank::Owner.find(row[1].to_i) + account.owner = owner_account + accounts_with_owners.push(account) + end + return accounts_with_owners + end + + # ----------------------------------------- # + # Work below is extra # + + # Displays (with formatting) the account details for all the accounts in accounts.csv + # (Made this on accident and didn't want to let it go to waste!) + def self.all_print_nice + if @accounts == nil + puts "There are no accounts." + else + @accounts.each do |account| + puts account + account.current_balance + end + end + return + end + + # Finds an account by id passed in as a parameter and displays the account information nicely formatted + # (Made this on accident and didn't want to let it go to waste!) + def self.find_and_display(id_search) + found = @accounts.find do |account| + account.id == id_search + end + return found.current_balance + end + # end of extra work # +# ----------------------------------------# + + # Method for withdrawing from account + def withdraw(amount_to_withdraw) + amount_to_withdraw = amount_to_withdraw/100.00 + amount_to_withdraw += @fee + # Checks that the user is not withdrawing more than what is available in the account + if (@balance - amount_to_withdraw)< @min_balance + puts "The requested withdrawal is more than the available funds." + puts "You only have $#{@balance-@min_balance-@fee} available for withdrawal." + return @balance + else + # makes the withdrawal and displays info to the user + @balance -= (amount_to_withdraw + @fee) + puts "You have withdrawn $#{amount_to_withdraw}" + if @fee != 0 + puts "You have also incurred a $#{@fee} fee." + end + puts "Your current balance is $#{@balance}" + return @balance + end + end + + + # Method for depositing into account + def deposit(amount_to_deposit) + # Makes the deposit and displays info to the user + @balance += amount_to_deposit + puts "You have deposited $#{amount_to_deposit}." + puts "Your current balance is $#{@balance}." + return @balance + end + + # Displays current balance in the account + def current_balance + puts "The account with ID #{@id} currently has a balance of $#{@balance}." + puts "This account was set up on #{@open_date}" + end + + + end + + class Owner + attr_reader :first_name, :last_name, :street, :city, :state, :id + + def initialize(owner_hash) + @id = owner_hash[:id] + @first_name = owner_hash[:first_name] + @last_name = owner_hash[:last_name] + @street_address = owner_hash[:street_address] + @city = owner_hash[:city] + @state = owner_hash[:state] + end + + # Method to display details of an owner instance + def print_owner_details + puts "The owner of this account is #{@first_name} #{@last_name}." + puts "Street: #{@street_address}" + puts "City: #{@city}" + puts "State: #{@state}" + end + + # Creates accounts from the accounts.csv file + def self.all + owner_hash = Hash.new + @owners = [] + owners_csv = CSV.read("support/owners.csv") + owners_csv.each do |id, last_name, first_name, street_address, city, state| + owner_hash[:id] = id.to_i + owner_hash[:last_name] = last_name + owner_hash[:first_name] = first_name + owner_hash[:street_address] = street_address + owner_hash[:city] = city + owner_hash[:state] = state + id = Bank::Owner.new(owner_hash) + @owners.push(id) + end + puts @owners + return @owners + end + + # Finds the owner with the ID that matches the passed parameter and returns the instance + def self.find(id_search) + found = @owners.find do |owner| + owner.id == id_search + end + return found + end + + +# ----------------------------------------- # + # Work below is extra # + + # Displays (with formatting) the owner details for all the accounts in owners.csv + def self.all_print_nice + if @owners == nil + puts "There are no accounts." + else + @owners.each do |owner| + owner.print_owner_details + end + end + return + end + + # Finds an owner by id passed in as a parameter and displays the owner information nicely formatted + def self.find_and_display(id_search) + found = @owners.find do |owner| + owner.id == id_search + end + return found.print_owner_details + end + + # end of extra work # +# ----------------------------------------# + + end +end diff --git a/lib/checking_account.rb b/lib/checking_account.rb new file mode 100644 index 00000000..a09003a6 --- /dev/null +++ b/lib/checking_account.rb @@ -0,0 +1,32 @@ +module Bank + + class CheckingAccount < Account + + def initialize(id, initial_balance, open_date) + super + @fee = 1 + @check_number = 1 + #@min_balance = 0 + end + + def withdraw(amount_to_withdraw) + super + end + + def withdraw_using_check(amount_to_withdraw) + if check_number <= 3 + @min_balance = -10 + withdraw(amount_to_withdraw) + @min_balance = 0 + @check_number +=1 + else + @fee = 2 + @min_balance = -10 + withdraw(amount_to_withdraw) + @min_balance = 0 + end + + end + + end +end diff --git a/lib/owner.rb b/lib/owner.rb new file mode 100644 index 00000000..af4616f9 --- /dev/null +++ b/lib/owner.rb @@ -0,0 +1,79 @@ +module Bank + +class Owner + attr_reader :first_name, :last_name, :street, :city, :state, :id + + def initialize(owner_hash) + @id = owner_hash[:id] + @first_name = owner_hash[:first_name] + @last_name = owner_hash[:last_name] + @street_address = owner_hash[:street_address] + @city = owner_hash[:city] + @state = owner_hash[:state] + end + + # Method to display details of an owner instance + def print_owner_details + puts "The owner of this account is #{@first_name} #{@last_name}." + puts "Street: #{@street_address}" + puts "City: #{@city}" + puts "State: #{@state}" + end + + # Creates accounts from the accounts.csv file + def self.all + owner_hash = Hash.new + @owners = [] + owners_csv = CSV.read("support/owners.csv") + owners_csv.each do |id, last_name, first_name, street_address, city, state| + owner_hash[:id] = id.to_i + owner_hash[:last_name] = last_name + owner_hash[:first_name] = first_name + owner_hash[:street_address] = street_address + owner_hash[:city] = city + owner_hash[:state] = state + id = Bank::Owner.new(owner_hash) + @owners.push(id) + end + puts @owners + return @owners + end + + # Finds the owner with the ID that matches the passed parameter and returns the instance + def self.find(id_search) + found = @owners.find do |owner| + owner.id == id_search + end + return found + end + + +# ----------------------------------------- # + # Work below is extra # + + # Displays (with formatting) the owner details for all the accounts in owners.csv + def self.all_print_nice + if @owners == nil + puts "There are no accounts." + else + @owners.each do |owner| + owner.print_owner_details + end + end + return + end + + # Finds an owner by id passed in as a parameter and displays the owner information nicely formatted + def self.find_and_display(id_search) + found = @owners.find do |owner| + owner.id == id_search + end + return found.print_owner_details + end + + # end of extra work # +# ----------------------------------------# + +end + +end diff --git a/lib/savings_account.rb b/lib/savings_account.rb new file mode 100644 index 00000000..e2ffcf06 --- /dev/null +++ b/lib/savings_account.rb @@ -0,0 +1,30 @@ +require 'pry' +module Bank + + + class SavingsAccount < Account + + def initialize(id, initial_balance, open_date) + super + @min_balance = 10 + @fee = 2 + #Raises an argument error if the initial balance is less than 0 + if initial_balance.to_i/100.00 < @min_balance + raise ArgumentError, "The balance cannot be less than $#{@min_balance}." + end + end + + # Rewrote the withdraw method in account so that only a super is needed - This line could come out but is being kept in for clarity. + def withdraw(amount_to_withdraw) + super + end + + def add_interest(rate) + interest = @balance * rate/100 + @balance += interest + return interest + end + + + end +end From 622f68cb935a51de27f744d5667290c4f25c1ca9 Mon Sep 17 00:00:00 2001 From: noglows Date: Thu, 8 Oct 2015 15:00:34 -0700 Subject: [PATCH 04/26] Updated old bank.rb file - this will be deleted later --- bank.rb | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/bank.rb b/bank.rb index 5bdd3ad3..c33d9bb9 100644 --- a/bank.rb +++ b/bank.rb @@ -9,8 +9,10 @@ class Account def initialize(id, initial_balance, open_date) @id = id.to_i - @balance = initial_balance.to_i/100.0 - @open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %z") + @balance = initial_balance.to_i/100.00 + @open_date = open_date + @min_balance = 0 + #open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %z") #@owner = nil # Raises an argument error if the initial balance is less than 0 @@ -85,9 +87,9 @@ def self.find_and_display(id_search) # Method for withdrawing from account def withdraw(amount_to_withdraw) # Checks that the user is not withdrawing more than what is available in the account - if (@balance - amount_to_withdraw)< 0 + if (@balance - amount_to_withdraw)< @min_balance puts "The requested withdrawal is more than the available funds." - puts "You only have $#{@balance} available for withdrawal." + puts "You only have $#{@balance-@min_balance} available for withdrawal." return @balance else # makes the withdrawal and displays info to the user @@ -192,4 +194,32 @@ def self.find_and_display(id_search) end + + + + + + + + class SavingsAccount < Account + + def initialize(id, initial_balance, open_date) + #@id = id.to_i + @balance = initial_balance.to_i/100.0 + #@open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %z") + #@owner = nil + @min_balance = 10 + + # Raises an argument error if the initial balance is less than 0 + if initial_balance.to_i < 10 + raise ArgumentError, "The balance cannot be less than $10." + end + end + + def withdraw(amount_to_withdraw) + super + end + + end + end From f8511666327f76ed2f7d671c1824ee727b3c39da Mon Sep 17 00:00:00 2001 From: noglows Date: Thu, 8 Oct 2015 15:28:41 -0700 Subject: [PATCH 05/26] Updated fee to a float --- lib/savings_account.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index e2ffcf06..1c1c70c7 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -6,8 +6,8 @@ class SavingsAccount < Account def initialize(id, initial_balance, open_date) super - @min_balance = 10 - @fee = 2 + @min_balance = 10.0 + @fee = 2.0 #Raises an argument error if the initial balance is less than 0 if initial_balance.to_i/100.00 < @min_balance raise ArgumentError, "The balance cannot be less than $#{@min_balance}." From 73915bb1a4bd971ce1e398d9fca193e998e81e82 Mon Sep 17 00:00:00 2001 From: noglows Date: Thu, 8 Oct 2015 15:29:12 -0700 Subject: [PATCH 06/26] Updated withdraw logic so that edge cases are handled --- lib/account.rb | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 42bc6a9c..cef2e64c 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,3 +1,4 @@ +require 'pry' module Bank class Account @@ -85,18 +86,26 @@ def self.find_and_display(id_search) # ----------------------------------------# # Method for withdrawing from account - def withdraw(amount_to_withdraw) - amount_to_withdraw = amount_to_withdraw/100.00 - amount_to_withdraw += @fee + def withdraw(orig_amount_to_withdraw) + orig_amount_to_withdraw = orig_amount_to_withdraw/100.00 + + amount_to_withdraw = orig_amount_to_withdraw + @fee # Checks that the user is not withdrawing more than what is available in the account - if (@balance - amount_to_withdraw)< @min_balance + binding.pry + if (@balance - amount_to_withdraw) < @min_balance puts "The requested withdrawal is more than the available funds." - puts "You only have $#{@balance-@min_balance-@fee} available for withdrawal." + if (@balance-@min_balance-@fee) < 0 + puts "You have no money left to withdraw." + else + puts "You only have $#{@balance-@min_balance-@fee} available for withdrawal." + end return @balance else # makes the withdrawal and displays info to the user - @balance -= (amount_to_withdraw + @fee) - puts "You have withdrawn $#{amount_to_withdraw}" + @balance -= (amount_to_withdraw) + puts balance + puts amount_to_withdraw + puts "You have withdrawn $#{orig_amount_to_withdraw}" if @fee != 0 puts "You have also incurred a $#{@fee} fee." end From a04961abc4994cb4a214ccb914bb0e1b6e790a9d Mon Sep 17 00:00:00 2001 From: noglows Date: Thu, 8 Oct 2015 15:29:42 -0700 Subject: [PATCH 07/26] Initial working checking account --- lib/checking_account.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index a09003a6..64bddafd 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -4,7 +4,7 @@ class CheckingAccount < Account def initialize(id, initial_balance, open_date) super - @fee = 1 + @fee = 1.0 @check_number = 1 #@min_balance = 0 end @@ -14,18 +14,25 @@ def withdraw(amount_to_withdraw) end def withdraw_using_check(amount_to_withdraw) - if check_number <= 3 - @min_balance = -10 + initial_balance = @balance + if @check_number <= 3 + @fee = 0 + @min_balance = -10.0 withdraw(amount_to_withdraw) @min_balance = 0 - @check_number +=1 + if @balance != initial_balance + @check_number +=1 + end else @fee = 2 @min_balance = -10 withdraw(amount_to_withdraw) + if @balance != initial_balance + @check_number +=1 + end @min_balance = 0 end - + return @balance end end From 715cb38389392b1a995e481c0346da417f78238e Mon Sep 17 00:00:00 2001 From: noglows Date: Thu, 8 Oct 2015 15:31:36 -0700 Subject: [PATCH 08/26] Added the reset checks method --- lib/checking_account.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 64bddafd..1d89be15 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -35,5 +35,9 @@ def withdraw_using_check(amount_to_withdraw) return @balance end + def reset_checks + @check_number = 0 + end + end end From b789fb0fd032e93a40a3be46d20253998d1ef5ad Mon Sep 17 00:00:00 2001 From: noglows Date: Thu, 8 Oct 2015 16:55:37 -0700 Subject: [PATCH 09/26] Added money_market_account and modified account withdraw method to accomodate money_market_acct --- bank2.rb | 1 + lib/account.rb | 26 ++++++++++++++------ lib/checking_account.rb | 2 +- lib/money_market_account.rb | 49 +++++++++++++++++++++++++++++++++++++ lib/savings_account.rb | 3 ++- 5 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 lib/money_market_account.rb diff --git a/bank2.rb b/bank2.rb index 29583f30..98640984 100644 --- a/bank2.rb +++ b/bank2.rb @@ -2,3 +2,4 @@ require './lib/owner.rb' require './lib/savings_account.rb' require './lib/checking_account.rb' +require './lib/money_market_account.rb' diff --git a/lib/account.rb b/lib/account.rb index cef2e64c..713987b0 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -3,7 +3,7 @@ module Bank class Account attr_reader :balance, :id - attr_accessor :owner, :min_balance, :fee + attr_accessor :owner, :min_balance, :fee, :acct_type def initialize(id, initial_balance, open_date) @@ -12,6 +12,7 @@ def initialize(id, initial_balance, open_date) @open_date = open_date @min_balance = 0 @fee = 0 + @acct_type = nil #open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %z") #@owner = nil @@ -91,20 +92,29 @@ def withdraw(orig_amount_to_withdraw) amount_to_withdraw = orig_amount_to_withdraw + @fee # Checks that the user is not withdrawing more than what is available in the account - binding.pry if (@balance - amount_to_withdraw) < @min_balance - puts "The requested withdrawal is more than the available funds." - if (@balance-@min_balance-@fee) < 0 - puts "You have no money left to withdraw." + if @acct_type == "MoneyMarket" + if (@balance - amount_to_withdraw - @fee) < 0 + puts "Sorry you cannot make that withdrawal without depositing more money." + else + puts "As this transaction puts your balance below $#{@min_balance}, a fee of $#{@fee} has been imposed." + @balance -= (amount_to_withdraw + @fee) + puts "Your balance is $#{@balance}" + end else - puts "You only have $#{@balance-@min_balance-@fee} available for withdrawal." + puts "The requested withdrawal is more than the available funds." + if (@balance-@min_balance-@fee) < 0 + puts "You have no money left to withdraw." + else + puts "You only have $#{@balance-@min_balance-@fee} available for withdrawal." + end end return @balance else # makes the withdrawal and displays info to the user @balance -= (amount_to_withdraw) - puts balance - puts amount_to_withdraw + # puts balance + # puts amount_to_withdraw puts "You have withdrawn $#{orig_amount_to_withdraw}" if @fee != 0 puts "You have also incurred a $#{@fee} fee." diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 1d89be15..0f168661 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -24,7 +24,7 @@ def withdraw_using_check(amount_to_withdraw) @check_number +=1 end else - @fee = 2 + @fee = 2.0 @min_balance = -10 withdraw(amount_to_withdraw) if @balance != initial_balance diff --git a/lib/money_market_account.rb b/lib/money_market_account.rb new file mode 100644 index 00000000..2e69f995 --- /dev/null +++ b/lib/money_market_account.rb @@ -0,0 +1,49 @@ +module Bank + + class MoneyMarketAccount < Account + + def initialize(id, initial_balance, open_date) + super + @transactions = 0 + @min_balance = 10000 + @fee = 0 + @acct_type = "MoneyMarket" + + if initial_balance.to_i/100.00 < @min_balance + raise ArgumentError, "The balance cannot be less than $#{@min_balance}." + end + end + + # def check_transactions + # if @transactions >= 6 + # puts "You cannot make any more transactions this month." + # else + # super + # transactions += 1 + # end + # end + + def withdraw(amount) + if @transactions >= 6 + puts "You cannot make any more transactions this month." + else + super + @transactions += 1 + end + end + + def deposit(amount) + if @transactions >= 6 + puts "You cannot make any more transactions this month." + else + super + @transactions += 1 + end + end + + def reset_transactions + @transactions = 0 + end + + end +end diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 1c1c70c7..752d8967 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -8,6 +8,7 @@ def initialize(id, initial_balance, open_date) super @min_balance = 10.0 @fee = 2.0 + #Raises an argument error if the initial balance is less than 0 if initial_balance.to_i/100.00 < @min_balance raise ArgumentError, "The balance cannot be less than $#{@min_balance}." @@ -15,7 +16,7 @@ def initialize(id, initial_balance, open_date) end # Rewrote the withdraw method in account so that only a super is needed - This line could come out but is being kept in for clarity. - def withdraw(amount_to_withdraw) + def withdraw(orig_amount_to_withdraw) super end From 2406a3738354df2c2aa7fb97340ce50f53e9260d Mon Sep 17 00:00:00 2001 From: noglows Date: Thu, 8 Oct 2015 17:03:19 -0700 Subject: [PATCH 10/26] Fixed some money market issues --- lib/account.rb | 6 +++--- lib/money_market_account.rb | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 713987b0..3a890681 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -94,11 +94,11 @@ def withdraw(orig_amount_to_withdraw) # Checks that the user is not withdrawing more than what is available in the account if (@balance - amount_to_withdraw) < @min_balance if @acct_type == "MoneyMarket" - if (@balance - amount_to_withdraw - @fee) < 0 + if (@balance - amount_to_withdraw - @money_market_fee) < 0 puts "Sorry you cannot make that withdrawal without depositing more money." else - puts "As this transaction puts your balance below $#{@min_balance}, a fee of $#{@fee} has been imposed." - @balance -= (amount_to_withdraw + @fee) + puts "As this transaction puts your balance below $#{@min_balance}, a fee of $#{@money_market_fee} has been imposed." + @balance -= (amount_to_withdraw + @money_market_fee) puts "Your balance is $#{@balance}" end else diff --git a/lib/money_market_account.rb b/lib/money_market_account.rb index 2e69f995..b116b228 100644 --- a/lib/money_market_account.rb +++ b/lib/money_market_account.rb @@ -7,6 +7,7 @@ def initialize(id, initial_balance, open_date) @transactions = 0 @min_balance = 10000 @fee = 0 + @money_market_fee = 100 @acct_type = "MoneyMarket" if initial_balance.to_i/100.00 < @min_balance From cbb30eff55c5c0c64f9602e3deca96e6a459c8fc Mon Sep 17 00:00:00 2001 From: noglows Date: Fri, 9 Oct 2015 14:38:34 -0700 Subject: [PATCH 11/26] Fixed bug in withdraw method and added add_interest method to parent class --- lib/account.rb | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 3a890681..a2c58f1c 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,4 +1,6 @@ require 'pry' +require 'csv' + module Bank class Account @@ -8,13 +10,13 @@ class Account def initialize(id, initial_balance, open_date) @id = id.to_i - @balance = initial_balance.to_i/100.00 + #@balance = initial_balance.to_i/100.00 + @balance = initial_balance.to_i @open_date = open_date @min_balance = 0 @fee = 0 - @acct_type = nil + #@acct_type = "Account" #open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %z") - #@owner = nil # Raises an argument error if the initial balance is less than 0 if initial_balance.to_i < @min_balance @@ -28,7 +30,9 @@ def self.all @accounts = [] accounts_csv = CSV.read("support/accounts.csv") accounts_csv.each do |id, balance, date| - id = Bank::Account.new(id,balance,date) + balance = balance.to_i/100 + date = DateTime.strptime(date, "%Y-%m-%d %H:%M:%S %z") + id = Bank::Account.new(id, balance ,date) @accounts.push(id) end #puts @accounts @@ -88,18 +92,22 @@ def self.find_and_display(id_search) # Method for withdrawing from account def withdraw(orig_amount_to_withdraw) - orig_amount_to_withdraw = orig_amount_to_withdraw/100.00 + #orig_amount_to_withdraw = orig_amount_to_withdraw/100.00 amount_to_withdraw = orig_amount_to_withdraw + @fee # Checks that the user is not withdrawing more than what is available in the account + + # if the requested withdrawal is more than the minimum balance if (@balance - amount_to_withdraw) < @min_balance + # If we are dealing with a MoneyMarket account if @acct_type == "MoneyMarket" - if (@balance - amount_to_withdraw - @money_market_fee) < 0 + if (@balance - amount_to_withdraw - @money_market_fee) < 0 || @allowed_to_withdraw == false puts "Sorry you cannot make that withdrawal without depositing more money." else puts "As this transaction puts your balance below $#{@min_balance}, a fee of $#{@money_market_fee} has been imposed." @balance -= (amount_to_withdraw + @money_market_fee) puts "Your balance is $#{@balance}" + @allowed_to_withdraw = false end else puts "The requested withdrawal is more than the available funds." @@ -140,6 +148,15 @@ def current_balance puts "This account was set up on #{@open_date}" end + def add_interest(rate) + if acct_type == "MoneyMarket" || acct_type == "Savings" + interest = @balance * rate/100 + @balance += interest + return interest + else + puts "This type of account does not accumulate interest." + end + end end From aaa58fb17046b494e9d10cea57b57128da701580 Mon Sep 17 00:00:00 2001 From: noglows Date: Fri, 9 Oct 2015 14:39:02 -0700 Subject: [PATCH 12/26] Fixed bugs in money market account --- lib/money_market_account.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/money_market_account.rb b/lib/money_market_account.rb index b116b228..e9831844 100644 --- a/lib/money_market_account.rb +++ b/lib/money_market_account.rb @@ -9,8 +9,9 @@ def initialize(id, initial_balance, open_date) @fee = 0 @money_market_fee = 100 @acct_type = "MoneyMarket" + @allowed_to_withdraw = true - if initial_balance.to_i/100.00 < @min_balance + if initial_balance.to_f < @min_balance raise ArgumentError, "The balance cannot be less than $#{@min_balance}." end end @@ -42,6 +43,10 @@ def deposit(amount) end end + def add_interest(rate) + super + end + def reset_transactions @transactions = 0 end From 8b98e5a90b2387754d74db527cb33f10785060b7 Mon Sep 17 00:00:00 2001 From: noglows Date: Fri, 9 Oct 2015 14:39:35 -0700 Subject: [PATCH 13/26] Modified checking and savings account to take dollars as input instead of cents --- lib/checking_account.rb | 3 +++ lib/savings_account.rb | 7 +++---- to-fix.txt | 5 +++++ 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 to-fix.txt diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 0f168661..3222555f 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -6,6 +6,7 @@ def initialize(id, initial_balance, open_date) super @fee = 1.0 @check_number = 1 + #@acct_type = "CheckingAccount" #@min_balance = 0 end @@ -23,6 +24,7 @@ def withdraw_using_check(amount_to_withdraw) if @balance != initial_balance @check_number +=1 end + @fee = 1.0 else @fee = 2.0 @min_balance = -10 @@ -31,6 +33,7 @@ def withdraw_using_check(amount_to_withdraw) @check_number +=1 end @min_balance = 0 + @fee = 1.0 end return @balance end diff --git a/lib/savings_account.rb b/lib/savings_account.rb index 752d8967..a98d50c5 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -8,9 +8,10 @@ def initialize(id, initial_balance, open_date) super @min_balance = 10.0 @fee = 2.0 + @acct_type = "Savings" #Raises an argument error if the initial balance is less than 0 - if initial_balance.to_i/100.00 < @min_balance + if initial_balance.to_f < @min_balance raise ArgumentError, "The balance cannot be less than $#{@min_balance}." end end @@ -21,9 +22,7 @@ def withdraw(orig_amount_to_withdraw) end def add_interest(rate) - interest = @balance * rate/100 - @balance += interest - return interest + super end diff --git a/to-fix.txt b/to-fix.txt new file mode 100644 index 00000000..cc2ab529 --- /dev/null +++ b/to-fix.txt @@ -0,0 +1,5 @@ +Return two places for dollar amounts +Floats instead of to_i +Check returns +Change overdraft wording +Pull owner out of account From 06832af4d82aee9c589f16c948b08b91c20bcf8e Mon Sep 17 00:00:00 2001 From: noglows Date: Fri, 9 Oct 2015 14:45:00 -0700 Subject: [PATCH 14/26] Cleaning up files --- bank.rb | 225 -------------------------------------------------------- 1 file changed, 225 deletions(-) delete mode 100644 bank.rb diff --git a/bank.rb b/bank.rb deleted file mode 100644 index c33d9bb9..00000000 --- a/bank.rb +++ /dev/null @@ -1,225 +0,0 @@ -require 'csv' -require 'pry' - -module Bank - class Account - - attr_reader :balance, :id - attr_accessor :owner - - def initialize(id, initial_balance, open_date) - @id = id.to_i - @balance = initial_balance.to_i/100.00 - @open_date = open_date - @min_balance = 0 - #open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %z") - #@owner = nil - - # Raises an argument error if the initial balance is less than 0 - if initial_balance.to_i < 0 - raise ArgumentError, "The balance cannot be less than 0." - end - end - - # Creates accounts from the accounts.csv file - def self.all - @accounts = [] - accounts_csv = CSV.read("support/accounts.csv") - accounts_csv.each do |id, balance, date| - id = Bank::Account.new(id,balance,date) - @accounts.push(id) - end - #puts @accounts - return @accounts - end - - # Finds the account with the ID that matches the passed parameter and returns the instance - def self.find(id_search) - found = @accounts.find do |account| - account.id == id_search - end - return found - end - - # Links owners with accounts - def self.link_owner - self.all - Bank::Owner.all - accounts_with_owners = [] - account_owners_csv = CSV.read("support/account_owners.csv") - account_owners_csv.each do |row| - account = self.find(row[0].to_i) - owner_account = Bank::Owner.find(row[1].to_i) - account.owner = owner_account - accounts_with_owners.push(account) - end - return accounts_with_owners - end - - # ----------------------------------------- # - # Work below is extra # - - # Displays (with formatting) the account details for all the accounts in accounts.csv - # (Made this on accident and didn't want to let it go to waste!) - def self.all_print_nice - if @accounts == nil - puts "There are no accounts." - else - @accounts.each do |account| - puts account - account.current_balance - end - end - return - end - - # Finds an account by id passed in as a parameter and displays the account information nicely formatted - # (Made this on accident and didn't want to let it go to waste!) - def self.find_and_display(id_search) - found = @accounts.find do |account| - account.id == id_search - end - return found.current_balance - end - # end of extra work # -# ----------------------------------------# - - # Method for withdrawing from account - def withdraw(amount_to_withdraw) - # Checks that the user is not withdrawing more than what is available in the account - if (@balance - amount_to_withdraw)< @min_balance - puts "The requested withdrawal is more than the available funds." - puts "You only have $#{@balance-@min_balance} available for withdrawal." - return @balance - else - # makes the withdrawal and displays info to the user - @balance -= amount_to_withdraw - puts "You have withdrawn $#{amount_to_withdraw}." - puts "Your current balance is $#{@balance}" - return @balance - end - end - - # Method for depositing into account - def deposit(amount_to_deposit) - # Makes the deposit and displays info to the user - @balance += amount_to_deposit - puts "You have deposited $#{amount_to_deposit}." - puts "Your current balance is $#{@balance}." - return @balance - end - - # Displays current balance in the account - def current_balance - puts "The account with ID #{@id} currently has a balance of $#{@balance}." - puts "This account was set up on #{@open_date}" - end - - - end - - class Owner - attr_reader :first_name, :last_name, :street, :city, :state, :id - - def initialize(owner_hash) - @id = owner_hash[:id] - @first_name = owner_hash[:first_name] - @last_name = owner_hash[:last_name] - @street_address = owner_hash[:street_address] - @city = owner_hash[:city] - @state = owner_hash[:state] - end - - # Method to display details of an owner instance - def print_owner_details - puts "The owner of this account is #{@first_name} #{@last_name}." - puts "Street: #{@street_address}" - puts "City: #{@city}" - puts "State: #{@state}" - end - - # Creates accounts from the accounts.csv file - def self.all - owner_hash = Hash.new - @owners = [] - owners_csv = CSV.read("support/owners.csv") - owners_csv.each do |id, last_name, first_name, street_address, city, state| - owner_hash[:id] = id.to_i - owner_hash[:last_name] = last_name - owner_hash[:first_name] = first_name - owner_hash[:street_address] = street_address - owner_hash[:city] = city - owner_hash[:state] = state - id = Bank::Owner.new(owner_hash) - @owners.push(id) - end - puts @owners - return @owners - end - - # Finds the owner with the ID that matches the passed parameter and returns the instance - def self.find(id_search) - found = @owners.find do |owner| - owner.id == id_search - end - return found - end - - -# ----------------------------------------- # - # Work below is extra # - - # Displays (with formatting) the owner details for all the accounts in owners.csv - def self.all_print_nice - if @owners == nil - puts "There are no accounts." - else - @owners.each do |owner| - owner.print_owner_details - end - end - return - end - - # Finds an owner by id passed in as a parameter and displays the owner information nicely formatted - def self.find_and_display(id_search) - found = @owners.find do |owner| - owner.id == id_search - end - return found.print_owner_details - end - - # end of extra work # -# ----------------------------------------# - - end - - - - - - - - - class SavingsAccount < Account - - def initialize(id, initial_balance, open_date) - #@id = id.to_i - @balance = initial_balance.to_i/100.0 - #@open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %z") - #@owner = nil - @min_balance = 10 - - # Raises an argument error if the initial balance is less than 0 - if initial_balance.to_i < 10 - raise ArgumentError, "The balance cannot be less than $10." - end - end - - def withdraw(amount_to_withdraw) - super - end - - end - -end From 6a7a92d0c9689118f01e566717f026c274b9bc4a Mon Sep 17 00:00:00 2001 From: noglows Date: Fri, 9 Oct 2015 14:45:29 -0700 Subject: [PATCH 15/26] Cleaning up file names --- bank2.rb => bank.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename bank2.rb => bank.rb (100%) diff --git a/bank2.rb b/bank.rb similarity index 100% rename from bank2.rb rename to bank.rb From c021e14721b6c11f9ef9548172cd91cc5ccf3b42 Mon Sep 17 00:00:00 2001 From: noglows Date: Fri, 9 Oct 2015 14:46:22 -0700 Subject: [PATCH 16/26] Created retired files folder --- bank_interaction.rb => retired/bank_interaction.rb | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename bank_interaction.rb => retired/bank_interaction.rb (100%) diff --git a/bank_interaction.rb b/retired/bank_interaction.rb similarity index 100% rename from bank_interaction.rb rename to retired/bank_interaction.rb From 7d83da6c64cde950bb7290f5dcda8a642bd32606 Mon Sep 17 00:00:00 2001 From: noglows Date: Fri, 9 Oct 2015 15:09:04 -0700 Subject: [PATCH 17/26] All outputs to the user round to two decimal places --- lib/account.rb | 113 +++++++----------------------------- lib/money_market_account.rb | 4 +- 2 files changed, 22 insertions(+), 95 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index a2c58f1c..0a6e53b5 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,5 +1,6 @@ require 'pry' require 'csv' +require './lib/owner.rb' module Bank class Account @@ -9,17 +10,17 @@ class Account def initialize(id, initial_balance, open_date) - @id = id.to_i - #@balance = initial_balance.to_i/100.00 - @balance = initial_balance.to_i + @id = id + @balance = initial_balance.to_f.round(2) @open_date = open_date @min_balance = 0 @fee = 0 + @owner = nil #@acct_type = "Account" #open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %z") # Raises an argument error if the initial balance is less than 0 - if initial_balance.to_i < @min_balance + if initial_balance.to_f < @min_balance raise ArgumentError, "The balance cannot be less than 0." end end @@ -30,7 +31,7 @@ def self.all @accounts = [] accounts_csv = CSV.read("support/accounts.csv") accounts_csv.each do |id, balance, date| - balance = balance.to_i/100 + balance = balance.to_f.round(2)/100 date = DateTime.strptime(date, "%Y-%m-%d %H:%M:%S %z") id = Bank::Account.new(id, balance ,date) @accounts.push(id) @@ -42,7 +43,7 @@ def self.all # Finds the account with the ID that matches the passed parameter and returns the instance def self.find(id_search) found = @accounts.find do |account| - account.id == id_search + account.id == id_search.to_s end return found end @@ -54,7 +55,8 @@ def self.link_owner accounts_with_owners = [] account_owners_csv = CSV.read("support/account_owners.csv") account_owners_csv.each do |row| - account = self.find(row[0].to_i) + #binding.pry + account = self.find(row[0]) owner_account = Bank::Owner.find(row[1].to_i) account.owner = owner_account accounts_with_owners.push(account) @@ -83,7 +85,7 @@ def self.all_print_nice # (Made this on accident and didn't want to let it go to waste!) def self.find_and_display(id_search) found = @accounts.find do |account| - account.id == id_search + account.id == id_search.to_s end return found.current_balance end @@ -104,9 +106,9 @@ def withdraw(orig_amount_to_withdraw) if (@balance - amount_to_withdraw - @money_market_fee) < 0 || @allowed_to_withdraw == false puts "Sorry you cannot make that withdrawal without depositing more money." else - puts "As this transaction puts your balance below $#{@min_balance}, a fee of $#{@money_market_fee} has been imposed." + puts "As this transaction puts your balance below $#{@min_balance.round(2)}, a fee of $#{@money_market_fee.round(2)} has been imposed." @balance -= (amount_to_withdraw + @money_market_fee) - puts "Your balance is $#{@balance}" + puts "Your balance is $#{@balance.round(2)}" @allowed_to_withdraw = false end else @@ -114,7 +116,7 @@ def withdraw(orig_amount_to_withdraw) if (@balance-@min_balance-@fee) < 0 puts "You have no money left to withdraw." else - puts "You only have $#{@balance-@min_balance-@fee} available for withdrawal." + puts "You only have $#{(@balance-@min_balance-@fee).round(2)} available for withdrawal." end end return @balance @@ -123,11 +125,11 @@ def withdraw(orig_amount_to_withdraw) @balance -= (amount_to_withdraw) # puts balance # puts amount_to_withdraw - puts "You have withdrawn $#{orig_amount_to_withdraw}" + puts "You have withdrawn $#{orig_amount_to_withdraw.round(2)}" if @fee != 0 - puts "You have also incurred a $#{@fee} fee." + puts "You have also incurred a $#{@fee.round(2)} fee." end - puts "Your current balance is $#{@balance}" + puts "Your current balance is $#{@balance.round(2)}" return @balance end end @@ -137,14 +139,14 @@ def withdraw(orig_amount_to_withdraw) def deposit(amount_to_deposit) # Makes the deposit and displays info to the user @balance += amount_to_deposit - puts "You have deposited $#{amount_to_deposit}." - puts "Your current balance is $#{@balance}." + puts "You have deposited $#{amount_to_deposit.round(2)}." + puts "Your current balance is $#{@balance.round(2)}." return @balance end # Displays current balance in the account def current_balance - puts "The account with ID #{@id} currently has a balance of $#{@balance}." + puts "The account with ID #{@id} currently has a balance of $#{@balance.round(2)}." puts "This account was set up on #{@open_date}" end @@ -152,6 +154,7 @@ def add_interest(rate) if acct_type == "MoneyMarket" || acct_type == "Savings" interest = @balance * rate/100 @balance += interest + puts "After adding interest, the balance is now $#{@balance.round(2)}" return interest else puts "This type of account does not accumulate interest." @@ -159,80 +162,4 @@ def add_interest(rate) end end - - class Owner - attr_reader :first_name, :last_name, :street, :city, :state, :id - - def initialize(owner_hash) - @id = owner_hash[:id] - @first_name = owner_hash[:first_name] - @last_name = owner_hash[:last_name] - @street_address = owner_hash[:street_address] - @city = owner_hash[:city] - @state = owner_hash[:state] - end - - # Method to display details of an owner instance - def print_owner_details - puts "The owner of this account is #{@first_name} #{@last_name}." - puts "Street: #{@street_address}" - puts "City: #{@city}" - puts "State: #{@state}" - end - - # Creates accounts from the accounts.csv file - def self.all - owner_hash = Hash.new - @owners = [] - owners_csv = CSV.read("support/owners.csv") - owners_csv.each do |id, last_name, first_name, street_address, city, state| - owner_hash[:id] = id.to_i - owner_hash[:last_name] = last_name - owner_hash[:first_name] = first_name - owner_hash[:street_address] = street_address - owner_hash[:city] = city - owner_hash[:state] = state - id = Bank::Owner.new(owner_hash) - @owners.push(id) - end - puts @owners - return @owners - end - - # Finds the owner with the ID that matches the passed parameter and returns the instance - def self.find(id_search) - found = @owners.find do |owner| - owner.id == id_search - end - return found - end - - -# ----------------------------------------- # - # Work below is extra # - - # Displays (with formatting) the owner details for all the accounts in owners.csv - def self.all_print_nice - if @owners == nil - puts "There are no accounts." - else - @owners.each do |owner| - owner.print_owner_details - end - end - return - end - - # Finds an owner by id passed in as a parameter and displays the owner information nicely formatted - def self.find_and_display(id_search) - found = @owners.find do |owner| - owner.id == id_search - end - return found.print_owner_details - end - - # end of extra work # -# ----------------------------------------# - - end end diff --git a/lib/money_market_account.rb b/lib/money_market_account.rb index e9831844..fdfa18ab 100644 --- a/lib/money_market_account.rb +++ b/lib/money_market_account.rb @@ -5,9 +5,9 @@ class MoneyMarketAccount < Account def initialize(id, initial_balance, open_date) super @transactions = 0 - @min_balance = 10000 + @min_balance = 10000.00 @fee = 0 - @money_market_fee = 100 + @money_market_fee = 100.00 @acct_type = "MoneyMarket" @allowed_to_withdraw = true From 35448bd16ca9ecc0840df3f07d7b236cc233bb12 Mon Sep 17 00:00:00 2001 From: noglows Date: Fri, 9 Oct 2015 15:18:35 -0700 Subject: [PATCH 18/26] Fixed more rounding errors --- lib/account.rb | 2 +- lib/savings_account.rb | 2 +- to-fix.txt | 3 --- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index 0a6e53b5..c834a122 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -151,7 +151,7 @@ def current_balance end def add_interest(rate) - if acct_type == "MoneyMarket" || acct_type == "Savings" + if @acct_type == "MoneyMarket" || @acct_type == "Savings" interest = @balance * rate/100 @balance += interest puts "After adding interest, the balance is now $#{@balance.round(2)}" diff --git a/lib/savings_account.rb b/lib/savings_account.rb index a98d50c5..f7eb654f 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -12,7 +12,7 @@ def initialize(id, initial_balance, open_date) #Raises an argument error if the initial balance is less than 0 if initial_balance.to_f < @min_balance - raise ArgumentError, "The balance cannot be less than $#{@min_balance}." + raise ArgumentError, "The balance cannot be less than $#{@min_balance.round(2)}." end end diff --git a/to-fix.txt b/to-fix.txt index cc2ab529..a8ee917f 100644 --- a/to-fix.txt +++ b/to-fix.txt @@ -1,5 +1,2 @@ -Return two places for dollar amounts -Floats instead of to_i Check returns Change overdraft wording -Pull owner out of account From 92ba7b1ae580f5c372adde6c3a61846a45deedfa Mon Sep 17 00:00:00 2001 From: noglows Date: Fri, 9 Oct 2015 16:10:48 -0700 Subject: [PATCH 19/26] Added comments to Money Market --- lib/money_market_account.rb | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/money_market_account.rb b/lib/money_market_account.rb index fdfa18ab..0b8d0721 100644 --- a/lib/money_market_account.rb +++ b/lib/money_market_account.rb @@ -1,7 +1,8 @@ module Bank class MoneyMarketAccount < Account - + # Money market has two fees - the normal withdrawal fee (@fee) and the fee assessed when the balance goes below 10_000 (@money_market_fee) + # Money Market has a transactions variable to keep track of the numer of transactions for the month (no other account has this) def initialize(id, initial_balance, open_date) super @transactions = 0 @@ -9,44 +10,45 @@ def initialize(id, initial_balance, open_date) @fee = 0 @money_market_fee = 100.00 @acct_type = "MoneyMarket" - @allowed_to_withdraw = true + # Check that the initial balance is above min_balance if initial_balance.to_f < @min_balance raise ArgumentError, "The balance cannot be less than $#{@min_balance}." end end - # def check_transactions - # if @transactions >= 6 - # puts "You cannot make any more transactions this month." - # else - # super - # transactions += 1 - # end - # end def withdraw(amount) + # If you have made more than 6 transactions, the transaction will not go through if @transactions >= 6 puts "You cannot make any more transactions this month." else + # If you have made fewer than 6 transactions, MoneyMarket uses the Account withdraw method and increments @transactions super @transactions += 1 end end def deposit(amount) - if @transactions >= 6 + # If the balance is below min balance, the user can make a deposit even if they have hit max transactions + if @balance < @min_balance + super + # If the balance is not below min balance and the user has made more than 6 transactions, the transaction will not go through + elsif @transactions >= 6 puts "You cannot make any more transactions this month." else + # If the balace is above min balance and the transactions are below 6, MoneyMarket uses the Account deposit method and increments @transactions super @transactions += 1 end end - + # The MoneyMarket account calls the add_interest method directly from Accounts + # This line is not necessary, but it being kept in for clarity def add_interest(rate) super end + # Method to reset the @transactions variabale and allow additional transactions def reset_transactions @transactions = 0 end From 50509e678c1d1b2272350ec8539f21d025350407 Mon Sep 17 00:00:00 2001 From: noglows Date: Fri, 9 Oct 2015 16:17:21 -0700 Subject: [PATCH 20/26] Added comments to checking account --- lib/checking_account.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/checking_account.rb b/lib/checking_account.rb index 3222555f..1dec7b4b 100644 --- a/lib/checking_account.rb +++ b/lib/checking_account.rb @@ -6,38 +6,42 @@ def initialize(id, initial_balance, open_date) super @fee = 1.0 @check_number = 1 - #@acct_type = "CheckingAccount" - #@min_balance = 0 end + # CheckingAccount uses the withdraw method from Account + # This method does not need to be called here, but is left in for clarity def withdraw(amount_to_withdraw) super end def withdraw_using_check(amount_to_withdraw) initial_balance = @balance + # min_balance is set to -10 for check withdrawals + @min_balance = -10 + # If the customer has used fewer than 3 checks, the fee is set to 0, and the withdraw method from Account is run if @check_number <= 3 @fee = 0 - @min_balance = -10.0 withdraw(amount_to_withdraw) - @min_balance = 0 + # If a successful withdrawal was made, the check number is incremented if @balance != initial_balance @check_number +=1 end - @fee = 1.0 else + # If the user has used more than 3 checks, the fee is updated and the withdraw method from Account is run @fee = 2.0 - @min_balance = -10 withdraw(amount_to_withdraw) + # If a successul withdrawal was made the check number is incremented if @balance != initial_balance @check_number +=1 end - @min_balance = 0 - @fee = 1.0 end + # Resets min_balance and fee to the defaults in initialize (necessary for normal withdraw method to function as expected) + @min_balance = 0 + @fee = 1.0 return @balance end + # Resets @check_number variable to allow more withdrawals using check def reset_checks @check_number = 0 end From 0073289650e8532937802f1ad0e16ee4e8c497cd Mon Sep 17 00:00:00 2001 From: noglows Date: Fri, 9 Oct 2015 16:19:01 -0700 Subject: [PATCH 21/26] Added comments to savings account --- lib/savings_account.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/savings_account.rb b/lib/savings_account.rb index f7eb654f..ef972f88 100644 --- a/lib/savings_account.rb +++ b/lib/savings_account.rb @@ -1,13 +1,11 @@ -require 'pry' module Bank - - class SavingsAccount < Account def initialize(id, initial_balance, open_date) super @min_balance = 10.0 @fee = 2.0 + # Acct_type variable allows add_interest method from Account to function correctly for Savings Account @acct_type = "Savings" #Raises an argument error if the initial balance is less than 0 @@ -16,11 +14,14 @@ def initialize(id, initial_balance, open_date) end end - # Rewrote the withdraw method in account so that only a super is needed - This line could come out but is being kept in for clarity. + # Savings Account uses the withdraw method from Account + # This line could come out but is being kept in for clarity. def withdraw(orig_amount_to_withdraw) super end + # Savings Account uses the add_interest method from Account + # This line could come out but is being kept in for clarity. def add_interest(rate) super end From f418c1f3e3aabc0dabc8fcc7206c32873dc52bfb Mon Sep 17 00:00:00 2001 From: noglows Date: Fri, 9 Oct 2015 16:19:53 -0700 Subject: [PATCH 22/26] Comment to bank.rb file --- bank.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bank.rb b/bank.rb index 98640984..1804de38 100644 --- a/bank.rb +++ b/bank.rb @@ -1,3 +1,5 @@ +# Master bank file +# Requires all the seperate class files for Bank Accounts require './lib/account.rb' require './lib/owner.rb' require './lib/savings_account.rb' From 3ee88816e2279d2aca46f6ce9c90adc77b3abeeb Mon Sep 17 00:00:00 2001 From: noglows Date: Fri, 9 Oct 2015 16:20:21 -0700 Subject: [PATCH 23/26] Removed the to-do.txt file --- to-fix.txt | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 to-fix.txt diff --git a/to-fix.txt b/to-fix.txt deleted file mode 100644 index a8ee917f..00000000 --- a/to-fix.txt +++ /dev/null @@ -1,2 +0,0 @@ -Check returns -Change overdraft wording From b10b425519b36749ef96239a603731059f3d8763 Mon Sep 17 00:00:00 2001 From: noglows Date: Mon, 12 Oct 2015 11:01:17 -0700 Subject: [PATCH 24/26] Finished comment and fixed money market bug --- lib/account.rb | 29 ++++++++++++++--------------- lib/money_market_account.rb | 1 + 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/account.rb b/lib/account.rb index c834a122..de53fbc4 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,4 +1,3 @@ -require 'pry' require 'csv' require './lib/owner.rb' @@ -6,7 +5,7 @@ module Bank class Account attr_reader :balance, :id - attr_accessor :owner, :min_balance, :fee, :acct_type + attr_accessor :owner, :min_balance, :fee, :acct_type, :allowed_to_withdraw def initialize(id, initial_balance, open_date) @@ -16,8 +15,6 @@ def initialize(id, initial_balance, open_date) @min_balance = 0 @fee = 0 @owner = nil - #@acct_type = "Account" - #open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %z") # Raises an argument error if the initial balance is less than 0 if initial_balance.to_f < @min_balance @@ -25,23 +22,24 @@ def initialize(id, initial_balance, open_date) end end - # Creates accounts from the accounts.csv file def self.all @accounts = [] accounts_csv = CSV.read("support/accounts.csv") + # For each line in accounts pass the id, balance, and date (formatted as need be) into a new Bank Account object accounts_csv.each do |id, balance, date| balance = balance.to_f.round(2)/100 date = DateTime.strptime(date, "%Y-%m-%d %H:%M:%S %z") id = Bank::Account.new(id, balance ,date) + # Push the new account into the @accounts array @accounts.push(id) end - #puts @accounts return @accounts end # Finds the account with the ID that matches the passed parameter and returns the instance def self.find(id_search) + # Looks in @accounts array for a matching ID value found = @accounts.find do |account| account.id == id_search.to_s end @@ -50,12 +48,13 @@ def self.find(id_search) # Links owners with accounts def self.link_owner + # Creates Account and Owner arrays (calls Account and Owner self.all methods) self.all Bank::Owner.all accounts_with_owners = [] account_owners_csv = CSV.read("support/account_owners.csv") + # for each row in the account_owners_csv.each do |row| - #binding.pry account = self.find(row[0]) owner_account = Bank::Owner.find(row[1].to_i) account.owner = owner_account @@ -94,25 +93,26 @@ def self.find_and_display(id_search) # Method for withdrawing from account def withdraw(orig_amount_to_withdraw) - #orig_amount_to_withdraw = orig_amount_to_withdraw/100.00 - amount_to_withdraw = orig_amount_to_withdraw + @fee - # Checks that the user is not withdrawing more than what is available in the account - - # if the requested withdrawal is more than the minimum balance + # check if the requested withdrawal is more than the minimum balance if (@balance - amount_to_withdraw) < @min_balance - # If we are dealing with a MoneyMarket account + # If we are dealing with a MoneyMarket account, we do special withdrawal behavior + # Keeping this here instead of in Money Market prevented us from having to rewrite an entire withdraw function for Money Market (we can just super the Account method) if @acct_type == "MoneyMarket" + # Checks that the withdrawal won't put you below 0 or if you are no longer allowed to withdraw if (@balance - amount_to_withdraw - @money_market_fee) < 0 || @allowed_to_withdraw == false puts "Sorry you cannot make that withdrawal without depositing more money." else + # If the withdrawal goes below min balance a fee is imposed and no further withdrawals are permitted puts "As this transaction puts your balance below $#{@min_balance.round(2)}, a fee of $#{@money_market_fee.round(2)} has been imposed." @balance -= (amount_to_withdraw + @money_market_fee) puts "Your balance is $#{@balance.round(2)}" @allowed_to_withdraw = false end else + # If account is not Money Market, normal withdrawal behavior for attempting to withdraw too much puts "The requested withdrawal is more than the available funds." + # Works for all account types, min balance and fee vary by account type if (@balance-@min_balance-@fee) < 0 puts "You have no money left to withdraw." else @@ -123,8 +123,6 @@ def withdraw(orig_amount_to_withdraw) else # makes the withdrawal and displays info to the user @balance -= (amount_to_withdraw) - # puts balance - # puts amount_to_withdraw puts "You have withdrawn $#{orig_amount_to_withdraw.round(2)}" if @fee != 0 puts "You have also incurred a $#{@fee.round(2)} fee." @@ -151,6 +149,7 @@ def current_balance end def add_interest(rate) + # Add interest only runs for the MoneyMarket and Savings account if @acct_type == "MoneyMarket" || @acct_type == "Savings" interest = @balance * rate/100 @balance += interest diff --git a/lib/money_market_account.rb b/lib/money_market_account.rb index 0b8d0721..ace30132 100644 --- a/lib/money_market_account.rb +++ b/lib/money_market_account.rb @@ -51,6 +51,7 @@ def add_interest(rate) # Method to reset the @transactions variabale and allow additional transactions def reset_transactions @transactions = 0 + @allowed_to_withdraw = true end end From e2ef83eb372bc1306390faf166b98fe623e2137a Mon Sep 17 00:00:00 2001 From: noglows Date: Mon, 12 Oct 2015 11:09:05 -0700 Subject: [PATCH 25/26] Fixed Money Market withdrawal bug --- lib/account.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/account.rb b/lib/account.rb index de53fbc4..0067acbc 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -139,6 +139,10 @@ def deposit(amount_to_deposit) @balance += amount_to_deposit puts "You have deposited $#{amount_to_deposit.round(2)}." puts "Your current balance is $#{@balance.round(2)}." + # Special case to allow Money Market account to make withdrawals again + if @acct_type == "MoneyMarket" && @balance > min_balance + @allowed_to_withdraw = true + end return @balance end From 76268ff0a0049937abf942dcb43eb39ac61540f2 Mon Sep 17 00:00:00 2001 From: noglows Date: Mon, 12 Oct 2015 11:10:48 -0700 Subject: [PATCH 26/26] Removed owner require from Account --- lib/account.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/account.rb b/lib/account.rb index 0067acbc..5a3a6272 100644 --- a/lib/account.rb +++ b/lib/account.rb @@ -1,5 +1,5 @@ require 'csv' -require './lib/owner.rb' +#require './lib/owner.rb' module Bank class Account