From b79bdfe503a4328712f3ff1f93473a1f8a762833 Mon Sep 17 00:00:00 2001 From: Kari Bancroft Date: Thu, 8 Oct 2015 11:13:05 -0700 Subject: [PATCH 1/8] 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 c9e1d9ef5fb3b9c9d9313344a3b085b5fd4bfb77 Mon Sep 17 00:00:00 2001 From: Riley Spicer Date: Thu, 8 Oct 2015 13:41:58 -0700 Subject: [PATCH 2/8] Creating new files for Wave 3 classes --- checking_account.rb | 25 +++++++++++++++++++++++++ savings_account.rb | 21 +++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 checking_account.rb create mode 100644 savings_account.rb diff --git a/checking_account.rb b/checking_account.rb new file mode 100644 index 00000000..f5e5d8bd --- /dev/null +++ b/checking_account.rb @@ -0,0 +1,25 @@ + + class CheckingAccount < Account + + def initialize + + end + + def withdraw + + end + + # 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 + #reset_checks: Resets the number of checks used to zero + + def withdraw_using_check(amount) + + end + + def reset_checks + #reset checks + end + + end diff --git a/savings_account.rb b/savings_account.rb new file mode 100644 index 00000000..95e28799 --- /dev/null +++ b/savings_account.rb @@ -0,0 +1,21 @@ +class SavingsAccount < Account + + #The initial balance cannot be less than $10. If it is, this will raise an ArgumentError + #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 + + def initialize(id, initial_balance, open_date) + super + + end + + # 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 From 01dbe364b1d0bb8736886f4e6eb5b8cdad2a921d Mon Sep 17 00:00:00 2001 From: Riley Spicer Date: Thu, 8 Oct 2015 14:28:54 -0700 Subject: [PATCH 3/8] Changed withdraw method to use variables so it works in all Account cases, and added savings interest rate. --- bank.rb | 9 ++++++--- savings_account.rb | 28 +++++++++++++++------------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/bank.rb b/bank.rb index e27fe891..c171b809 100644 --- a/bank.rb +++ b/bank.rb @@ -10,7 +10,10 @@ def initialize (id, initial_balance, open_date) @account_id = id raise ArgumentError.new("You can't start an account with a negative balance.") if initial_balance <= 0 @balance = initial_balance # in cents + open_date = open_date.to_s @open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %z") + @min_balance = 0 + @withdrawal_fee = 0 end # Return an array of all Account instances in account.csv @@ -44,10 +47,10 @@ def withdraw(amount) new_balance = @balance - amount if amount < 0 puts "You can't withdraw a negative amount." - elsif new_balance < 0 - puts "You don't have that much money. You can withdraw up to #{@balance} dollars." + elsif new_balance < @min_balance + puts "You don't have that much money. You can withdraw up to #{@balance - @min_balance - @withdrawal_fee} dollars." else - @balance = new_balance + @balance = new_balance - @withdrawal_fee return @balance end end diff --git a/savings_account.rb b/savings_account.rb index 95e28799..0a759a07 100644 --- a/savings_account.rb +++ b/savings_account.rb @@ -1,20 +1,22 @@ -class SavingsAccount < Account +require "./bank.rb" - #The initial balance cannot be less than $10. If it is, this will raise an ArgumentError - #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 +module Bank - def initialize(id, initial_balance, open_date) - super + class SavingsAccount < Account + attr_reader :balance, :owner, :account_id, :owner_id - end + def initialize(id, initial_balance, open_date) + super + raise ArgumentError.new("You must have at least $10 to start a savings account.") if initial_balance < 1000 + @min_balance = 1000 + @withdrawal_fee = 200 + end - # 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) + def add_interest(rate) + @interest = @balance * rate/100 + @balance += @interest + return @interest + end end From 8a3540ebcacc337c44fcd70da90daad51cdbaaa4 Mon Sep 17 00:00:00 2001 From: Riley Spicer Date: Thu, 8 Oct 2015 15:48:38 -0700 Subject: [PATCH 4/8] All primary requirements complete and functional. Separate run file created. New file for optional reqs created. --- bank.rb | 13 +++++++------ checking_account.rb | 24 ++++++++++++++++-------- money_market_account.rb | 0 run_bank.rb | 4 ++++ savings_account.rb | 9 ++------- 5 files changed, 29 insertions(+), 21 deletions(-) create mode 100644 money_market_account.rb create mode 100644 run_bank.rb diff --git a/bank.rb b/bank.rb index c171b809..9d4c7c0f 100644 --- a/bank.rb +++ b/bank.rb @@ -6,14 +6,15 @@ module Bank class Account attr_reader :balance, :owner, :account_id, :owner_id + MIN_BALANCE = 0 + WITHDRAWAL_FEE = 0 + def initialize (id, initial_balance, open_date) @account_id = id - raise ArgumentError.new("You can't start an account with a negative balance.") if initial_balance <= 0 + raise ArgumentError.new("That's not enough money to start your account.") if initial_balance <= MIN_BALANCE @balance = initial_balance # in cents open_date = open_date.to_s @open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %z") - @min_balance = 0 - @withdrawal_fee = 0 end # Return an array of all Account instances in account.csv @@ -47,10 +48,10 @@ def withdraw(amount) new_balance = @balance - amount if amount < 0 puts "You can't withdraw a negative amount." - elsif new_balance < @min_balance - puts "You don't have that much money. You can withdraw up to #{@balance - @min_balance - @withdrawal_fee} dollars." + elsif new_balance < MIN_BALANCE + puts "You don't have that much money. You can withdraw up to #{@balance - MIN_BALANCE - WITHDRAWAL_FEE} dollars." else - @balance = new_balance - @withdrawal_fee + @balance = new_balance - WITHDRAWAL_FEE return @balance end end diff --git a/checking_account.rb b/checking_account.rb index f5e5d8bd..2d37da06 100644 --- a/checking_account.rb +++ b/checking_account.rb @@ -1,12 +1,13 @@ - +module Bank class CheckingAccount < Account + attr_reader :used_checks, :balance, :account_id, :owner_id - def initialize - - end - - def withdraw + MIN_BALANCE = 0 + WITHDRAWAL_FEE= 100 + def initialize(id, initial_balance, open_date) + super + @used_checks = 0 end # The input amount gets taken out of the account as a result of a check withdrawal. Returns the updated account balance. @@ -15,11 +16,18 @@ def withdraw #reset_checks: Resets the number of checks used to zero def withdraw_using_check(amount) - + if @used_checks >= 3 + @balance = @balance - 200 + end + new_balance = @balance - amount + raise ArgumentError.new("You don't have enough money for that.") if new_balance <= @balance - 1000 + @used_checks += 1 + @balance = new_balance end def reset_checks - #reset checks + @used_checks = 0 end end +end diff --git a/money_market_account.rb b/money_market_account.rb new file mode 100644 index 00000000..e69de29b diff --git a/run_bank.rb b/run_bank.rb new file mode 100644 index 00000000..de06024b --- /dev/null +++ b/run_bank.rb @@ -0,0 +1,4 @@ +require "./bank.rb" +require "./savings_account.rb" +require "./checking_account.rb" +require "./money_market_account.rb" diff --git a/savings_account.rb b/savings_account.rb index 0a759a07..eca40889 100644 --- a/savings_account.rb +++ b/savings_account.rb @@ -1,16 +1,11 @@ -require "./bank.rb" module Bank class SavingsAccount < Account attr_reader :balance, :owner, :account_id, :owner_id - def initialize(id, initial_balance, open_date) - super - raise ArgumentError.new("You must have at least $10 to start a savings account.") if initial_balance < 1000 - @min_balance = 1000 - @withdrawal_fee = 200 - end + MIN_BALANCE = 1000 + WITHDRAWAL_FEE = 200 def add_interest(rate) @interest = @balance * rate/100 From 754b98d4bc5f0dcb0c676bfd7dad6309604b7aa6 Mon Sep 17 00:00:00 2001 From: Riley Spicer Date: Thu, 8 Oct 2015 16:38:09 -0700 Subject: [PATCH 5/8] All files complete, still fixing a couple bugs in money_market_account --- money_market_account.rb | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/money_market_account.rb b/money_market_account.rb index e69de29b..45870d44 100644 --- a/money_market_account.rb +++ b/money_market_account.rb @@ -0,0 +1,50 @@ +module Bank + + class MoneyMarketAccount < Account + attr_reader :balance, :owner, :account_id, :owner_id, :good_standing, :max_trans + + MIN_BALANCE = 1000000 + + def initialize(id, initial_balance, open_date) + super + @max_trans = 0 + @good_standing = true + end + + def withdraw(amount) + new_balance = @balance - amount + if @max_trans >= 6 || @good_standing == false + puts "No more transactions available." + elsif amount < 0 + puts "You can't withdraw a negative amount." + elsif new_balance < MIN_BALANCE + @balance = @balance - amount - 10000 + @good_standing == false + puts "Next time you need to deposit enouhg money to bring your account up to #{MIN_BALANCE}" + @max_trans += 1 + else + @balance = new_balance + return @balance + @max_trans += 1 + end + end + + def deposit(amount) + if @balance < 1000000 + super(amount) + else + super(amount) + @max_trans += 1 + end + if @balance > 1000000 + @good_standing == true + end + end + + def reset_transactions + @max_trans + end + + end + +end From 6a9a01a48b6ed5aaf0609024e2ebfc5d9d6acb9f Mon Sep 17 00:00:00 2001 From: Riley Spicer Date: Thu, 8 Oct 2015 17:02:14 -0700 Subject: [PATCH 6/8] Now the main bug is fixed --- money_market_account.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/money_market_account.rb b/money_market_account.rb index 45870d44..4055ad67 100644 --- a/money_market_account.rb +++ b/money_market_account.rb @@ -23,9 +23,9 @@ def withdraw(amount) puts "Next time you need to deposit enouhg money to bring your account up to #{MIN_BALANCE}" @max_trans += 1 else + @max_trans += 1 @balance = new_balance return @balance - @max_trans += 1 end end From 6bdd69f8fa0a4709b0067826bca9dc525fdd61bd Mon Sep 17 00:00:00 2001 From: Riley Spicer Date: Fri, 9 Oct 2015 14:12:45 -0700 Subject: [PATCH 7/8] Completed program, I think bug free? --- bank.rb | 8 ++++---- money_market_account.rb | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bank.rb b/bank.rb index 9d4c7c0f..0c268f38 100644 --- a/bank.rb +++ b/bank.rb @@ -11,7 +11,7 @@ class Account def initialize (id, initial_balance, open_date) @account_id = id - raise ArgumentError.new("That's not enough money to start your account.") if initial_balance <= MIN_BALANCE + raise ArgumentError.new("That's not enough money to start your account.") if initial_balance <= self.class::MIN_BALANCE @balance = initial_balance # in cents open_date = open_date.to_s @open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %z") @@ -48,10 +48,10 @@ def withdraw(amount) new_balance = @balance - amount if amount < 0 puts "You can't withdraw a negative amount." - elsif new_balance < MIN_BALANCE - puts "You don't have that much money. You can withdraw up to #{@balance - MIN_BALANCE - WITHDRAWAL_FEE} dollars." + elsif new_balance < self.class::MIN_BALANCE + puts "You don't have that much money. You can withdraw up to #{@balance - self.class::MIN_BALANCE - self.class::WITHDRAWAL_FEE} dollars." else - @balance = new_balance - WITHDRAWAL_FEE + @balance = new_balance - self.class::WITHDRAWAL_FEE return @balance end end diff --git a/money_market_account.rb b/money_market_account.rb index 4055ad67..d0ad2114 100644 --- a/money_market_account.rb +++ b/money_market_account.rb @@ -17,10 +17,10 @@ def withdraw(amount) puts "No more transactions available." elsif amount < 0 puts "You can't withdraw a negative amount." - elsif new_balance < MIN_BALANCE + elsif new_balance < self.class::MIN_BALANCE @balance = @balance - amount - 10000 - @good_standing == false - puts "Next time you need to deposit enouhg money to bring your account up to #{MIN_BALANCE}" + @good_standing = false + puts "Next time you need to deposit enough money to bring your account up to #{self.class::MIN_BALANCE}" @max_trans += 1 else @max_trans += 1 From 36e40abb15ada69968a6da7938e2377f6e5d9279 Mon Sep 17 00:00:00 2001 From: Riley Spicer Date: Sun, 11 Oct 2015 13:05:19 -0700 Subject: [PATCH 8/8] Last couple editing errors worked out, post group code review. --- bank.rb | 2 +- money_market_account.rb | 3 +++ savings_account.rb | 10 +++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/bank.rb b/bank.rb index 0c268f38..e4fd80bc 100644 --- a/bank.rb +++ b/bank.rb @@ -49,7 +49,7 @@ def withdraw(amount) if amount < 0 puts "You can't withdraw a negative amount." elsif new_balance < self.class::MIN_BALANCE - puts "You don't have that much money. You can withdraw up to #{@balance - self.class::MIN_BALANCE - self.class::WITHDRAWAL_FEE} dollars." + puts "You don't have that much money. You can withdraw up to #{@balance - self.class::MIN_BALANCE - self.class::WITHDRAWAL_FEE} cents." else @balance = new_balance - self.class::WITHDRAWAL_FEE return @balance diff --git a/money_market_account.rb b/money_market_account.rb index d0ad2114..7462d7e2 100644 --- a/money_market_account.rb +++ b/money_market_account.rb @@ -22,6 +22,9 @@ def withdraw(amount) @good_standing = false puts "Next time you need to deposit enough money to bring your account up to #{self.class::MIN_BALANCE}" @max_trans += 1 + elsif new_balance < 0 + puts "That will make your balance negative. Please try a smaller amount." + return @balance else @max_trans += 1 @balance = new_balance diff --git a/savings_account.rb b/savings_account.rb index eca40889..7c27355d 100644 --- a/savings_account.rb +++ b/savings_account.rb @@ -8,9 +8,13 @@ class SavingsAccount < Account WITHDRAWAL_FEE = 200 def add_interest(rate) - @interest = @balance * rate/100 - @balance += @interest - return @interest + if rate < 0 + puts "Please select a positive interest rate." + else + @interest = @balance * rate/100 + @balance += @interest + return @interest + end end end