From ce31762142e4d2676043b7232ecda9615828b14d Mon Sep 17 00:00:00 2001 From: justine Date: Mon, 29 Feb 2016 14:13:31 -0800 Subject: [PATCH 01/24] Created Bank module. --- bank_accounts.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 bank_accounts.rb diff --git a/bank_accounts.rb b/bank_accounts.rb new file mode 100644 index 00000000..5768300c --- /dev/null +++ b/bank_accounts.rb @@ -0,0 +1,22 @@ +# Bank Accounts 2.29.16 Justine Winnie +### Primary Functionality +# 1. Create a `Bank` module which will contain your `Account` class and any future bank account logic. +# 1. Create an `Account` class which should have the following functionality: +# - A new account should be created with an __ID__ and an __initial balance__ +# - Should have a `withdraw` method that accepts a single parameter which represents the amount of money that will be withdrawn. This method should return the updated account balance. +# - Should have a `deposit` method that accepts a single parameter which represents the amount of money that will be deposited. This method should return the updated account balance. +# - Should be able to access the current `balance` of an account at any time. + + # Example code: + # module Gym + # class Push + # def up + # 40 + # end + # end + # end + # require "gym" + +module Bank + +end From a074ee388ca418ba69376228a566cbec43781d4f Mon Sep 17 00:00:00 2001 From: justine Date: Mon, 29 Feb 2016 14:20:08 -0800 Subject: [PATCH 02/24] Created Account class; initialize, withdraw, and deposit methods. --- bank_accounts.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bank_accounts.rb b/bank_accounts.rb index 5768300c..f52657fd 100644 --- a/bank_accounts.rb +++ b/bank_accounts.rb @@ -18,5 +18,21 @@ # require "gym" module Bank + class Account + # initialize method creates instance of Account class with @instance variables @id and @init_balance + def initialize(Accountdata) + @id = Accountdata[:id] # float? provided from csv? + @init_balance = Accountdata[:init_balance] #float + end + # withdraw method accepts a single parameter which represents the amount of the withdrawal. method should return the updated account balance. + def withdraw + + end + + # deposit method accepts a single parameter which represents the amount of the deposit. method should return the updated account balance. + def deposit + + end + end end From 02f5bb4039f0a27fd504816f333e99e91374cc5c Mon Sep 17 00:00:00 2001 From: justine Date: Mon, 29 Feb 2016 14:39:52 -0800 Subject: [PATCH 03/24] Trying to differentiate init_balance and balance. Added balance method to return balance at any time. --- bank_accounts.rb | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/bank_accounts.rb b/bank_accounts.rb index f52657fd..63c6e626 100644 --- a/bank_accounts.rb +++ b/bank_accounts.rb @@ -19,20 +19,31 @@ module Bank class Account - # initialize method creates instance of Account class with @instance variables @id and @init_balance - def initialize(Accountdata) - @id = Accountdata[:id] # float? provided from csv? - @init_balance = Accountdata[:init_balance] #float + # initialize method creates instance of Account class with @instance variables @id, @init_balance, and balance + def initialize(accountdata) + @id = accountdata[:id] # float? provided from csv? + @init_balance = accountdata[:init_balance] #float + @balance = accountdata[:init_balance]# float end # withdraw method accepts a single parameter which represents the amount of the withdrawal. method should return the updated account balance. - def withdraw - + def withdraw(withdrawal) + if @init_balance == @balance + @balance = @balance - withdrawal + else @balance = @init_balance - withdrawal + end + return @balance end # deposit method accepts a single parameter which represents the amount of the deposit. method should return the updated account balance. - def deposit + def deposit(deposit) + if @init_balance == @balance + end + end + def balance + return @balance end + end end From 68d4ebacbf941b423738f57f34a725c6a7c10103 Mon Sep 17 00:00:00 2001 From: justine Date: Mon, 29 Feb 2016 15:10:32 -0800 Subject: [PATCH 04/24] Added errors, fixed @init_balance and @balance. Added ArgumentError when user tries to initialize new Account with a negative balance. Added warning message and abort withdrawal when user tries to overdraw account. Tracking @init_balance and @balance in separate variables so user can go back and look at their initial balance, and so the code looks cuter (seeing @init_balance all the time = bothersome). --- bank_accounts.rb | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/bank_accounts.rb b/bank_accounts.rb index 63c6e626..a8742cd4 100644 --- a/bank_accounts.rb +++ b/bank_accounts.rb @@ -17,33 +17,49 @@ # end # require "gym" +### Error handling + # 1. A new account cannot be created with initial negative balance - this will `raise` an `ArgumentError` (Google this) + # 1. The `withdraw` method does not allow the account to go negative - Will `puts` a warning message and then return the original un-modified balance + module Bank class Account # initialize method creates instance of Account class with @instance variables @id, @init_balance, and balance def initialize(accountdata) @id = accountdata[:id] # float? provided from csv? @init_balance = accountdata[:init_balance] #float - @balance = accountdata[:init_balance]# float + @balance = accountdata[:balance]# float + # @init_balance = @balance + if @init_balance < 0 + raise ArgumentError.new("Account cannot be initialized with a negative balance.") + end + # set @balance to value of @init_balance + @balance = @init_balance end + # withdraw method accepts a single parameter which represents the amount of the withdrawal. method should return the updated account balance. def withdraw(withdrawal) - if @init_balance == @balance - @balance = @balance - withdrawal - else @balance = @init_balance - withdrawal + if @balance - withdrawal >= 0 + @balance -= withdrawal + else puts "Withdrawal cannot be completed with available funds." + balance end - return @balance end # deposit method accepts a single parameter which represents the amount of the deposit. method should return the updated account balance. def deposit(deposit) - if @init_balance == @balance - end + @balance += deposit + balance end def balance return @balance end + # just checking to see if differentiating @init_balance and @balance worked. + # def initial_balance + # return @init_balance + # end + end end From dc0f41e4d0df557e76ccdffae68b148505b47515 Mon Sep 17 00:00:00 2001 From: justine Date: Tue, 1 Mar 2016 09:57:05 -0800 Subject: [PATCH 05/24] Created add_owner method to the Account class. This allows the user to instantiate an Owner and then associate that owner with an already existing instance of Account. --- bank_accounts.rb | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/bank_accounts.rb b/bank_accounts.rb index a8742cd4..c60185f2 100644 --- a/bank_accounts.rb +++ b/bank_accounts.rb @@ -22,12 +22,16 @@ # 1. The `withdraw` method does not allow the account to go negative - Will `puts` a warning message and then return the original un-modified balance module Bank + + require "money" + class Account # initialize method creates instance of Account class with @instance variables @id, @init_balance, and balance def initialize(accountdata) + @owner = accountdata[:owner] @id = accountdata[:id] # float? provided from csv? - @init_balance = accountdata[:init_balance] #float - @balance = accountdata[:balance]# float + @init_balance = accountdata[:init_balance].to_f #float + @balance = accountdata[:balance].to_f # float # @init_balance = @balance if @init_balance < 0 raise ArgumentError.new("Account cannot be initialized with a negative balance.") @@ -36,6 +40,9 @@ def initialize(accountdata) @balance = @init_balance end + # def money_print + # Money.new(@balance, "USD").to_f + # end # withdraw method accepts a single parameter which represents the amount of the withdrawal. method should return the updated account balance. def withdraw(withdrawal) @@ -53,7 +60,7 @@ def deposit(deposit) end def balance - return @balance + @balance end # just checking to see if differentiating @init_balance and @balance worked. @@ -61,5 +68,26 @@ def balance # return @init_balance # end + # add an owner (instance of Owner class, below) to an already existing account. + def add_owner(owner) + @owner = owner + end + + end + + class Owner + def initialize(ownerdata) + @title = ownerdata[:title] + @first_name = ownerdata[:first_name] + @middle_init = ownerdata[:middle_init] + @last_name = ownerdata[:last_name] + @street_address = ownerdata[:street_address] + @street_address2 = ownerdata[:street_address2] + @city = ownerdata[:city] + @state = ownerdata[:state] + @zip = ownerdata[:zip] + @cell = ownerdata[:cell] + @email = ownerdata[:email] + end end end From cd0f0b75e58abd27f2cbe44805a8a8c644fe79e3 Mon Sep 17 00:00:00 2001 From: justine Date: Tue, 1 Mar 2016 15:27:31 -0800 Subject: [PATCH 06/24] Time for Wave 2! Setup. --- bank_accounts.rb | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/bank_accounts.rb b/bank_accounts.rb index c60185f2..85b9da0e 100644 --- a/bank_accounts.rb +++ b/bank_accounts.rb @@ -21,21 +21,41 @@ # 1. A new account cannot be created with initial negative balance - this will `raise` an `ArgumentError` (Google this) # 1. The `withdraw` method does not allow the account to go negative - Will `puts` a warning message and then return the original un-modified balance + + # Wave 2: CSV Files! + # + # Primary Requirements + # + # Update the Account class to be able to handle all of these fields from the CSV file used as input. + # For example, manually choose the data from the first line of the CSV file and ensure you can create a new instance of your Account using that data + # Add the following class methods to your existing Account class + # self.all - returns a collection of Account instances, representing all of the Accounts described in the CSV. See below for the CSV file specifications + # self.find(id) - returns an instance of Account where the value of the id field in the CSV matches the passed parameter + # CSV Data File for Bank::Account + # + # The data, in order in the CSV, consists of: + # + # ID - (Fixnum) a unique identifier for that Account + # Balance - (Fixnum) the account balance amount, in cents (i.e., 150 would be $1.50) + # OpenDate - (Datetime) when the account was opened + module Bank - require "money" + # require "money" class Account # initialize method creates instance of Account class with @instance variables @id, @init_balance, and balance def initialize(accountdata) - @owner = accountdata[:owner] - @id = accountdata[:id] # float? provided from csv? + @owner = accountdata[:owner] # string + @id = accountdata[:id] # fixnum? provided from csv? + @balance + @open_date @init_balance = accountdata[:init_balance].to_f #float + if @init_balance < 0 + raise ArgumentError.new("Account cannot be initialized with a negative balance.") + end @balance = accountdata[:balance].to_f # float - # @init_balance = @balance - if @init_balance < 0 - raise ArgumentError.new("Account cannot be initialized with a negative balance.") - end + # set @balance to value of @init_balance @balance = @init_balance end @@ -77,7 +97,7 @@ def add_owner(owner) class Owner def initialize(ownerdata) - @title = ownerdata[:title] + @title = ownerdata[:title] # all strings @first_name = ownerdata[:first_name] @middle_init = ownerdata[:middle_init] @last_name = ownerdata[:last_name] From 9c8b95815dfb18a8cfb3106c93d8a8f356102d3e Mon Sep 17 00:00:00 2001 From: justine Date: Wed, 2 Mar 2016 13:20:03 -0800 Subject: [PATCH 07/24] added .all class method to print all csv entries. --- bank_accounts.rb | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/bank_accounts.rb b/bank_accounts.rb index 85b9da0e..fb2ece9a 100644 --- a/bank_accounts.rb +++ b/bank_accounts.rb @@ -46,10 +46,8 @@ module Bank class Account # initialize method creates instance of Account class with @instance variables @id, @init_balance, and balance def initialize(accountdata) - @owner = accountdata[:owner] # string + # @owner = accountdata[:owner] # string @id = accountdata[:id] # fixnum? provided from csv? - @balance - @open_date @init_balance = accountdata[:init_balance].to_f #float if @init_balance < 0 raise ArgumentError.new("Account cannot be initialized with a negative balance.") @@ -93,6 +91,50 @@ def add_owner(owner) @owner = owner end + # be able to instantiate a new account from a csv. + def acct_from_csv(csv_index) + + require 'csv' + allaccountscsv = CSV.read("./support/accounts.csv", 'r') + + @id = allaccountscsv[csv_index][0] + @balance = allaccountscsv[csv_index][1] + @open_date = allaccountscsv[csv_index][2] + end + + # be able to instantiate a new account from each line in the csv. + # class method. + # similar to above. + def self.csv_to_accounts + require "CSV" + allaccountscsv = CSV.read("./support/accounts.csv", 'r') + + allaccountscsv.each do |entry| + Account.new(name: "name") + @id = entry[0] + @balance = entry[1] + @open_date = entry[2] + end + + end + + def self.all + require "awesome_print" + require "CSV" + allaccountscsv = CSV.read("./support/accounts.csv", 'r') + allaccounts = [] + allaccountscsv.each do |entry| + + @id = entry[0] + @balance = entry[1] + @open_date = entry[2] + allaccounts << entry + end + + ap allaccounts + end + + end class Owner From 0a153c4c618c627213fcf1d6d4792799e78c4182 Mon Sep 17 00:00:00 2001 From: justine Date: Wed, 2 Mar 2016 14:19:27 -0800 Subject: [PATCH 08/24] added .find class method to find a specific instance of account from the csv file. --- bank_accounts.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/bank_accounts.rb b/bank_accounts.rb index fb2ece9a..ff9bad3f 100644 --- a/bank_accounts.rb +++ b/bank_accounts.rb @@ -115,7 +115,6 @@ def self.csv_to_accounts @balance = entry[1] @open_date = entry[2] end - end def self.all @@ -134,6 +133,22 @@ def self.all ap allaccounts end + def self.find(id) + looking_for = [] + require "CSV" + + allaccountscsv = CSV.read("./support/accounts.csv", 'r') + allaccounts = [] + # find the entry in the csv where id matches the user-requested id + allaccountscsv.each do |entry| + if entry[0] == id + looking_for << entry + end + end + return looking_for + end + + end From 3d1c19d058867246cf2c54e7379eb49b6a26d9b9 Mon Sep 17 00:00:00 2001 From: justine Date: Wed, 2 Mar 2016 16:58:06 -0800 Subject: [PATCH 09/24] Created read_csv method: creates arrays from csvs. Also started working to associate owner data, owner_account data, and account data. WHEW. --- bank_accounts.rb | 153 +++++++++++++++++++++++++++++++---------------- 1 file changed, 100 insertions(+), 53 deletions(-) diff --git a/bank_accounts.rb b/bank_accounts.rb index ff9bad3f..94b8b2c3 100644 --- a/bank_accounts.rb +++ b/bank_accounts.rb @@ -41,8 +41,6 @@ module Bank - # require "money" - class Account # initialize method creates instance of Account class with @instance variables @id, @init_balance, and balance def initialize(accountdata) @@ -53,7 +51,6 @@ def initialize(accountdata) raise ArgumentError.new("Account cannot be initialized with a negative balance.") end @balance = accountdata[:balance].to_f # float - # set @balance to value of @init_balance @balance = @init_balance end @@ -91,80 +88,130 @@ def add_owner(owner) @owner = owner end - # be able to instantiate a new account from a csv. - def acct_from_csv(csv_index) - - require 'csv' - allaccountscsv = CSV.read("./support/accounts.csv", 'r') + # pulled tracing the pathway and putting the csv data into an array, into its own method. + def read_csv(file) + require 'csv' + allaccountscsv = CSV.read(file, 'r') + return read_csv + end + # be able to pull data from a specific line in the csv to an existing account. + def acct_from_csv(csv_index) + read_csv("./support/accounts.csv") @id = allaccountscsv[csv_index][0] @balance = allaccountscsv[csv_index][1] @open_date = allaccountscsv[csv_index][2] end + # be able to instantiate a new account from each line in the csv. # class method. # similar to above. + def self.read_csv(file) + require 'csv' + read_csv = CSV.read(file, 'r') + end + + def self.csv_to_accounts - require "CSV" - allaccountscsv = CSV.read("./support/accounts.csv", 'r') - - allaccountscsv.each do |entry| - Account.new(name: "name") - @id = entry[0] - @balance = entry[1] - @open_date = entry[2] + require "awesome_print" + + allaccounts = [] + read_csv("./support/accounts.csv").each do |entry| + # allaccountscsv.each do |entry| + account = self.new(id: entry[0], balance: entry[1], open_date: entry[2]) + allaccounts << account end + ap allaccounts end + def self.all - require "awesome_print" - require "CSV" - allaccountscsv = CSV.read("./support/accounts.csv", 'r') - allaccounts = [] - allaccountscsv.each do |entry| + require "awesome_print" + + allaccounts = [] + read_csv("./support/accounts.csv").each do |entry| + @id = entry[0] + @balance = entry[1] + @open_date = entry[2] + allaccounts << entry + end + ap allaccounts + end + + + def self.find(id) + id = id.to_s #lets the user enter id as a string/fixnum/float, and method still works. + # find the entry in the csv where id matches the user-requested id + read_csv.("./support/accounts.csv")each do |entry| + if entry[0] == id + return entry + end + end + end + end - @id = entry[0] - @balance = entry[1] - @open_date = entry[2] - allaccounts << entry - end - ap allaccounts + + class Owner + def initialize + @ownerID = ownerhash[:ownerID] + @last_name = ownerhash[:last_name] + @first_name = ownerhash[:first_name] + @street_address = ownerhash[:street_address] + @city = ownerhash[:city] + @state = ownerhash[:state] end - def self.find(id) - looking_for = [] + def self.read_csv(file) require "CSV" - - allaccountscsv = CSV.read("./support/accounts.csv", 'r') - allaccounts = [] - # find the entry in the csv where id matches the user-requested id - allaccountscsv.each do |entry| - if entry[0] == id - looking_for << entry - end - end - return looking_for + allownerscsv = CSV.read(file, 'r') end + def self.owner_csv + allowners = [] + read_csv("./support/owners.csv").each do |column| + ownerinfo = { + ownerID: column[0], + last_name: column[1], + first_name: column[2], + street_address: column[3], + city: column[4], + state: column[5]} + allowners << ownerinfo + end + end - end + # The data, in order in the CSV, consists of: + # + # ID - (Fixnum) a unique identifier for that Owner + # Last Name - (String) the owner's last name + # First Name - (String) the owner's first name + # Street Addess - (String) the owner's street address + # City - (String) the owner's city + # State - (String) the owner's state + # + # Add the instance method accounts to the Owner class. This method should return a collection of Account instances that belong to the specific owner. To create the relationship between the accounts and the owners use an account_owners.csv file. The data for this file, in order in the CSV, consists of: + # + # Account ID - (Fixnum) a unique identifier corresponding to an Account instance. + # Owner ID - (Fixnum) a unique identifier corresponding to an Owner instance. + + # Step 1... Associate account_owners.csv and owners.csv + # Step 2... Add method to return all accounts that belong to a specific owner. + + def self.link_csvs_by_id(ownerID) + assoc_accts = [] + find read_csv("./support/accounts.csv")[n][ownerID] + read_csv("./support/accounts.csv").each do |acct| + if acct[0] == read_csv("./support/accounts.csv")[n][ownerID] + assoc_accts << acct + end + end - class Owner - def initialize(ownerdata) - @title = ownerdata[:title] # all strings - @first_name = ownerdata[:first_name] - @middle_init = ownerdata[:middle_init] - @last_name = ownerdata[:last_name] - @street_address = ownerdata[:street_address] - @street_address2 = ownerdata[:street_address2] - @city = ownerdata[:city] - @state = ownerdata[:state] - @zip = ownerdata[:zip] - @cell = ownerdata[:cell] - @email = ownerdata[:email] + def owner_from_csv end + + end end From fd5493f3047cd01a19d15802ccba84aa09c01a0e Mon Sep 17 00:00:00 2001 From: justine Date: Thu, 3 Mar 2016 11:30:21 -0800 Subject: [PATCH 10/24] Scaffolding Wave 3 requirements. --- bank_accounts.rb | 63 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/bank_accounts.rb b/bank_accounts.rb index 94b8b2c3..0015b70c 100644 --- a/bank_accounts.rb +++ b/bank_accounts.rb @@ -152,6 +152,63 @@ def self.find(id) end + class SavingsAccount < Account + # The initial balance cannot be less than $10. If it is, this will raise an ArgumentError + @init_balance = accountdata[:init_balance].to_f #float + if @init_balance < 0 + raise ArgumentError.new("Account cannot be initialized with a negative balance.") + end + + # Updated withdrawal functionality: + # Each withdrawal 'transaction' incurs a fee of $2 that is taken out of the balance. + # Does not allow the account to go below the $10 minimum balance - Will output a warning message and return the original un-modified balance + # It should include the following new methods: + def withdraw(withdrawal) + if @balance - withdrawal >= 0 + @balance -= withdrawal + else puts "Withdrawal cannot be completed with available funds." + balance + end + end + + #add_interest(rate): Calculate the interest on the balance and add the interest to the balance. Return the interest that was calculated and added to the balance (not the updated balance). + # Input rate is assumed to be a percentage (i.e. 0.25). + # The formula for calculating interest is balance * rate/100 + # Example: If the interest rate is 0.25% and the balance is $10,000, then the interest that is returned is $25 and the new balance becomes $10,025. + def add_interest_rate + + end + + end + + + + class CheckingAccount < Account + # Updated withdrawal functionality: + # Each withdrawal 'transaction' incurs a fee of $1 that is taken out of the balance. Returns the updated account balance. + # Does not allow the account to go negative. Will output a warning message and return the original un-modified balance. + def withdraw(withdrawal) + if @balance - withdrawal >= 0 + @balance -= withdrawal + else puts "Withdrawal cannot be completed with available funds." + balance + end + end + + # #withdraw_using_check(amount): The input amount gets taken out of the account as a result of a check withdrawal. Returns the updated account balance. + # Allows the account to go into overdraft up to -$10 but not any lower + # The user is allowed three free check uses in one month, but any subsequent use adds a $2 transaction fee + def withdraw_using_check + + end + + #reset_checks: Resets the number of checks used to zero + def reset_checks + + end + end + + class Owner def initialize @@ -165,7 +222,7 @@ def initialize def self.read_csv(file) require "CSV" - allownerscsv = CSV.read(file, 'r') + read_csv = CSV.read(file, 'r') end def self.owner_csv @@ -201,8 +258,10 @@ def self.owner_csv # Step 2... Add method to return all accounts that belong to a specific owner. def self.link_csvs_by_id(ownerID) + + ownerinfo[:ownerID] == ownerID assoc_accts = [] - find read_csv("./support/accounts.csv")[n][ownerID] + owner = read_csv("./support/accounts.csv")[ownerID] read_csv("./support/accounts.csv").each do |acct| if acct[0] == read_csv("./support/accounts.csv")[n][ownerID] assoc_accts << acct From 2cbffa971d93b4fa4e76de7fe0b371d8cc11b186 Mon Sep 17 00:00:00 2001 From: justine Date: Thu, 3 Mar 2016 13:02:34 -0800 Subject: [PATCH 11/24] Updated withdrawal methods for Savings Accounts. --- bank_accounts.rb | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/bank_accounts.rb b/bank_accounts.rb index 0015b70c..b33c3807 100644 --- a/bank_accounts.rb +++ b/bank_accounts.rb @@ -154,20 +154,22 @@ def self.find(id) class SavingsAccount < Account # The initial balance cannot be less than $10. If it is, this will raise an ArgumentError - @init_balance = accountdata[:init_balance].to_f #float - if @init_balance < 0 - raise ArgumentError.new("Account cannot be initialized with a negative balance.") - end + if @init_balance < 10 + raise ArgumentError.new("Minimum balance to open a savings account is $10.") + end # Updated withdrawal functionality: # Each withdrawal 'transaction' incurs a fee of $2 that is taken out of the balance. # Does not allow the account to go below the $10 minimum balance - Will output a warning message and return the original un-modified balance # It should include the following new methods: + def withdrawal_fee + withdrawal_fee = 2 + end + def withdraw(withdrawal) - if @balance - withdrawal >= 0 - @balance -= withdrawal - else puts "Withdrawal cannot be completed with available funds." - balance + if @balance - (withdrawal + withdrawal_fee) >= 10 + @balance -= withdrawal - withdrawal_fee + else puts "Savings account balance must be above $10. Current balance $#{@balance}. Insufficient funds for this withdrawal." end end @@ -175,8 +177,19 @@ def withdraw(withdrawal) # Input rate is assumed to be a percentage (i.e. 0.25). # The formula for calculating interest is balance * rate/100 # Example: If the interest rate is 0.25% and the balance is $10,000, then the interest that is returned is $25 and the new balance becomes $10,025. - def add_interest_rate + # defining interest_rate in isolated, easily changed method. + def interest_rate + interest_rate = .25 + end + + # calculating interest on a specific balance. User can specify interest_rate or default to interest_rate method. + def calc_interest(interest_rate = nil) + @balance * (interest_rate / 100) + end + # adding calculated interest to balance. + def add_interest + @balance += calc_interest end end From 7fca95dc1b7c525c5219922fe6922df8f0d5f4c4 Mon Sep 17 00:00:00 2001 From: justine Date: Thu, 3 Mar 2016 13:22:09 -0800 Subject: [PATCH 12/24] Fixed a typo and removed required arg for calc_interest method. --- bank_accounts.rb | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/bank_accounts.rb b/bank_accounts.rb index b33c3807..0bdbe495 100644 --- a/bank_accounts.rb +++ b/bank_accounts.rb @@ -143,19 +143,22 @@ def self.all def self.find(id) id = id.to_s #lets the user enter id as a string/fixnum/float, and method still works. # find the entry in the csv where id matches the user-requested id - read_csv.("./support/accounts.csv")each do |entry| + read_csv("./support/accounts.csv").each do |entry| if entry[0] == id - return entry + return entry end end end + end class SavingsAccount < Account # The initial balance cannot be less than $10. If it is, this will raise an ArgumentError - if @init_balance < 10 - raise ArgumentError.new("Minimum balance to open a savings account is $10.") + def init_balance + if @init_balance < 10 + raise ArgumentError.new("Minimum balance to open a savings account is $10.") + end end # Updated withdrawal functionality: @@ -179,11 +182,11 @@ def withdraw(withdrawal) # Example: If the interest rate is 0.25% and the balance is $10,000, then the interest that is returned is $25 and the new balance becomes $10,025. # defining interest_rate in isolated, easily changed method. def interest_rate - interest_rate = .25 + interest_rate = (0.25) end - # calculating interest on a specific balance. User can specify interest_rate or default to interest_rate method. - def calc_interest(interest_rate = nil) + # calculating interest on a specific balance. + def calc_interest @balance * (interest_rate / 100) end @@ -270,19 +273,20 @@ def self.owner_csv # Step 1... Associate account_owners.csv and owners.csv # Step 2... Add method to return all accounts that belong to a specific owner. - def self.link_csvs_by_id(ownerID) - - ownerinfo[:ownerID] == ownerID - assoc_accts = [] - owner = read_csv("./support/accounts.csv")[ownerID] - read_csv("./support/accounts.csv").each do |acct| - if acct[0] == read_csv("./support/accounts.csv")[n][ownerID] - assoc_accts << acct - end - end - - def owner_from_csv - end + # def self.link_csvs_by_id(ownerID) + # + # ownerinfo[:ownerID] == ownerID + # assoc_accts = [] + # owner = read_csv("./support/accounts.csv")[ownerID] + # read_csv("./support/accounts.csv").each do |acct| + # if acct[0] == read_csv("./support/accounts.csv")[n][ownerID] + # assoc_accts << acct + # end + # end + # end + # + # def owner_from_csv + # end end From 1f67504da84e0efc661444f5fa9a3f9871b70147 Mon Sep 17 00:00:00 2001 From: justine Date: Thu, 3 Mar 2016 13:27:09 -0800 Subject: [PATCH 13/24] Added withdraw and withdrawal fee methods to calculate withdrawal fees in isolation. --- bank_accounts.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bank_accounts.rb b/bank_accounts.rb index 0bdbe495..c55e9f7c 100644 --- a/bank_accounts.rb +++ b/bank_accounts.rb @@ -185,7 +185,7 @@ def interest_rate interest_rate = (0.25) end - # calculating interest on a specific balance. + # calculating interest on a specific balance. def calc_interest @balance * (interest_rate / 100) end @@ -203,12 +203,12 @@ class CheckingAccount < Account # Updated withdrawal functionality: # Each withdrawal 'transaction' incurs a fee of $1 that is taken out of the balance. Returns the updated account balance. # Does not allow the account to go negative. Will output a warning message and return the original un-modified balance. + def withdrawal_fee + withdrawal_fee = 2 + end + def withdraw(withdrawal) - if @balance - withdrawal >= 0 - @balance -= withdrawal - else puts "Withdrawal cannot be completed with available funds." - balance - end + @balance -= withdrawal - withdrawal_fee end # #withdraw_using_check(amount): The input amount gets taken out of the account as a result of a check withdrawal. Returns the updated account balance. From e8efd492319598c96041a7b477a30b4349015ac9 Mon Sep 17 00:00:00 2001 From: justine Date: Thu, 3 Mar 2016 13:47:22 -0800 Subject: [PATCH 14/24] Fixed withdrawal method for Checking Account class. --- bank_accounts.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bank_accounts.rb b/bank_accounts.rb index c55e9f7c..b15f7b5b 100644 --- a/bank_accounts.rb +++ b/bank_accounts.rb @@ -207,9 +207,14 @@ def withdrawal_fee withdrawal_fee = 2 end - def withdraw(withdrawal) - @balance -= withdrawal - withdrawal_fee - end + def withdraw(withdrawal) + if @balance - withdrawal >= 0 + @balance -= (withdrawal + withdrawal_fee) + else puts "Withdrawal cannot be completed with available funds." + balance + end + end + # #withdraw_using_check(amount): The input amount gets taken out of the account as a result of a check withdrawal. Returns the updated account balance. # Allows the account to go into overdraft up to -$10 but not any lower From 551a47445c8c6afb8db2c330021c9556c589e0a4 Mon Sep 17 00:00:00 2001 From: justine Date: Thu, 3 Mar 2016 13:51:15 -0800 Subject: [PATCH 15/24] Added withdraw_with_check method to Checking Account class. --- bank_accounts.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bank_accounts.rb b/bank_accounts.rb index b15f7b5b..2ebcceff 100644 --- a/bank_accounts.rb +++ b/bank_accounts.rb @@ -219,8 +219,12 @@ def withdraw(withdrawal) # #withdraw_using_check(amount): The input amount gets taken out of the account as a result of a check withdrawal. Returns the updated account balance. # Allows the account to go into overdraft up to -$10 but not any lower # The user is allowed three free check uses in one month, but any subsequent use adds a $2 transaction fee - def withdraw_using_check - + def withdraw_using_check(withdrawal) + if @balance - withdrawal >= -10 + @balance -= withdrawal + withdrawal_fee + else puts "Checking account must maintain minimum balance of $-10. Withdrawal cannot be completed with available funds." + balance + end end #reset_checks: Resets the number of checks used to zero From 8e678477e2e407e41737ff374e5bee3824840750 Mon Sep 17 00:00:00 2001 From: justine Date: Thu, 3 Mar 2016 15:00:25 -0800 Subject: [PATCH 16/24] Finished Checking Account's withdraw_using_check method. Created methods to store the withdrawal fee and calculate the minimum checking balance that is okay for a withdrawal. --- bank_accounts.rb | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/bank_accounts.rb b/bank_accounts.rb index 2ebcceff..a63baa9e 100644 --- a/bank_accounts.rb +++ b/bank_accounts.rb @@ -200,6 +200,19 @@ def add_interest class CheckingAccount < Account + + def initialize(accountdata) + # @owner = accountdata[:owner] # string + @id = accountdata[:id] # fixnum? provided from csv? + @init_balance = accountdata[:init_balance].to_f #float + if @init_balance < 0 + raise ArgumentError.new("Account cannot be initialized with a negative balance.") + end + @balance = accountdata[:balance].to_f # float + # set @balance to value of @init_balance + @balance = @init_balance + @checktally = 0 + end # Updated withdrawal functionality: # Each withdrawal 'transaction' incurs a fee of $1 that is taken out of the balance. Returns the updated account balance. # Does not allow the account to go negative. Will output a warning message and return the original un-modified balance. @@ -219,17 +232,31 @@ def withdraw(withdrawal) # #withdraw_using_check(amount): The input amount gets taken out of the account as a result of a check withdrawal. Returns the updated account balance. # Allows the account to go into overdraft up to -$10 but not any lower # The user is allowed three free check uses in one month, but any subsequent use adds a $2 transaction fee + def check_withdrawal_fee + check_withdrawal_fee = 2 + end + + def checking_min_balance(withdrawal) + checking_min_balance = ((@balance - withdrawal) >= -10) + end + def withdraw_using_check(withdrawal) - if @balance - withdrawal >= -10 - @balance -= withdrawal + withdrawal_fee - else puts "Checking account must maintain minimum balance of $-10. Withdrawal cannot be completed with available funds." - balance + if @checktally >= 3 && checking_min_balance(withdrawal) + @balance -= (withdrawal + check_withdrawal_fee) + @checktally += 1 + return @balance + elsif @checktally < 3 && checking_min_balance(withdrawal) + @balance -= withdrawal + @checktally += 1 + return @balance + elsif (checking_min_balance(withdrawal) == false) + puts "Checking account must maintain minimum balance of $-10. Withdrawal cannot be completed with available funds." end end #reset_checks: Resets the number of checks used to zero def reset_checks - + @checktally = 0 end end From 4bb4a7884ecac0d31812ab420713692114a54446 Mon Sep 17 00:00:00 2001 From: justine Date: Thu, 3 Mar 2016 15:09:54 -0800 Subject: [PATCH 17/24] Refactored to use WITHDRAWAL FEE constant variable in Account class. --- bank_accounts.rb | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/bank_accounts.rb b/bank_accounts.rb index a63baa9e..0f98cf23 100644 --- a/bank_accounts.rb +++ b/bank_accounts.rb @@ -40,6 +40,7 @@ # OpenDate - (Datetime) when the account was opened module Bank +WITHDRAWAL_FEE = 2 class Account # initialize method creates instance of Account class with @instance variables @id, @init_balance, and balance @@ -165,13 +166,9 @@ def init_balance # Each withdrawal 'transaction' incurs a fee of $2 that is taken out of the balance. # Does not allow the account to go below the $10 minimum balance - Will output a warning message and return the original un-modified balance # It should include the following new methods: - def withdrawal_fee - withdrawal_fee = 2 - end - def withdraw(withdrawal) - if @balance - (withdrawal + withdrawal_fee) >= 10 - @balance -= withdrawal - withdrawal_fee + if (@balance - withdrawal - WITHDRAWAL_FEE)) >= 10 + @balance -= withdrawal - WITHDRAWAL_FEE else puts "Savings account balance must be above $10. Current balance $#{@balance}. Insufficient funds for this withdrawal." end end @@ -203,46 +200,31 @@ class CheckingAccount < Account def initialize(accountdata) # @owner = accountdata[:owner] # string - @id = accountdata[:id] # fixnum? provided from csv? - @init_balance = accountdata[:init_balance].to_f #float - if @init_balance < 0 - raise ArgumentError.new("Account cannot be initialized with a negative balance.") - end - @balance = accountdata[:balance].to_f # float - # set @balance to value of @init_balance - @balance = @init_balance + super @checktally = 0 end + # Updated withdrawal functionality: # Each withdrawal 'transaction' incurs a fee of $1 that is taken out of the balance. Returns the updated account balance. # Does not allow the account to go negative. Will output a warning message and return the original un-modified balance. - def withdrawal_fee - withdrawal_fee = 2 - end - def withdraw(withdrawal) if @balance - withdrawal >= 0 - @balance -= (withdrawal + withdrawal_fee) + @balance -= withdrawal - WITHDRAWAL_FEE else puts "Withdrawal cannot be completed with available funds." balance end end - # #withdraw_using_check(amount): The input amount gets taken out of the account as a result of a check withdrawal. Returns the updated account balance. # Allows the account to go into overdraft up to -$10 but not any lower # The user is allowed three free check uses in one month, but any subsequent use adds a $2 transaction fee - def check_withdrawal_fee - check_withdrawal_fee = 2 - end - def checking_min_balance(withdrawal) checking_min_balance = ((@balance - withdrawal) >= -10) end def withdraw_using_check(withdrawal) if @checktally >= 3 && checking_min_balance(withdrawal) - @balance -= (withdrawal + check_withdrawal_fee) + @balance -= (withdrawal + WITHDRAWAL_FEE) @checktally += 1 return @balance elsif @checktally < 3 && checking_min_balance(withdrawal) From 019ad0d176ed3211f79be66c9c64dd2c35ec7ca2 Mon Sep 17 00:00:00 2001 From: justine Date: Thu, 3 Mar 2016 16:22:48 -0800 Subject: [PATCH 18/24] Fixed Savings Account withdraw method. --- bank_accounts.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bank_accounts.rb b/bank_accounts.rb index 0f98cf23..a4f5a3d0 100644 --- a/bank_accounts.rb +++ b/bank_accounts.rb @@ -167,8 +167,8 @@ def init_balance # Does not allow the account to go below the $10 minimum balance - Will output a warning message and return the original un-modified balance # It should include the following new methods: def withdraw(withdrawal) - if (@balance - withdrawal - WITHDRAWAL_FEE)) >= 10 - @balance -= withdrawal - WITHDRAWAL_FEE + if (@balance - withdrawal - WITHDRAWAL_FEE) >= 10 + @balance -= (withdrawal + WITHDRAWAL_FEE) else puts "Savings account balance must be above $10. Current balance $#{@balance}. Insufficient funds for this withdrawal." end end @@ -197,7 +197,7 @@ def add_interest class CheckingAccount < Account - + CHECK_LIMIT = 3 def initialize(accountdata) # @owner = accountdata[:owner] # string super @@ -223,11 +223,11 @@ def checking_min_balance(withdrawal) end def withdraw_using_check(withdrawal) - if @checktally >= 3 && checking_min_balance(withdrawal) + if @checktally >= CHECK_LIMIT && checking_min_balance(withdrawal) @balance -= (withdrawal + WITHDRAWAL_FEE) @checktally += 1 return @balance - elsif @checktally < 3 && checking_min_balance(withdrawal) + elsif @checktally < CHECK_LIMIT && checking_min_balance(withdrawal) @balance -= withdrawal @checktally += 1 return @balance From bdf4c67bb1766d3c29c1a3c2f61f691bfb8fca17 Mon Sep 17 00:00:00 2001 From: justine Date: Fri, 4 Mar 2016 11:11:39 -0800 Subject: [PATCH 19/24] Added MIN_INIT_FEE to Accounts class and overrode in SavingsAccount class. --- bank_accounts.rb | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/bank_accounts.rb b/bank_accounts.rb index a4f5a3d0..44729628 100644 --- a/bank_accounts.rb +++ b/bank_accounts.rb @@ -40,16 +40,19 @@ # OpenDate - (Datetime) when the account was opened module Bank -WITHDRAWAL_FEE = 2 class Account + WITHDRAWAL_FEE = 2 + MIN_INIT_BALANCE = 0 + # initialize method creates instance of Account class with @instance variables @id, @init_balance, and balance + def initialize(accountdata) # @owner = accountdata[:owner] # string @id = accountdata[:id] # fixnum? provided from csv? @init_balance = accountdata[:init_balance].to_f #float - if @init_balance < 0 - raise ArgumentError.new("Account cannot be initialized with a negative balance.") + if @init_balance < self.class::MIN_INIT_BALANCE + raise ArgumentError.new("Account cannot be initialized with a balance less than #{self.class::MIN_INIT_BALANCE}.") end @balance = accountdata[:balance].to_f # float # set @balance to value of @init_balance @@ -156,11 +159,7 @@ def self.find(id) class SavingsAccount < Account # The initial balance cannot be less than $10. If it is, this will raise an ArgumentError - def init_balance - if @init_balance < 10 - raise ArgumentError.new("Minimum balance to open a savings account is $10.") - end - end + MIN_INIT_BALANCE = 10 # Updated withdrawal functionality: # Each withdrawal 'transaction' incurs a fee of $2 that is taken out of the balance. From a9949254fbfff271e8388ac5ce5b11e16a335d6a Mon Sep 17 00:00:00 2001 From: justine Date: Fri, 4 Mar 2016 11:24:19 -0800 Subject: [PATCH 20/24] Refactored to add check_tally method to CheckingAccount. --- bank_accounts.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bank_accounts.rb b/bank_accounts.rb index 44729628..aeffda0a 100644 --- a/bank_accounts.rb +++ b/bank_accounts.rb @@ -221,20 +221,26 @@ def checking_min_balance(withdrawal) checking_min_balance = ((@balance - withdrawal) >= -10) end + def check_tally + @checktally += 1 + end + def withdraw_using_check(withdrawal) if @checktally >= CHECK_LIMIT && checking_min_balance(withdrawal) @balance -= (withdrawal + WITHDRAWAL_FEE) - @checktally += 1 + check_tally return @balance elsif @checktally < CHECK_LIMIT && checking_min_balance(withdrawal) @balance -= withdrawal - @checktally += 1 + check_tally return @balance + puts elsif (checking_min_balance(withdrawal) == false) puts "Checking account must maintain minimum balance of $-10. Withdrawal cannot be completed with available funds." end end + #reset_checks: Resets the number of checks used to zero def reset_checks @checktally = 0 From edd2359c31d6c1dce760e9c2ce35064f690c6bf7 Mon Sep 17 00:00:00 2001 From: justine Date: Fri, 4 Mar 2016 14:36:40 -0800 Subject: [PATCH 21/24] Refactored Account withdrawl method and WITHDRAWAL_FEE constant. Removed Checking Account withdrawal method. --- bank_accounts.rb | 77 ++++++++++++++++++------------------------------ 1 file changed, 29 insertions(+), 48 deletions(-) diff --git a/bank_accounts.rb b/bank_accounts.rb index aeffda0a..74fd1b41 100644 --- a/bank_accounts.rb +++ b/bank_accounts.rb @@ -42,14 +42,15 @@ module Bank class Account - WITHDRAWAL_FEE = 2 + # Class has constants to simplify changing minimum initial balances and fees. + WITHDRAWAL_FEE = 0 MIN_INIT_BALANCE = 0 - # initialize method creates instance of Account class with @instance variables @id, @init_balance, and balance + attr_reader :balance def initialize(accountdata) - # @owner = accountdata[:owner] # string - @id = accountdata[:id] # fixnum? provided from csv? + @owner = accountdata[:owner] # string + @id = accountdata[:id] # fixnum @init_balance = accountdata[:init_balance].to_f #float if @init_balance < self.class::MIN_INIT_BALANCE raise ArgumentError.new("Account cannot be initialized with a balance less than #{self.class::MIN_INIT_BALANCE}.") @@ -59,47 +60,39 @@ def initialize(accountdata) @balance = @init_balance end - # def money_print - # Money.new(@balance, "USD").to_f - # end - - # withdraw method accepts a single parameter which represents the amount of the withdrawal. method should return the updated account balance. + # Withdraw method accepts a single parameter which represents the amount of the withdrawal. Method should return the updated account balance. def withdraw(withdrawal) - if @balance - withdrawal >= 0 - @balance -= withdrawal + if @balance - (withdrawal + self.class::WITHDRAWAL_FEE)>= 0 + @balance -= (withdrawal + self.class::WITHDRAWAL_FEE) else puts "Withdrawal cannot be completed with available funds." balance end end - # deposit method accepts a single parameter which represents the amount of the deposit. method should return the updated account balance. + # Deposit method accepts a single parameter which represents the amount of the deposit. Method should return the updated account balance. def deposit(deposit) @balance += deposit balance end - def balance - @balance - end - - # just checking to see if differentiating @init_balance and @balance worked. + # Test to see if differentiating @init_balance and @balance worked. # def initial_balance # return @init_balance # end - # add an owner (instance of Owner class, below) to an already existing account. + # Add an owner (instance of Owner class, below) to an already existing account. def add_owner(owner) @owner = owner end - # pulled tracing the pathway and putting the csv data into an array, into its own method. + # Pulled tracing the pathway and putting the csv data into an array, into its own method. def read_csv(file) require 'csv' allaccountscsv = CSV.read(file, 'r') return read_csv end - # be able to pull data from a specific line in the csv to an existing account. + # Be able to pull data from a specific line in the csv to an existing account. def acct_from_csv(csv_index) read_csv("./support/accounts.csv") @id = allaccountscsv[csv_index][0] @@ -107,7 +100,6 @@ def acct_from_csv(csv_index) @open_date = allaccountscsv[csv_index][2] end - # be able to instantiate a new account from each line in the csv. # class method. # similar to above. @@ -116,25 +108,22 @@ def self.read_csv(file) read_csv = CSV.read(file, 'r') end - +# Create array of hashes from csv. def self.csv_to_accounts require "awesome_print" - allaccounts = [] read_csv("./support/accounts.csv").each do |entry| - # allaccountscsv.each do |entry| account = self.new(id: entry[0], balance: entry[1], open_date: entry[2]) allaccounts << account end ap allaccounts end - - def self.all +#Create array of arrays from csv. + def self.csv_to_accounts_2 require "awesome_print" - allaccounts = [] - read_csv("./support/accounts.csv").each do |entry| + (read_csv("./support/accounts.csv")).each do |entry| @id = entry[0] @balance = entry[1] @open_date = entry[2] @@ -143,7 +132,6 @@ def self.all ap allaccounts end - def self.find(id) id = id.to_s #lets the user enter id as a string/fixnum/float, and method still works. # find the entry in the csv where id matches the user-requested id @@ -153,12 +141,13 @@ def self.find(id) end end end - end class SavingsAccount < Account # The initial balance cannot be less than $10. If it is, this will raise an ArgumentError + # Override constants from base class Account. + WITHDRAWAL_FEE = 2 MIN_INIT_BALANCE = 10 # Updated withdrawal functionality: @@ -176,44 +165,36 @@ def withdraw(withdrawal) # Input rate is assumed to be a percentage (i.e. 0.25). # The formula for calculating interest is balance * rate/100 # Example: If the interest rate is 0.25% and the balance is $10,000, then the interest that is returned is $25 and the new balance becomes $10,025. - # defining interest_rate in isolated, easily changed method. + # Defining interest_rate in isolated, easily changed method. def interest_rate interest_rate = (0.25) end - # calculating interest on a specific balance. + # Calculating interest on a specific balance. def calc_interest @balance * (interest_rate / 100) end - # adding calculated interest to balance. + # Adding calculated interest to balance. def add_interest @balance += calc_interest end - end - class CheckingAccount < Account + # Override constant from base class Account. + WITHDRAWAL_FEE = 1 + + # Set local constants. CHECK_LIMIT = 3 + CHECK_FEE = 2 + def initialize(accountdata) - # @owner = accountdata[:owner] # string super @checktally = 0 end - # Updated withdrawal functionality: - # Each withdrawal 'transaction' incurs a fee of $1 that is taken out of the balance. Returns the updated account balance. - # Does not allow the account to go negative. Will output a warning message and return the original un-modified balance. - def withdraw(withdrawal) - if @balance - withdrawal >= 0 - @balance -= withdrawal - WITHDRAWAL_FEE - else puts "Withdrawal cannot be completed with available funds." - balance - end - end - # #withdraw_using_check(amount): The input amount gets taken out of the account as a result of a check withdrawal. Returns the updated account balance. # Allows the account to go into overdraft up to -$10 but not any lower # The user is allowed three free check uses in one month, but any subsequent use adds a $2 transaction fee @@ -227,7 +208,7 @@ def check_tally def withdraw_using_check(withdrawal) if @checktally >= CHECK_LIMIT && checking_min_balance(withdrawal) - @balance -= (withdrawal + WITHDRAWAL_FEE) + @balance -= (withdrawal + CHECK_FEE) check_tally return @balance elsif @checktally < CHECK_LIMIT && checking_min_balance(withdrawal) From 6cfad90b997dfeb1a0f85905940b4a6185986de8 Mon Sep 17 00:00:00 2001 From: justine Date: Fri, 4 Mar 2016 14:44:40 -0800 Subject: [PATCH 22/24] Refactored Account withdrawl method further, added MIN_NEG_MSG error message and removed overridden withdrawal method from SavingsAccount class. --- bank_accounts.rb | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/bank_accounts.rb b/bank_accounts.rb index 74fd1b41..0ee710cc 100644 --- a/bank_accounts.rb +++ b/bank_accounts.rb @@ -45,6 +45,8 @@ class Account # Class has constants to simplify changing minimum initial balances and fees. WITHDRAWAL_FEE = 0 MIN_INIT_BALANCE = 0 + MIN_NEG_BALANCE = 0 + MIN_NEG_MSG = "Withdrawal cannot be completed with available funds." attr_reader :balance @@ -62,9 +64,9 @@ def initialize(accountdata) # Withdraw method accepts a single parameter which represents the amount of the withdrawal. Method should return the updated account balance. def withdraw(withdrawal) - if @balance - (withdrawal + self.class::WITHDRAWAL_FEE)>= 0 + if @balance - (withdrawal + self.class::WITHDRAWAL_FEE)>= self.class::MIN_NEG_BALANCE @balance -= (withdrawal + self.class::WITHDRAWAL_FEE) - else puts "Withdrawal cannot be completed with available funds." + else puts self.class::MIN_NEG_MSG balance end end @@ -149,17 +151,8 @@ class SavingsAccount < Account # Override constants from base class Account. WITHDRAWAL_FEE = 2 MIN_INIT_BALANCE = 10 - - # Updated withdrawal functionality: - # Each withdrawal 'transaction' incurs a fee of $2 that is taken out of the balance. - # Does not allow the account to go below the $10 minimum balance - Will output a warning message and return the original un-modified balance - # It should include the following new methods: - def withdraw(withdrawal) - if (@balance - withdrawal - WITHDRAWAL_FEE) >= 10 - @balance -= (withdrawal + WITHDRAWAL_FEE) - else puts "Savings account balance must be above $10. Current balance $#{@balance}. Insufficient funds for this withdrawal." - end - end + MIN_NEG_BALANCE = 10 + MIN_NEG_MSG = "Savings account balance remain above $#{MIN_NEG_BALANCE}. Current balance $#{@balance}. Insufficient funds for this withdrawal." #add_interest(rate): Calculate the interest on the balance and add the interest to the balance. Return the interest that was calculated and added to the balance (not the updated balance). # Input rate is assumed to be a percentage (i.e. 0.25). From f7f90b0313b614da712d60f5e98cd6eb2d3af03c Mon Sep 17 00:00:00 2001 From: justine Date: Fri, 4 Mar 2016 15:04:21 -0800 Subject: [PATCH 23/24] Cleaned up comments. Removed interpolated instance variable in constant MIN_NEG_MSG (line 154) - how to interpolate? --- bank_accounts.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bank_accounts.rb b/bank_accounts.rb index 0ee710cc..322d43e0 100644 --- a/bank_accounts.rb +++ b/bank_accounts.rb @@ -102,9 +102,7 @@ def acct_from_csv(csv_index) @open_date = allaccountscsv[csv_index][2] end - # be able to instantiate a new account from each line in the csv. - # class method. - # similar to above. + # Class method traces file pathway and puts csv data into array. def self.read_csv(file) require 'csv' read_csv = CSV.read(file, 'r') @@ -147,17 +145,19 @@ def self.find(id) class SavingsAccount < Account + attr_reader :balance # The initial balance cannot be less than $10. If it is, this will raise an ArgumentError # Override constants from base class Account. WITHDRAWAL_FEE = 2 MIN_INIT_BALANCE = 10 MIN_NEG_BALANCE = 10 - MIN_NEG_MSG = "Savings account balance remain above $#{MIN_NEG_BALANCE}. Current balance $#{@balance}. Insufficient funds for this withdrawal." + MIN_NEG_MSG = "Savings account balance remain above $#{MIN_NEG_BALANCE}. Insufficient funds for this withdrawal." #add_interest(rate): Calculate the interest on the balance and add the interest to the balance. Return the interest that was calculated and added to the balance (not the updated balance). # Input rate is assumed to be a percentage (i.e. 0.25). # The formula for calculating interest is balance * rate/100 # Example: If the interest rate is 0.25% and the balance is $10,000, then the interest that is returned is $25 and the new balance becomes $10,025. + # Defining interest_rate in isolated, easily changed method. def interest_rate interest_rate = (0.25) @@ -183,6 +183,7 @@ class CheckingAccount < Account CHECK_LIMIT = 3 CHECK_FEE = 2 + # Initialize from Account, add instance variable @checktally. def initialize(accountdata) super @checktally = 0 @@ -214,8 +215,7 @@ def withdraw_using_check(withdrawal) end end - - #reset_checks: Resets the number of checks used to zero + #Resets the number of checks used to zero. def reset_checks @checktally = 0 end @@ -253,8 +253,9 @@ def self.owner_csv end - # The data, in order in the CSV, consists of: + # Wave 2 Optionals. # + # The data, in order in the CSV, consists of: # ID - (Fixnum) a unique identifier for that Owner # Last Name - (String) the owner's last name # First Name - (String) the owner's first name From dd509090305d51d53f8e3b28fde183de6e55812e Mon Sep 17 00:00:00 2001 From: justine Date: Fri, 4 Mar 2016 16:27:30 -0800 Subject: [PATCH 24/24] Final push before pull request --- bank_accounts.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/bank_accounts.rb b/bank_accounts.rb index 322d43e0..b2b337d4 100644 --- a/bank_accounts.rb +++ b/bank_accounts.rb @@ -145,7 +145,6 @@ def self.find(id) class SavingsAccount < Account - attr_reader :balance # The initial balance cannot be less than $10. If it is, this will raise an ArgumentError # Override constants from base class Account. WITHDRAWAL_FEE = 2