From 47157cdbc9bcdefe21551014589c397c33252af3 Mon Sep 17 00:00:00 2001 From: Suzannah Kirk-Daligcon Date: Tue, 23 Aug 2016 11:59:25 -0700 Subject: [PATCH 1/4] primary requirements complete --- account.rb | 46 ++++++++++++++++++++++++++++++++++++++++++++++ program.rb | 11 +++++++++++ 2 files changed, 57 insertions(+) create mode 100644 account.rb create mode 100644 program.rb diff --git a/account.rb b/account.rb new file mode 100644 index 00000000..439b5ca7 --- /dev/null +++ b/account.rb @@ -0,0 +1,46 @@ +module Bank + class Account + attr_reader + + def initialize(initial_balance) + @initial_balance = initial_balance + @ID = rand(100000..999999) + @current_balance = @initial_balance + + unless @initial_balance >= 5 + raise ArgumentError.new("All account balances must begin and maintain a minimum of $5.") + end + end + + def withdraw(withdrawal_amount) + unless withdrawal_amount.is_a?(Numeric) + raise ArgumentError.new("You can only withdraw numerical values. Please log-in again.") + end + + if @current_balance - withdrawal_amount >= 5 + @current_balance = @current_balance - withdrawal_amount + puts "You successfully withdrew $#{ withdrawal_amount }. Your updated account balance is $#{ @current_balance }." + return @current_balance + else + puts "Your current account balance is $#{ @current_balance }. You cannot withdraw $#{ withdrawal_amount } because your account must maintain a minimum of $5. Please login again to try a different withdrawal request." + return @current_balance + end + end + + def deposit(deposit_amount) + unless deposit_amount.is_a?(Numeric) + raise ArgumentError.new("You can only deposit numerical values. Please log-in again.") + end + + @current_balance = @current_balance + deposit_amount + + puts "You successfully deposited $#{ deposit_amount }. Your updated account balance is $#{ @current_balance }." + return @current_balance + end + + def balance + puts "Your current balance is $#{ @current_balance}." + return @current_balance + end + end +end diff --git a/program.rb b/program.rb new file mode 100644 index 00000000..91dc02f0 --- /dev/null +++ b/program.rb @@ -0,0 +1,11 @@ +require_relative 'account' + +test = Bank::Account.new(100) + +test.balance + +test.deposit(50) + +test.withdraw(50) + +test.withdraw(96) From 9ce99a53dfce941a7d452d3b5361b8e45ae99882 Mon Sep 17 00:00:00 2001 From: Suzannah Kirk-Daligcon Date: Wed, 24 Aug 2016 16:03:40 -0700 Subject: [PATCH 2/4] wave 2 primary requirements done --- account.rb | 61 +++++++++++++++++++++++++++++++++++++++++++++--------- program.rb | 4 +++- 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/account.rb b/account.rb index 439b5ca7..c48a9881 100644 --- a/account.rb +++ b/account.rb @@ -1,17 +1,39 @@ +require 'csv' + module Bank class Account - attr_reader + attr_reader :id, :balance, :open_date - def initialize(initial_balance) - @initial_balance = initial_balance - @ID = rand(100000..999999) - @current_balance = @initial_balance + def initialize(account_hash) + @id = account_hash[:id] + @balance = account_hash[:balance] + @open_date = account_hash[:open_date] - unless @initial_balance >= 5 + unless @balance >= 5 raise ArgumentError.new("All account balances must begin and maintain a minimum of $5.") end end + def self.all + csv_accounts = [] + CSV.read('./support/accounts.csv').each do |line| + csv_account = {} + csv_account[:id] = line[0].to_i + csv_account[:balance] = line[1].to_i + csv_account[:open_date] = line[2].to_i + csv_accounts << self.new(csv_account) + end + csv_accounts + end + + def self.find(id) + self.all.each do |object| + if object.id == id + return object + end + end + end + def withdraw(withdrawal_amount) unless withdrawal_amount.is_a?(Numeric) raise ArgumentError.new("You can only withdraw numerical values. Please log-in again.") @@ -38,9 +60,28 @@ def deposit(deposit_amount) return @current_balance end - def balance - puts "Your current balance is $#{ @current_balance}." - return @current_balance - end + # def balance + # puts "Your current balance is $#{ @current_balance}." + # return @current_balance + # end end end + + + +# WAVE TWO TESTING... +test = Bank::Account.all + +puts test + +puts "Woo hoo!" + +test.each do |item| + puts item.balance +end + +puts "Does this work?" +works = Bank::Account.find(1216) +puts works.balance + +puts "Yay!" diff --git a/program.rb b/program.rb index 91dc02f0..e09b296a 100644 --- a/program.rb +++ b/program.rb @@ -1,8 +1,10 @@ +# WAVE ONE TESTING... + require_relative 'account' test = Bank::Account.new(100) -test.balance +puts test.current_balance test.deposit(50) From 7a776f842605fa3bc8b81e8b46c04b8b77db8aba Mon Sep 17 00:00:00 2001 From: Suzannah Kirk-Daligcon Date: Fri, 26 Aug 2016 11:20:32 -0700 Subject: [PATCH 3/4] Savings_Account has all the primary requirments completed --- account.rb | 87 +++++++++++++++++++++++++++++----------------- savings_account.rb | 61 ++++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 31 deletions(-) create mode 100644 savings_account.rb diff --git a/account.rb b/account.rb index c48a9881..6726c25c 100644 --- a/account.rb +++ b/account.rb @@ -2,6 +2,9 @@ module Bank class Account + MINIMUM_BALANCE = 0 + TRANSACTION_FEE = 0 + attr_reader :id, :balance, :open_date def initialize(account_hash) @@ -9,8 +12,8 @@ def initialize(account_hash) @balance = account_hash[:balance] @open_date = account_hash[:open_date] - unless @balance >= 5 - raise ArgumentError.new("All account balances must begin and maintain a minimum of $5.") + unless @balance >= self.class::MINIMUM_BALANCE + raise ArgumentError.new("Account balances cannot be less than #{ self.class::MINIMUM_BALANCE } cents.") end end @@ -39,13 +42,20 @@ def withdraw(withdrawal_amount) raise ArgumentError.new("You can only withdraw numerical values. Please log-in again.") end - if @current_balance - withdrawal_amount >= 5 - @current_balance = @current_balance - withdrawal_amount - puts "You successfully withdrew $#{ withdrawal_amount }. Your updated account balance is $#{ @current_balance }." - return @current_balance + total_withdrawn = withdrawal_amount + self.class::TRANSACTION_FEE + + transaction_fee_incurred = "Please note: you were charged a #{ self.class::TRANSACTION_FEE } cent transaction fee on this transaction." + + if @balance - total_withdrawn >= self.class::MINIMUM_BALANCE + @balance = @balance - total_withdrawn + puts "You successfully withdrew #{ withdrawal_amount } cents. Your updated account balance is #{ @balance } cents." + if self.class::TRANSACTION_FEE != 0 + puts transaction_fee_incurred + end + return @balance else - puts "Your current account balance is $#{ @current_balance }. You cannot withdraw $#{ withdrawal_amount } because your account must maintain a minimum of $5. Please login again to try a different withdrawal request." - return @current_balance + puts "Your current account balance is #{ @balance } cents. You cannot withdraw #{ total_withdrawn } cents (this includes any transaction fees, if applicable) because your account must maintain a minimum of #{ self.class::MINIMUM_BALANCE } cents. Please login again to try a different withdrawal request." + return @balance end end @@ -54,34 +64,49 @@ def deposit(deposit_amount) raise ArgumentError.new("You can only deposit numerical values. Please log-in again.") end - @current_balance = @current_balance + deposit_amount + @balance = @balance + deposit_amount - puts "You successfully deposited $#{ deposit_amount }. Your updated account balance is $#{ @current_balance }." - return @current_balance + puts "You successfully deposited #{ deposit_amount } cents. Your updated account balance is #{ @balance } cents." + return @balance end # def balance - # puts "Your current balance is $#{ @current_balance}." - # return @current_balance + # puts "Your current balance is $#{ @balance}." + # return @balance # end end end - - -# WAVE TWO TESTING... -test = Bank::Account.all - -puts test - -puts "Woo hoo!" - -test.each do |item| - puts item.balance -end - -puts "Does this work?" -works = Bank::Account.find(1216) -puts works.balance - -puts "Yay!" +# # WAVE THREE TESTING... +# +# puts "Does this work?" +# works = Bank::Account.find(1216) +# puts works.balance +# +# puts "Yay!" +# +# works.deposit(50) +# +# works.withdraw(50) +# +# works.withdraw(1000002) +# +# puts "End of Thursday's testing..." +# +# +# # WAVE TWO TESTING... +# test = Bank::Account.all +# +# puts test +# +# puts "Woo hoo!" +# +# test.each do |item| +# puts item.balance +# end +# +# puts "Does this work?" +# works = Bank::Account.find(1216) +# puts works.balance +# +# puts "Yay!" diff --git a/savings_account.rb b/savings_account.rb new file mode 100644 index 00000000..5d93ad6c --- /dev/null +++ b/savings_account.rb @@ -0,0 +1,61 @@ +require_relative 'account' + +module Bank + class SavingsAccount < Account + MINIMUM_BALANCE = 1000 + TRANSACTION_FEE = 200 + + def initialize(account_hash) + super(account_hash) + end + + def withdraw(withdrawal_amount) + super(withdrawal_amount) + end + + def add_interest(rate) + interest = (rate/100) * @balance + @balance = @balance + interest + return interest + end + + end +end + + +# WAVE THREE TESTING... + +puts "Initiating a savings account with manual information:" +test = Bank::SavingsAccount.new({:id => 5268, :balance => 2000, :open_date => 1965}) +print "Here's the account balance (in cents): " +puts test.balance + +puts "\n\nWithdrawing 600 cents..." +puts test.withdraw(600) + +puts "Successfully withdrew $6 so my account is now $12--simply confirming that this aligns with the cents below..." +puts test.balance + +puts "\n\nI'd love this savings account! Adding 25% interest..." +print "Here's the interest amount: " +puts test.add_interest(0.25) +print "Here's the updated account balance: " +puts test.balance + +puts "\n\nI ought to receive an error when trying to withdraw $2 more..." +puts test.withdraw(200) + + +puts "\n\nThursday's testing... Does this work?" +works = Bank::SavingsAccount.find(1216) +puts works.balance + +puts "Yay!" + +works.deposit(50) + +works.withdraw(50) + +works.withdraw(1000002) + +puts "End of Thursday's testing...\n" From 44fcc620412aee92871c7145ccb28916afe46bac Mon Sep 17 00:00:00 2001 From: Suzannah Kirk-Daligcon Date: Fri, 26 Aug 2016 15:36:26 -0700 Subject: [PATCH 4/4] awesome. all primary requirements complete for waves 1, 2, and 3 --- account.rb | 18 ++++++-- checking_account.rb | 103 ++++++++++++++++++++++++++++++++++++++++++++ program.rb | 3 +- 3 files changed, 119 insertions(+), 5 deletions(-) create mode 100644 checking_account.rb diff --git a/account.rb b/account.rb index 6726c25c..e12f6fc7 100644 --- a/account.rb +++ b/account.rb @@ -11,6 +11,7 @@ def initialize(account_hash) @id = account_hash[:id] @balance = account_hash[:balance] @open_date = account_hash[:open_date] + @total_withdrawn = nil unless @balance >= self.class::MINIMUM_BALANCE raise ArgumentError.new("Account balances cannot be less than #{ self.class::MINIMUM_BALANCE } cents.") @@ -38,27 +39,36 @@ def self.find(id) end def withdraw(withdrawal_amount) + #COME BACK HERE, can I save this as a method and then call this method here and in the checking withdraw method? unless withdrawal_amount.is_a?(Numeric) raise ArgumentError.new("You can only withdraw numerical values. Please log-in again.") end - total_withdrawn = withdrawal_amount + self.class::TRANSACTION_FEE + @total_withdrawn = withdrawal_amount + self.class::TRANSACTION_FEE transaction_fee_incurred = "Please note: you were charged a #{ self.class::TRANSACTION_FEE } cent transaction fee on this transaction." - if @balance - total_withdrawn >= self.class::MINIMUM_BALANCE - @balance = @balance - total_withdrawn + if valid_withdrawal? + @balance = @balance - @total_withdrawn puts "You successfully withdrew #{ withdrawal_amount } cents. Your updated account balance is #{ @balance } cents." if self.class::TRANSACTION_FEE != 0 puts transaction_fee_incurred end return @balance else - puts "Your current account balance is #{ @balance } cents. You cannot withdraw #{ total_withdrawn } cents (this includes any transaction fees, if applicable) because your account must maintain a minimum of #{ self.class::MINIMUM_BALANCE } cents. Please login again to try a different withdrawal request." + puts "Your current account balance is #{ @balance } cents. You cannot withdraw #{ @total_withdrawn } cents (this includes any transaction fees, if applicable) because your account must maintain a minimum of #{ self.class::MINIMUM_BALANCE } cents. Please login again to try a different withdrawal request." return @balance end end + def valid_withdrawal? + @balance - @total_withdrawn >= self.class::MINIMUM_BALANCE + end + + def valid_opening_amount? + @balance < self.class::MINIMUM_BALANCE + end + def deposit(deposit_amount) unless deposit_amount.is_a?(Numeric) raise ArgumentError.new("You can only deposit numerical values. Please log-in again.") diff --git a/checking_account.rb b/checking_account.rb new file mode 100644 index 00000000..d3a2eeee --- /dev/null +++ b/checking_account.rb @@ -0,0 +1,103 @@ +require_relative 'account' + +module Bank + class CheckingAccount < Account + # MINIMUM_BALANCE = 1000 + TRANSACTION_FEE = 100 + + attr_reader :check_number + + def initialize(account_hash) + super(account_hash) + @check_account_overdraw_maximum = -1000 + @check_number = 0 + @free_checks = 3 + @check_transaction_fee = 0 + end + + def withdraw(withdrawal_amount) + super(withdrawal_amount) + end + + def withdraw_using_check(amount) + unless amount.is_a?(Numeric) + raise ArgumentError.new("You can only withdraw numerical values. Please log-in again.") + end + + @total_withdrawn = amount + @check_transaction_fee + + if @check_number < @free_checks + if valid_check_withdrawal? + @balance = @balance - @total_withdrawn + @check_number += 1 + puts "You successfully withdrew #{ amount } cents. Your updated account balance is #{ @balance } cents." + return @balance + else + puts "Your current account balance is #{ @balance } cents. You cannot withdraw #{ @total_withdrawn } cents because your account cannot exceed your #{ @check_account_overdraw_maximum.abs } cent overdraft limit. Please login again to try a different withdrawal request." + return @balance + end + else + @check_transaction_fee = 200 + if valid_check_withdrawal? + @balance = @balance - @total_withdrawn + @check_number += 1 + puts "You successfully withdrew #{ amount } cents. NOTE: You are allowed #{ @free_checks } free check withdrawals per month. You incurred a #{ @check_transaction_fee } cent check transaction fee today because you have written #{ @check_number } checks this month. Your updated account balance is #{ @balance } cents." + return @balance + else + puts "Your current account balance is #{ @balance } cents. You cannot withdraw #{ @total_withdrawn } cents (includes your check transaction fee) because your account cannot exceed your #{ @check_account_overdraw_maximum.abs } cent overdraft limit. Please login again to try a different withdrawal request." + return @balance + end + end + end + + def valid_check_withdrawal? + @balance - @total_withdrawn >= @check_account_overdraw_maximum + end + + def reset_checks + @check_number = 0 + end + end +end + + +# WAVE THREE TESTING... + +puts "Initiating a checking account with manual information:" +test = Bank::CheckingAccount.new({:id => 5268, :balance => 2000, :open_date => 1965}) +print "Here's the account balance (in cents): " +puts test.balance + +puts "\n\nWithdrawing 600 cents..." +puts test.withdraw(600) + +puts "Successfully withdrew $6 so my account is now $13--simply confirming that this aligns with the cents below..." +puts test.balance + +puts "\n\nI ought to receive an error when trying to withdraw $14 more..." +puts test.withdraw(1400) + +# NOW TESTING MY CHECK WITHDRAWAL METHOD... + +puts "\n\n\nHere's my 'first' check..." +puts test.withdraw_using_check(100) +print "Here's the check number: " +puts test.check_number + +puts "\nHere's my 'second' check..." +puts test.withdraw_using_check(100) +print "Here's the check number: " +puts test.check_number + +puts "\nHere's my 'third' check..." +puts test.withdraw_using_check(100) +print "Here's the check number: " +puts test.check_number + +puts "\nHere's my 'fourth' check, incurring a fee?" +puts test.withdraw_using_check(50) +print "Here's the check number: " +puts test.check_number + +puts "\nThis ought to error..." +puts test.withdraw_using_check(1960) diff --git a/program.rb b/program.rb index e09b296a..ff6dd84c 100644 --- a/program.rb +++ b/program.rb @@ -1,10 +1,11 @@ # WAVE ONE TESTING... +## THIS NO LONGER WORKS since Wave 2 was implemented... require_relative 'account' test = Bank::Account.new(100) -puts test.current_balance +puts test.balance test.deposit(50)