From 53a462b244c34c2f857f9fc46526026e65784ad1 Mon Sep 17 00:00:00 2001 From: LaurenSky Date: Tue, 23 Aug 2016 10:57:01 -0700 Subject: [PATCH 1/9] account_wave 1 tasks completed --- account.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 account.rb diff --git a/account.rb b/account.rb new file mode 100644 index 00000000..a2cef6f7 --- /dev/null +++ b/account.rb @@ -0,0 +1,33 @@ +require_relative 'owner' + +module Bank + class Account + attr_reader :balance + + def initialize (init_balance) + @id = rand(100..999) + + if init_balance > 0 + @balance = init_balance + else + raise ArgumentError, "You can't start an account with a negative balance" + end + end + + def withdraw (amt_withdrawn) + if @balance - amt_withdrawn > 0 + @balance = @balance - amt_withdrawn + return @balance + else + puts "Sorry, but you do not have that amount of money in your account." + return @balance + end + end + + def deposit (amt_deposited) + @balance = @balance + amt_deposited + return @balance + end + + end +end From c694a1c39cbf51ad0781afca576b68f74e07fd5c Mon Sep 17 00:00:00 2001 From: LaurenSky Date: Tue, 23 Aug 2016 15:21:03 -0700 Subject: [PATCH 2/9] wave1 optional completed & added owner.rb --- account.rb | 1 + owner.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 owner.rb diff --git a/account.rb b/account.rb index a2cef6f7..c86a09f9 100644 --- a/account.rb +++ b/account.rb @@ -12,6 +12,7 @@ def initialize (init_balance) else raise ArgumentError, "You can't start an account with a negative balance" end + @owner = Bank::Owner.new(@id) end def withdraw (amt_withdrawn) diff --git a/owner.rb b/owner.rb new file mode 100644 index 00000000..2b3c54ab --- /dev/null +++ b/owner.rb @@ -0,0 +1,18 @@ +module Bank + class Owner + + def initialize (id) + @id = id + puts "Enter first name:" + @first_name = gets.chomp + puts "Enter last name:" + @last_name = gets.chomp + puts "Enter street address" + @address = gets.chomp + puts "Enter city" + @city = gets.chomp + puts "Enter state" + @state = gets.chomp + end + end +end From 82c982405eb3fc1ffeb2f092c7decbe663cc8b70 Mon Sep 17 00:00:00 2001 From: LaurenSky Date: Wed, 24 Aug 2016 15:55:13 -0700 Subject: [PATCH 3/9] Accnt Wave2 basic reqs completed --- account.rb | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/account.rb b/account.rb index c86a09f9..03b7a1d2 100644 --- a/account.rb +++ b/account.rb @@ -1,33 +1,52 @@ -require_relative 'owner' +#require_relative 'owner' +require 'csv' module Bank class Account attr_reader :balance - def initialize (init_balance) - @id = rand(100..999) + def initialize (id, balance, open_date = Time.now) + @id = id - if init_balance > 0 - @balance = init_balance + if balance > 0 + @balance = balance else - raise ArgumentError, "You can't start an account with a negative balance" + raise ArgumentError, "You can't start an account with a negative balance" end - @owner = Bank::Owner.new(@id) + + @date_opened = open_date + #@owner = Bank::Owner.new(@id) + end + + # self.all - returns a collection of Account instances, representing all of the Accounts described in the CSV. See below for the CSV file specifications + def self.all + accounts = {} + # /Documents/Ada/Week3/BankAccounts/support/accounts.csv + CSV.read('support/accounts.csv').each do |line| + accounts[line[0]] = self.new(line[0], line[1].to_i, line[2]) + end + return accounts + end + + # self.find(id) - returns an instance of Account where the value of the id field in the CSV matches the passed parameter + def self.find (id) + accounts = self.all + return accounts[id] end def withdraw (amt_withdrawn) if @balance - amt_withdrawn > 0 @balance = @balance - amt_withdrawn - return @balance + return "$#{@balance/100}" else puts "Sorry, but you do not have that amount of money in your account." - return @balance + return "$#{@balance/100}" end end def deposit (amt_deposited) @balance = @balance + amt_deposited - return @balance + return "$#{@balance/100}" end end From 0a528dad561c99ea01462c9bcc2f54598a5079cf Mon Sep 17 00:00:00 2001 From: LaurenSky Date: Wed, 24 Aug 2016 16:20:31 -0700 Subject: [PATCH 4/9] wave2 optional: added owner csvto owner.rb --- account.rb | 9 +++++++-- owner.rb | 50 +++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/account.rb b/account.rb index 03b7a1d2..00a5003d 100644 --- a/account.rb +++ b/account.rb @@ -22,8 +22,8 @@ def initialize (id, balance, open_date = Time.now) def self.all accounts = {} # /Documents/Ada/Week3/BankAccounts/support/accounts.csv - CSV.read('support/accounts.csv').each do |line| - accounts[line[0]] = self.new(line[0], line[1].to_i, line[2]) + CSV.read('support/owners.csv').each do |line| + accounts[line[0].to_i] = self.new(line[0].to_i, line[1].to_i, line[2]) end return accounts end @@ -51,3 +51,8 @@ def deposit (amt_deposited) end end + + +# 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 diff --git a/owner.rb b/owner.rb index 2b3c54ab..b405592f 100644 --- a/owner.rb +++ b/owner.rb @@ -1,18 +1,46 @@ +require 'csv' + module Bank class Owner - def initialize (id) + def initialize (id, last_name, first_name, street_address, city, state) @id = id - puts "Enter first name:" - @first_name = gets.chomp - puts "Enter last name:" - @last_name = gets.chomp - puts "Enter street address" - @address = gets.chomp - puts "Enter city" - @city = gets.chomp - puts "Enter state" - @state = gets.chomp + # puts "Enter last name:" + @last_name = last_name + # puts "Enter first name:" + @first_name = first_name + # puts "Enter street address" + @street_address = street_address + # puts "Enter city" + @city = city + # puts "Enter state" + @state = state + end + + # self.all - returns a collection of Owner instances, representing all of the Owners described in the CSV. See below for the CSV file specifications + def self.all + owners = {} + # /Documents/Ada/Week3/BankAccounts/support/accounts.csv + CSV.read('support/owners.csv').each do |line| + owners[line[0].to_i] = self.new(line[0].to_i, line[1], line[2], line[3], line[4], line[5]) + end + return owners + end + + # self.find(id) - returns an instance of Owner where the value of the id field in the CSV matches the passed parameter + def self.find (id) + owners = self.all + return owners[id] end end end + + + # Bank::Owner + # 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 From e799aa7f99c4098c6f762621564258c44128bcbe Mon Sep 17 00:00:00 2001 From: LaurenSky Date: Thu, 25 Aug 2016 14:06:35 -0700 Subject: [PATCH 5/9] account files add for wave optionals --- account.rb | 26 ++++++++-- account_w1_optionals.rb | 36 +++++++++++++ account_w2_opt_merge_not_finished.rb | 76 ++++++++++++++++++++++++++++ owner.rb | 1 - 4 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 account_w1_optionals.rb create mode 100644 account_w2_opt_merge_not_finished.rb diff --git a/account.rb b/account.rb index 00a5003d..ddd15d73 100644 --- a/account.rb +++ b/account.rb @@ -1,4 +1,4 @@ -#require_relative 'owner' +require_relative 'owner' require 'csv' module Bank @@ -8,21 +8,39 @@ class Account def initialize (id, balance, open_date = Time.now) @id = id - if balance > 0 + if balance >= 0 @balance = balance else raise ArgumentError, "You can't start an account with a negative balance" end @date_opened = open_date - #@owner = Bank::Owner.new(@id) + + # @owner = Bank::Owner.find(@id) + end + +# need to figure out how to merge the one array into the another array + def self.all_with_owners + acct_list_w_owners = [] + CSV.read('support/account_owners.csv').each do |line| + a = Bank::Account.find(line[0].to_i) + o = Bank::Owner.find(line[1].to_i) + puts " " + puts o + # a.add_owner(0) + # acct_list_w_owners << a + end + end + + def add_owner + end # self.all - returns a collection of Account instances, representing all of the Accounts described in the CSV. See below for the CSV file specifications def self.all accounts = {} # /Documents/Ada/Week3/BankAccounts/support/accounts.csv - CSV.read('support/owners.csv').each do |line| + CSV.read('support/accounts.csv').each do |line| accounts[line[0].to_i] = self.new(line[0].to_i, line[1].to_i, line[2]) end return accounts diff --git a/account_w1_optionals.rb b/account_w1_optionals.rb new file mode 100644 index 00000000..f54ad1a6 --- /dev/null +++ b/account_w1_optionals.rb @@ -0,0 +1,36 @@ +require_relative 'owner' + +module Bank + class Account + attr_reader :balance + + def initialize (init_balance) + @id = rand(100..999) + + if init_balance > 0 + @balance = init_balance + else + raise ArgumentError, "You can't start an account with a negative balance" + end + @owner = Bank::Owner.new(@id) + end + + def withdraw (amt_withdrawn) + if @balance - amt_withdrawn > 0 + @balance = @balance - amt_withdrawn + return "$#{@balance}" + else + puts "Sorry, but you do not have that amount of money in your account." + return "$#{@balance}" + end + end + + def deposit (amt_deposited) + @balance = @balance + amt_deposited + return "$#{@balance}" + end + + end +end + +p = Bank::Account.new(500) diff --git a/account_w2_opt_merge_not_finished.rb b/account_w2_opt_merge_not_finished.rb new file mode 100644 index 00000000..ddd15d73 --- /dev/null +++ b/account_w2_opt_merge_not_finished.rb @@ -0,0 +1,76 @@ +require_relative 'owner' +require 'csv' + +module Bank + class Account + attr_reader :balance + + def initialize (id, balance, open_date = Time.now) + @id = id + + if balance >= 0 + @balance = balance + else + raise ArgumentError, "You can't start an account with a negative balance" + end + + @date_opened = open_date + + # @owner = Bank::Owner.find(@id) + end + +# need to figure out how to merge the one array into the another array + def self.all_with_owners + acct_list_w_owners = [] + CSV.read('support/account_owners.csv').each do |line| + a = Bank::Account.find(line[0].to_i) + o = Bank::Owner.find(line[1].to_i) + puts " " + puts o + # a.add_owner(0) + # acct_list_w_owners << a + end + end + + def add_owner + + end + + # self.all - returns a collection of Account instances, representing all of the Accounts described in the CSV. See below for the CSV file specifications + def self.all + accounts = {} + # /Documents/Ada/Week3/BankAccounts/support/accounts.csv + CSV.read('support/accounts.csv').each do |line| + accounts[line[0].to_i] = self.new(line[0].to_i, line[1].to_i, line[2]) + end + return accounts + end + + # self.find(id) - returns an instance of Account where the value of the id field in the CSV matches the passed parameter + def self.find (id) + accounts = self.all + return accounts[id] + end + + def withdraw (amt_withdrawn) + if @balance - amt_withdrawn > 0 + @balance = @balance - amt_withdrawn + return "$#{@balance/100}" + else + puts "Sorry, but you do not have that amount of money in your account." + return "$#{@balance/100}" + end + end + + def deposit (amt_deposited) + @balance = @balance + amt_deposited + return "$#{@balance/100}" + end + + end +end + + +# 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 diff --git a/owner.rb b/owner.rb index b405592f..a2a5c08d 100644 --- a/owner.rb +++ b/owner.rb @@ -20,7 +20,6 @@ def initialize (id, last_name, first_name, street_address, city, state) # self.all - returns a collection of Owner instances, representing all of the Owners described in the CSV. See below for the CSV file specifications def self.all owners = {} - # /Documents/Ada/Week3/BankAccounts/support/accounts.csv CSV.read('support/owners.csv').each do |line| owners[line[0].to_i] = self.new(line[0].to_i, line[1], line[2], line[3], line[4], line[5]) end From 6155c5bfd8222fec35be4b947c11e50da01a49ac Mon Sep 17 00:00:00 2001 From: LaurenSky Date: Thu, 25 Aug 2016 16:02:51 -0700 Subject: [PATCH 6/9] added checking account class and functions --- account.rb | 35 ++++------------------- checking_acct.rb | 74 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 29 deletions(-) create mode 100644 checking_acct.rb diff --git a/account.rb b/account.rb index ddd15d73..b1864c8a 100644 --- a/account.rb +++ b/account.rb @@ -9,31 +9,13 @@ def initialize (id, balance, open_date = Time.now) @id = id if balance >= 0 - @balance = balance + @balance = balance/100 else raise ArgumentError, "You can't start an account with a negative balance" end @date_opened = open_date - - # @owner = Bank::Owner.find(@id) - end - -# need to figure out how to merge the one array into the another array - def self.all_with_owners - acct_list_w_owners = [] - CSV.read('support/account_owners.csv').each do |line| - a = Bank::Account.find(line[0].to_i) - o = Bank::Owner.find(line[1].to_i) - puts " " - puts o - # a.add_owner(0) - # acct_list_w_owners << a - end - end - - def add_owner - + #@owner = Bank::Owner.new(@id) end # self.all - returns a collection of Account instances, representing all of the Accounts described in the CSV. See below for the CSV file specifications @@ -41,7 +23,7 @@ def self.all accounts = {} # /Documents/Ada/Week3/BankAccounts/support/accounts.csv CSV.read('support/accounts.csv').each do |line| - accounts[line[0].to_i] = self.new(line[0].to_i, line[1].to_i, line[2]) + accounts[line[0]] = self.new(line[0], line[1].to_i, line[2]) end return accounts end @@ -55,22 +37,17 @@ def self.find (id) def withdraw (amt_withdrawn) if @balance - amt_withdrawn > 0 @balance = @balance - amt_withdrawn - return "$#{@balance/100}" + return "$#{@balance}" else puts "Sorry, but you do not have that amount of money in your account." - return "$#{@balance/100}" + return "$#{@balance}" end end def deposit (amt_deposited) @balance = @balance + amt_deposited - return "$#{@balance/100}" + return "$#{@balance}" end end end - - -# 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 diff --git a/checking_acct.rb b/checking_acct.rb new file mode 100644 index 00000000..f349c753 --- /dev/null +++ b/checking_acct.rb @@ -0,0 +1,74 @@ +require_relative 'account.rb' + +module Bank + class CheckingAccount < Account + attr_reader :num_of_checks_used, :balance, :id + + def initialize (id, balance, open_date = Time.now ) + super(id, balance, open_date) + # @date_opened = open_date + @num_of_checks_used = 0 + end + + def withdraw (amount) + # Does not allow the account to go negative. Will output a warning message and return the original un-modified balance. + @withdrawal_fee = 1 #$1 checking account withdrawal fee taken out of the balance. Returns the updated account balance. + if (@balance - amount - @withdrawal_fee) >= 0 + @balance = @balance - amount - @withdrawal_fee + return "$#{@balance}" + else + puts "Sorry, but you do not have that amount of money in your account." + return "$#{@balance}" + end + end + + def charge_fee_for_check? + @num_of_checks_used >= 3 + end + + #reset_checks: Resets the number of checks used to zero + def reset_checks + @num_of_checks_used = 0 + 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. + def withdraw_using_check (amount) + @check_withdrawel_fee = 2 #$2 transaction fee + if charge_fee_for_check? + if (@balance - amount - @check_withdrawel_fee) >= -10 + @num_of_checks_used += 1 + return @balance = @balance - amount - @check_withdrawel_fee + else + puts "Sorry, but you do not have that amount of money in your account." + return "$#{@balance}" + end + + else + + if (@balance - amount) >= -10 + @num_of_checks_used += 1 + return @balance = @balance - amount + else + puts "Sorry, but you do not have that amount of money in your account." + return "$#{@balance}" + end + end + end + + end +end + +# p = Bank::CheckingAccount.new(1234, 60000) +# puts p.withdraw_using_check(100) +# puts p.num_of_checks_used +# puts p.withdraw_using_check(100) +# puts p.num_of_checks_used +# puts p.withdraw_using_check(100) +# puts p.num_of_checks_used + + + +# puts p + # Allows the account to go into overdraft up to -$10 but not any lower + # The user is allowed 3 free check uses in one month, but any subsequent use adds a $2 transaction fee + # 3 free check uses, then a fee until we call the reset_checks method to reset. Do not use time in this. From 80caff6cb1bcca2ef0a90c5cb040c6c5af199288 Mon Sep 17 00:00:00 2001 From: LaurenSky Date: Thu, 25 Aug 2016 16:43:44 -0700 Subject: [PATCH 7/9] added variables for min_balance and used super --- account.rb | 14 +++++++++----- checking_acct.rb | 32 ++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/account.rb b/account.rb index b1864c8a..abbba26d 100644 --- a/account.rb +++ b/account.rb @@ -7,8 +7,8 @@ class Account def initialize (id, balance, open_date = Time.now) @id = id - - if balance >= 0 + @min_balance = 0 + if balance >= @min_balance @balance = balance/100 else raise ArgumentError, "You can't start an account with a negative balance" @@ -16,6 +16,7 @@ def initialize (id, balance, open_date = Time.now) @date_opened = open_date #@owner = Bank::Owner.new(@id) + @withdrawal_fee = 0 end # self.all - returns a collection of Account instances, representing all of the Accounts described in the CSV. See below for the CSV file specifications @@ -34,9 +35,9 @@ def self.find (id) return accounts[id] end - def withdraw (amt_withdrawn) - if @balance - amt_withdrawn > 0 - @balance = @balance - amt_withdrawn + def withdraw (amount) + if (@balance - amount - @withdrawal_fee) >= @min_balance + @balance = @balance - amount - @withdrawal_fee return "$#{@balance}" else puts "Sorry, but you do not have that amount of money in your account." @@ -44,6 +45,9 @@ def withdraw (amt_withdrawn) end end + # Does not allow the account to go negative. Will output a warning message and return the original un-modified balance. + #$1 checking account withdrawal fee taken out of the balance. Returns the updated account balance. + def deposit (amt_deposited) @balance = @balance + amt_deposited return "$#{@balance}" diff --git a/checking_acct.rb b/checking_acct.rb index f349c753..a7161cbb 100644 --- a/checking_acct.rb +++ b/checking_acct.rb @@ -6,20 +6,22 @@ class CheckingAccount < Account def initialize (id, balance, open_date = Time.now ) super(id, balance, open_date) - # @date_opened = open_date @num_of_checks_used = 0 + @withdrawal_fee = 1 + @min_balance_check = -10 end def withdraw (amount) - # Does not allow the account to go negative. Will output a warning message and return the original un-modified balance. - @withdrawal_fee = 1 #$1 checking account withdrawal fee taken out of the balance. Returns the updated account balance. - if (@balance - amount - @withdrawal_fee) >= 0 - @balance = @balance - amount - @withdrawal_fee - return "$#{@balance}" - else - puts "Sorry, but you do not have that amount of money in your account." - return "$#{@balance}" - end + super (amount) + # # Does not allow the account to go negative. Will output a warning message and return the original un-modified balance. + # #$1 checking account withdrawal fee taken out of the balance. Returns the updated account balance. + # if (@balance - amount - @withdrawal_fee) >= 0 + # @balance = @balance - amount - @withdrawal_fee + # return "$#{@balance}" + # else + # puts "Sorry, but you do not have that amount of money in your account." + # return "$#{@balance}" + # end end def charge_fee_for_check? @@ -35,9 +37,10 @@ def reset_checks def withdraw_using_check (amount) @check_withdrawel_fee = 2 #$2 transaction fee if charge_fee_for_check? - if (@balance - amount - @check_withdrawel_fee) >= -10 + if (@balance - amount - @check_withdrawel_fee) >= @min_balance_check @num_of_checks_used += 1 - return @balance = @balance - amount - @check_withdrawel_fee + @balance = @balance - amount - @check_withdrawel_fee + return "$#{@balance}" else puts "Sorry, but you do not have that amount of money in your account." return "$#{@balance}" @@ -45,9 +48,10 @@ def withdraw_using_check (amount) else - if (@balance - amount) >= -10 + if (@balance - amount) >= @min_balance_check @num_of_checks_used += 1 - return @balance = @balance - amount + @balance = @balance - amount + return "$#{@balance}" else puts "Sorry, but you do not have that amount of money in your account." return "$#{@balance}" From 06826dc8dcc55c0ba72244d81f47e6dcc837d19d Mon Sep 17 00:00:00 2001 From: LaurenSky Date: Thu, 25 Aug 2016 17:05:22 -0700 Subject: [PATCH 8/9] Wave3 basic reqs completed --- account.rb | 10 +++++----- checking_acct.rb | 24 ++++-------------------- savings_acct.rb | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 25 deletions(-) create mode 100644 savings_acct.rb diff --git a/account.rb b/account.rb index abbba26d..2b334078 100644 --- a/account.rb +++ b/account.rb @@ -11,7 +11,7 @@ def initialize (id, balance, open_date = Time.now) if balance >= @min_balance @balance = balance/100 else - raise ArgumentError, "You can't start an account with a negative balance" + raise ArgumentError, "You can't start an account with a negative balance." end @date_opened = open_date @@ -38,10 +38,10 @@ def self.find (id) def withdraw (amount) if (@balance - amount - @withdrawal_fee) >= @min_balance @balance = @balance - amount - @withdrawal_fee - return "$#{@balance}" + return "$#{ @balance }" else - puts "Sorry, but you do not have that amount of money in your account." - return "$#{@balance}" + puts "Sorry. You're transaction cannot be completed because it will take you below the required minimum amount of $#{ @min_balance }." + return "$#{ @balance }" end end @@ -50,7 +50,7 @@ def withdraw (amount) def deposit (amt_deposited) @balance = @balance + amt_deposited - return "$#{@balance}" + return "$#{ @balance }" end end diff --git a/checking_acct.rb b/checking_acct.rb index a7161cbb..1f6467e9 100644 --- a/checking_acct.rb +++ b/checking_acct.rb @@ -40,10 +40,10 @@ def withdraw_using_check (amount) if (@balance - amount - @check_withdrawel_fee) >= @min_balance_check @num_of_checks_used += 1 @balance = @balance - amount - @check_withdrawel_fee - return "$#{@balance}" + return "$#{ @balance }" else puts "Sorry, but you do not have that amount of money in your account." - return "$#{@balance}" + return "$#{ @balance }" end else @@ -51,28 +51,12 @@ def withdraw_using_check (amount) if (@balance - amount) >= @min_balance_check @num_of_checks_used += 1 @balance = @balance - amount - return "$#{@balance}" + return "$#{ @balance }" else puts "Sorry, but you do not have that amount of money in your account." - return "$#{@balance}" + return "$#{ @balance }" end end end - end end - -# p = Bank::CheckingAccount.new(1234, 60000) -# puts p.withdraw_using_check(100) -# puts p.num_of_checks_used -# puts p.withdraw_using_check(100) -# puts p.num_of_checks_used -# puts p.withdraw_using_check(100) -# puts p.num_of_checks_used - - - -# puts p - # Allows the account to go into overdraft up to -$10 but not any lower - # The user is allowed 3 free check uses in one month, but any subsequent use adds a $2 transaction fee - # 3 free check uses, then a fee until we call the reset_checks method to reset. Do not use time in this. diff --git a/savings_acct.rb b/savings_acct.rb new file mode 100644 index 00000000..cc371c2b --- /dev/null +++ b/savings_acct.rb @@ -0,0 +1,37 @@ +require_relative 'account.rb' + +module Bank + class SavingsAccount < Account + attr_reader :balance, :id + + def initialize (id, balance, open_date = Time.now) + super(id, balance, open_date) + # The initial balance cannot be less than $10. If it is, this will raise an ArgumentError + @min_balance = 10 + if @balance < @min_balance + raise ArgumentError, "You need at least #{ @min_balance } to open a savings account." + else + @balance = balance/100 + end + + @withdrawal_fee = 2 #$2 withdrawal fee for saving acct + + end + + def withdraw (amount) + super(amount) + end + + def add_interest(rate) + #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 + interest_rate = rate / 100 + interest_on_balance = @balance * interest_rate + @balance = @balance + interest_on_balance + return "$" + interest_on_balance.to_s + # 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. + end + + end +end From 7892e75eb460113262d4223e8a7aea02d276ff3f Mon Sep 17 00:00:00 2001 From: LaurenSky Date: Fri, 26 Aug 2016 11:26:22 -0700 Subject: [PATCH 9/9] Wave3 reqs & optionals completed and if statment on account.rb line 11 fixed --- account.rb | 6 +-- money_market_acct.rb | 89 ++++++++++++++++++++++++++++++++++++++++++++ savings_acct.rb | 6 +-- 3 files changed, 95 insertions(+), 6 deletions(-) create mode 100644 money_market_acct.rb diff --git a/account.rb b/account.rb index 2b334078..8ba15a44 100644 --- a/account.rb +++ b/account.rb @@ -8,7 +8,7 @@ class Account def initialize (id, balance, open_date = Time.now) @id = id @min_balance = 0 - if balance >= @min_balance + if (balance/100) >= @min_balance @balance = balance/100 else raise ArgumentError, "You can't start an account with a negative balance." @@ -48,8 +48,8 @@ def withdraw (amount) # Does not allow the account to go negative. Will output a warning message and return the original un-modified balance. #$1 checking account withdrawal fee taken out of the balance. Returns the updated account balance. - def deposit (amt_deposited) - @balance = @balance + amt_deposited + def deposit (amount) + @balance = @balance + amount return "$#{ @balance }" end diff --git a/money_market_acct.rb b/money_market_acct.rb new file mode 100644 index 00000000..3daacd05 --- /dev/null +++ b/money_market_acct.rb @@ -0,0 +1,89 @@ +require_relative 'account.rb' + +module Bank + class MoneyMarketAccount < Account + attr_reader :id, :balance + + def initialize (id, balance, open_date = Time.now) + super(id, balance, open_date) + + @min_balance = 10000 + puts @min_balance + if (balance/100) >= @min_balance + @balance = balance/100 + else + raise ArgumentError, "You need at least $#{ @min_balance } to open a money market account." + end + + @below_min_balance_fee = 100 + @num_of_transactions = 0 + @max_num_transactions = 6 + end + + def reset_transactions + @num_of_transactions = 0 + end + + def transaction_limit_reached? + @num_of_transactions >= @max_num_transactions + end + + def charge_fee_for_overdraft? (amount) + (@balance - amount) < @min_balance + end + + def account_below_min_balance? + @balance < @min_balance + end + + def withdraw (amount) + if transaction_limit_reached? + puts "Sorry you have reached your maximum number of transactions/month of #{ @max_num_transactions }" + return "$#{ @balance }" + else + + if account_below_min_balance? + return "Sorry, you can only deposit money at this point until your acount balance reaches the minimum acount balance of $#{ @min_balance }." + else + + if charge_fee_for_overdraft?(amount) + @balance = @balance - amount - @below_min_balance_fee + @num_of_transactions += 1 + return "$#{ @balance }" + else + @balance = @balance - amount + @num_of_transactions += 1 + return "$#{ @balance }" + end + end + end + end + + def deposit (amount) + if account_below_min_balance? + if (@balance + amount) >= @min_balance + super(amount) + else + return "Sorry, you're account is frozen until you deposit enough money to reach the required min account balance of $#{ @min_balance }." + end + else + if transaction_limit_reached? + puts "Sorry you have reached your maximum number of transactions/month of #{ @max_num_transactions }" + return "$#{ @balance }" + else + @num_of_transactions += 1 + super(amount) + end + end + end + + def add_interest(rate) + interest_rate = rate / 100 + interest_on_balance = @balance * interest_rate + @balance = @balance + interest_on_balance + return "$" + interest_on_balance.to_s + # 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. + end + + end +end diff --git a/savings_acct.rb b/savings_acct.rb index cc371c2b..6884da4c 100644 --- a/savings_acct.rb +++ b/savings_acct.rb @@ -8,10 +8,10 @@ def initialize (id, balance, open_date = Time.now) super(id, balance, open_date) # The initial balance cannot be less than $10. If it is, this will raise an ArgumentError @min_balance = 10 - if @balance < @min_balance - raise ArgumentError, "You need at least #{ @min_balance } to open a savings account." - else + if (balance/100) >= @min_balance @balance = balance/100 + else + raise ArgumentError, "You need at least $#{ @min_balance } to open a savings account." end @withdrawal_fee = 2 #$2 withdrawal fee for saving acct