From b79bdfe503a4328712f3ff1f93473a1f8a762833 Mon Sep 17 00:00:00 2001 From: Kari Bancroft Date: Thu, 8 Oct 2015 11:13:05 -0700 Subject: [PATCH 01/12] 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 d5d3abbc9c8b866765426d27e7cafeb5e0214cc1 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Thu, 8 Oct 2015 14:11:49 -0700 Subject: [PATCH 02/12] created file with all file names in the project so that the files can access info from the other files --- bankrequirefiles.rb | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 bankrequirefiles.rb diff --git a/bankrequirefiles.rb b/bankrequirefiles.rb new file mode 100644 index 00000000..00076f17 --- /dev/null +++ b/bankrequirefiles.rb @@ -0,0 +1,3 @@ +require "./bankaccounttest.rb" +require "./savingsaccountclass.rb" +# require "./checkingaccountclass.rb" From 40603aa296e18fb7107af16b131eb1fa5c3fb305 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Thu, 8 Oct 2015 14:12:52 -0700 Subject: [PATCH 03/12] Created savings account class and this version of the code can create a new instance of a savings account --- savingsaccountclass.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 savingsaccountclass.rb diff --git a/savingsaccountclass.rb b/savingsaccountclass.rb new file mode 100644 index 00000000..53bd966b --- /dev/null +++ b/savingsaccountclass.rb @@ -0,0 +1,14 @@ +require "./bankrequirefiles.rb" +module Bank + class SavingsAccount < Account + def initialize(balance) + @balance = balance + if @balance < 1000 + raise ArgumentError.new("An initial deposit of at least ten dollars (1000 cents) is required to open an account.") + end + end + + # def add_interest(rate) + # end + end +end From 0bc851a051cac961bb7d7be1c16fc5cfac4ebc32 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Thu, 8 Oct 2015 16:38:31 -0700 Subject: [PATCH 04/12] Checking account class with initialize and withdrawal working functions --- checkingaccountclass.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 checkingaccountclass.rb diff --git a/checkingaccountclass.rb b/checkingaccountclass.rb new file mode 100644 index 00000000..082f6905 --- /dev/null +++ b/checkingaccountclass.rb @@ -0,0 +1,23 @@ +require "./bankaccounttest.rb" + +module Bank + class CheckingAccount < Account + def initialize(balance) + @checks_written = 0 + @balance = balance + if @balance < 1000 + raise ArgumentError.new("An initial deposit of at least ten dollars (1000 cents) is required to open an account.") + end + end + + def withdrawal(amount) + if amount > @balance + puts "Cannot perform withdrawal because the account will become negative" + print @balance + end + end + + def withdrawal_using_check + + end +end From 4078fe5a07db979b6fa80505f9b4f925e3cf2cc1 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Thu, 8 Oct 2015 16:39:43 -0700 Subject: [PATCH 05/12] First update of BankAccount file for wave three --- bankaccounttest.rb | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/bankaccounttest.rb b/bankaccounttest.rb index 35e71bf9..99babef4 100644 --- a/bankaccounttest.rb +++ b/bankaccounttest.rb @@ -14,8 +14,9 @@ def initialize() @opendate = account_array[@@number_of_accounts][2] # @opendate = opendate # @account_id = account_id - @balance = @balance.to_i - # @amount = amount.to_i + @balance = balance.to_i + # @fee = fee + @amount = amount.to_i if @balance < 0 raise ArgumentError.new("Cannot create a new account with a negative balance") @@ -26,15 +27,15 @@ def initialize() @@number_of_accounts += 1 end #end statement for initialize method begining on line 10 - def withdraw - puts "Type the amount you would like to withdraw:" - @amount = gets.chomp.to_i - if @balance - @amount < 0 + def withdraw(amount) + # puts "Type the amount you would like to withdraw:" + # @amount = gets.chomp.to_i + if @balance - amount.to_i < 0 puts ("Cannot withdraw an amount that will make the balance negative.") puts "Your current balance is #{@balance}." else - @balance -= @amount - puts "Your new balance is: #{@balance} dollars." + @balance -= amount.to_i + # puts "Your new balance is: #{@balance} dollars." end#end statment for the if/else beginning on line 32 end#end for withdraw method beginning on line 29 From e0a6e4b845e0884acf9c8592ce514951aefedd99 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Thu, 8 Oct 2015 16:40:49 -0700 Subject: [PATCH 06/12] First commit of savings account class. --- savingsaccountclass.rb | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/savingsaccountclass.rb b/savingsaccountclass.rb index 53bd966b..422ace04 100644 --- a/savingsaccountclass.rb +++ b/savingsaccountclass.rb @@ -1,6 +1,8 @@ require "./bankrequirefiles.rb" +require "./bankaccounttest.rb" module Bank class SavingsAccount < Account + attr_accessor = :amount, :balance def initialize(balance) @balance = balance if @balance < 1000 @@ -8,7 +10,23 @@ def initialize(balance) end end - # def add_interest(rate) - # end + def savings_withdraw(withdraw) + withdrawal_amount = withdraw + 200 + if @balance - withdrawal_amount <= 1000 + puts "The account minimum balance is $10 (1000 cents). You cannot go below that minimum." + puts "Your current balance is #{@balance}" + else + @balance -= withdrawal_amount + end + end + + def add_interest(rate) + account_interest = @balance * rate/100 + @balance += account_interest + puts account_interest + print @balance + end + + end end From ad29aa86307b6fa5d9b4c1b54d7c95d0cd5417b8 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Thu, 8 Oct 2015 18:13:26 -0700 Subject: [PATCH 07/12] Refactored initialize, withdrawl, and deposit methods in BankAccount class. --- bankaccounttest.rb | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/bankaccounttest.rb b/bankaccounttest.rb index 99babef4..f9a511c4 100644 --- a/bankaccounttest.rb +++ b/bankaccounttest.rb @@ -7,13 +7,14 @@ class Account # :file @@number_of_accounts = 0 - def initialize() - account_array = CSV.read("./support/accounts.csv") - @id = account_array[@@number_of_accounts][0] - @balance = account_array[@@number_of_accounts][1] - @opendate = account_array[@@number_of_accounts][2] + def initialize(id, balance) + # account_array = CSV.read("./support/accounts.csv") + # @id = account_array[@@number_of_accounts][0] + # @balance = account_array[@@number_of_accounts][1] + # @opendate = account_array[@@number_of_accounts][2] # @opendate = opendate # @account_id = account_id + @id = id @balance = balance.to_i # @fee = fee @amount = amount.to_i @@ -24,7 +25,7 @@ def initialize() puts "You deposited #{@balance} dollars." puts "Your new balance is #{@balance} dollars." end - @@number_of_accounts += 1 + # @@number_of_accounts += 1 end #end statement for initialize method begining on line 10 def withdraw(amount) @@ -35,14 +36,14 @@ def withdraw(amount) puts "Your current balance is #{@balance}." else @balance -= amount.to_i - # puts "Your new balance is: #{@balance} dollars." + puts "Your new balance is: #{@balance} dollars." end#end statment for the if/else beginning on line 32 end#end for withdraw method beginning on line 29 - def deposit - puts "Type the amount you would like to deposit:" - @amount = gets.chomp.to_i - @balance += @amount + def deposit(amount) + # puts "Type the amount you would like to deposit:" + # @amount = gets.chomp.to_i + @balance += amount.to_i puts "Your new balance is #{@balance} dollars." end#end statement for deposit method beginning on line 41 From 01b14cd0b13b4e534f9553d592a3a5e5c90a665e Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Mon, 12 Oct 2015 21:01:19 -0700 Subject: [PATCH 08/12] File containing account class for bank account project --- bankaccounttest.rb | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/bankaccounttest.rb b/bankaccounttest.rb index f9a511c4..e95ec20a 100644 --- a/bankaccounttest.rb +++ b/bankaccounttest.rb @@ -1,8 +1,8 @@ require 'csv' - +# require "./bankrequirefiles.rb" module Bank class Account - attr_accessor :id, :balance, :amount + attr_accessor :id, :balance, :opendate, :amount # :file @@number_of_accounts = 0 @@ -12,10 +12,11 @@ def initialize(id, balance) # @id = account_array[@@number_of_accounts][0] # @balance = account_array[@@number_of_accounts][1] # @opendate = account_array[@@number_of_accounts][2] - # @opendate = opendate + # @account_id = account_id @id = id @balance = balance.to_i + @opendate = opendate # @fee = fee @amount = amount.to_i if @balance < 0 @@ -28,11 +29,11 @@ def initialize(id, balance) # @@number_of_accounts += 1 end #end statement for initialize method begining on line 10 - def withdraw(amount) + def withdrawal(amount) # puts "Type the amount you would like to withdraw:" # @amount = gets.chomp.to_i if @balance - amount.to_i < 0 - puts ("Cannot withdraw an amount that will make the balance negative.") + puts "Cannot withdraw an amount that will make the balance negative." puts "Your current balance is #{@balance}." else @balance -= amount.to_i @@ -52,15 +53,22 @@ def balance end #end for balance method begining on line 48 def self.all - @@number_of_accounts = 0 - all_accounts_array = [] - account_array = CSV.read("./support/accounts.csv") - while @@number_of_accounts < account_array.length do - account_name = "Account" + @@number_of_accounts.to_s - account_name = Account.new() - all_accounts_array.push(account_name) + account_array = [] + CSV.read("./support/accounts.csv").each do |account| + print account + p = Account.new(account[0], account[1], account[2]) + account_array.push(p) end - return all_accounts_array + # @@number_of_accounts = 0 + # all_accounts_array = [] + # account_array = CSV.read("./support/accounts.csv") + # while @@number_of_accounts < account_array.length do + # account = "Account" + @@number_of_accounts.to_s + # account_name = Account.new() + # all_accounts_array.push(account_name) + # @@number_of_accounts += 1 + # end + # return all_accounts_array end#end statement for self.all method beginning on line 52 def self.find(id) From 96d97d1fca59dd92ad748159579095b7982dff9f Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Mon, 12 Oct 2015 21:02:18 -0700 Subject: [PATCH 09/12] File with all of the files to run the bank account program --- bankrequirefiles.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bankrequirefiles.rb b/bankrequirefiles.rb index 00076f17..bd5a3fe4 100644 --- a/bankrequirefiles.rb +++ b/bankrequirefiles.rb @@ -1,3 +1,3 @@ require "./bankaccounttest.rb" require "./savingsaccountclass.rb" -# require "./checkingaccountclass.rb" +require "./checkingaccountclass.rb" From 35d275ac0af830979e2541e7d9d4f78163fa3c9c Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Mon, 12 Oct 2015 21:02:43 -0700 Subject: [PATCH 10/12] File with checking account class. --- checkingaccountclass.rb | 48 +++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/checkingaccountclass.rb b/checkingaccountclass.rb index 082f6905..2fbd0200 100644 --- a/checkingaccountclass.rb +++ b/checkingaccountclass.rb @@ -1,23 +1,43 @@ -require "./bankaccounttest.rb" - +# require "./bankaccounttest.rb" +# require "./bankrequirefiles.rb" module Bank class CheckingAccount < Account - def initialize(balance) + def initialize(id, balance) + super @checks_written = 0 - @balance = balance if @balance < 1000 raise ArgumentError.new("An initial deposit of at least ten dollars (1000 cents) is required to open an account.") - end - end + end#end of if balance in the initialize method + end#end of def initialize method def withdrawal(amount) - if amount > @balance - puts "Cannot perform withdrawal because the account will become negative" - print @balance - end - end + super + # if amount > @balance + # puts "Cannot perform withdrawal because the account will become negative" + # print @balance + # else + @balance -= (amount + 100) + puts "Your new balance is #{@balance}, which includes a $1 (100 cent) withdrawal fee." + # end of if amount > @balance block + end#end of withdrawal method - def withdrawal_using_check + def withdrawal_using_check(check_amount) + if check_amount > (@balance - 1000) + puts "Cannot perform transaction because the check amount is greater than the balance amount by ten dollars below zero." + else + if @checks_written < 3 + @balance -= (check_amount) + puts "Your new balance is #{@balance}." + @checks_written += 1 + else + @balance -= (check_amount + 200) + puts "Your new balance is #{@balance}, which includes a $2 (200 cent) check withdrawal fee." + end#end if if @checks_written block + end#end of if @check_amount block + end#edn of def withdrawal_using_check method - end -end + def reset_checks + @checks_written = 0 + end#end for reset checks method + end#end for class +end#end for module From 4fb440f56fa81da8cd16d3d92febf8346a0e7ca8 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Mon, 12 Oct 2015 21:03:06 -0700 Subject: [PATCH 11/12] File with savings account class. --- savingsaccountclass.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/savingsaccountclass.rb b/savingsaccountclass.rb index 422ace04..df644b61 100644 --- a/savingsaccountclass.rb +++ b/savingsaccountclass.rb @@ -1,10 +1,11 @@ -require "./bankrequirefiles.rb" -require "./bankaccounttest.rb" +# require "./bankaccounttest.rb"# require "./bankaccounttest.rb" +# require "./bankaccounttest.rb" module Bank class SavingsAccount < Account - attr_accessor = :amount, :balance - def initialize(balance) - @balance = balance + # attr_accessor = :amount, :balance + def initialize(id, balance) + super + # @balance = balance if @balance < 1000 raise ArgumentError.new("An initial deposit of at least ten dollars (1000 cents) is required to open an account.") end @@ -14,7 +15,7 @@ def savings_withdraw(withdraw) withdrawal_amount = withdraw + 200 if @balance - withdrawal_amount <= 1000 puts "The account minimum balance is $10 (1000 cents). You cannot go below that minimum." - puts "Your current balance is #{@balance}" + return @balance else @balance -= withdrawal_amount end @@ -24,7 +25,7 @@ def add_interest(rate) account_interest = @balance * rate/100 @balance += account_interest puts account_interest - print @balance + # print @balance end From 1bdf5dd44396650024687e7b58d4b4237ac44516 Mon Sep 17 00:00:00 2001 From: Amy Hunter Date: Tue, 27 Oct 2015 17:18:30 -0700 Subject: [PATCH 12/12] Added code that I forgot to commit and push before submitting my pull request. --- .DS_Store | Bin 0 -> 6148 bytes bankaccounttest.rb | 2 +- experimentbankaccount.rb | 54 +++++++++++++++++++++++++++++++++++++++ tryoutbankaccount.rb | 5 ++++ 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 .DS_Store create mode 100644 experimentbankaccount.rb create mode 100644 tryoutbankaccount.rb diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0= 0 +# beginning_account_amount = @default_deposit_amount.to_i + @integer_user_deposit +# puts "You deposited #{@integer_user_deposit} dollars." +# puts "Your new balance is #{beginning_account_amount} dollars." +# else +# raise ArgumentError, "Please enter an amount that is greater than zero." +# @user_deposit = gets.chomp +# end diff --git a/tryoutbankaccount.rb b/tryoutbankaccount.rb new file mode 100644 index 00000000..5b249498 --- /dev/null +++ b/tryoutbankaccount.rb @@ -0,0 +1,5 @@ +require 'csv' +# def show_all_accounts +s = CSV.read("./support/accounts.csv") +print s +# print s[-1]