From b79bdfe503a4328712f3ff1f93473a1f8a762833 Mon Sep 17 00:00:00 2001 From: Kari Bancroft Date: Thu, 8 Oct 2015 11:13:05 -0700 Subject: [PATCH 1/7] 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 f988c663d6087dd113fff7328cf3a5aec2b39cd0 Mon Sep 17 00:00:00 2001 From: Wesley Willis Date: Thu, 8 Oct 2015 13:49:42 -0700 Subject: [PATCH 2/7] created 3 class files and main file for wave 3 --- account_class.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ bankaccount_wave3.rb | 3 +++ checking_class.rb | 1 + savings_class.rb | 1 + 4 files changed, 47 insertions(+) create mode 100644 account_class.rb create mode 100644 bankaccount_wave3.rb create mode 100644 checking_class.rb create mode 100644 savings_class.rb diff --git a/account_class.rb b/account_class.rb new file mode 100644 index 00000000..09092a16 --- /dev/null +++ b/account_class.rb @@ -0,0 +1,42 @@ +module Bank + class Account + attr_reader :account_id, :balance, :time + #allows account to be created with an initial balance as a parameter + def initialize(account_id, balance, time) + #creates ID# + @account_id = account_id + @balance = balance + @time = time + #prevents initial balance from being a negative amount + if balance < 0 + raise ArgumentError, "No negative balance allowed! Live within your means!" + end + end + + #method to create an ID number, not unique number yet + def generate_id + user_id = rand(0..101) + return user_id + end + + #method for withdrawal + def withdrawal(subtract_money) + if (@balance - subtract_money) >= 0 + @balance = (@balance - subtract_money) + #returns updated account balance + return @balance + else + #rejects negative balance, and returns current balance + puts "Your withdrawal was rejected. You only have #{@balance} dollars." + puts "You are not allowed to overdraft. Try a smaller withdrawal." + end + end + + #method for deposit + def deposit(add_money) + @balance = (@balance + add_money) + #returns updated account balance + return @balance + end + end +end diff --git a/bankaccount_wave3.rb b/bankaccount_wave3.rb new file mode 100644 index 00000000..b3a9ea98 --- /dev/null +++ b/bankaccount_wave3.rb @@ -0,0 +1,3 @@ +require "./account_class.rb" +require "./checking_class.rb" +require "./savings_class.rb" diff --git a/checking_class.rb b/checking_class.rb new file mode 100644 index 00000000..15e494bb --- /dev/null +++ b/checking_class.rb @@ -0,0 +1 @@ +require "./account_class.rb" diff --git a/savings_class.rb b/savings_class.rb new file mode 100644 index 00000000..15e494bb --- /dev/null +++ b/savings_class.rb @@ -0,0 +1 @@ +require "./account_class.rb" From 55f8fe68596f8f451b70ec9e7c06f5216b19e4eb Mon Sep 17 00:00:00 2001 From: Wesley Willis Date: Thu, 8 Oct 2015 14:02:07 -0700 Subject: [PATCH 3/7] add account_opened method to call the current time when new account created --- account_class.rb | 13 +++++++++---- checking_class.rb | 9 +++++++++ savings_class.rb | 12 ++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/account_class.rb b/account_class.rb index 09092a16..cb32d4ba 100644 --- a/account_class.rb +++ b/account_class.rb @@ -2,11 +2,11 @@ module Bank class Account attr_reader :account_id, :balance, :time #allows account to be created with an initial balance as a parameter - def initialize(account_id, balance, time) + def initialize(balance) #creates ID# - @account_id = account_id + @account_id = generate_id @balance = balance - @time = time + @time = account_opened #prevents initial balance from being a negative amount if balance < 0 raise ArgumentError, "No negative balance allowed! Live within your means!" @@ -15,10 +15,15 @@ def initialize(account_id, balance, time) #method to create an ID number, not unique number yet def generate_id - user_id = rand(0..101) + user_id = rand(1000..9000) return user_id end + def account_opened + time = Time.new + return time + end + #method for withdrawal def withdrawal(subtract_money) if (@balance - subtract_money) >= 0 diff --git a/checking_class.rb b/checking_class.rb index 15e494bb..6294846b 100644 --- a/checking_class.rb +++ b/checking_class.rb @@ -1 +1,10 @@ require "./account_class.rb" + +#Create a `CheckingAccount` class which should inherit behavior from the `Account` class. It should include the following updated functionality: +#- 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. +#- `#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 +#- `#reset_checks`: Resets the number of checks used to zero diff --git a/savings_class.rb b/savings_class.rb index 15e494bb..ced1d5f2 100644 --- a/savings_class.rb +++ b/savings_class.rb @@ -1 +1,13 @@ require "./account_class.rb" + +#Create a `SavingsAccount` class which should inherit behavior from the `Account` class. It should include the following updated functionality: +#- 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 +# +#It should include the following new method: +#- `#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. From 1438d2c8d2cc2215dcaf5318c8c9542a38125691 Mon Sep 17 00:00:00 2001 From: Wesley Willis Date: Thu, 8 Oct 2015 14:12:11 -0700 Subject: [PATCH 4/7] add child classes checking and savings --- account_class.rb | 2 +- checking_class.rb | 5 ++++- savings_class.rb | 5 ++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/account_class.rb b/account_class.rb index cb32d4ba..31cfc2d9 100644 --- a/account_class.rb +++ b/account_class.rb @@ -9,7 +9,7 @@ def initialize(balance) @time = account_opened #prevents initial balance from being a negative amount if balance < 0 - raise ArgumentError, "No negative balance allowed! Live within your means!" + raise Exception.new, "No negative balance allowed! Live within your means!" end end diff --git a/checking_class.rb b/checking_class.rb index 6294846b..10bdeb1d 100644 --- a/checking_class.rb +++ b/checking_class.rb @@ -1,4 +1,7 @@ -require "./account_class.rb" +module Bank + class Checking < Account + end +end #Create a `CheckingAccount` class which should inherit behavior from the `Account` class. It should include the following updated functionality: #- Updated withdrawal functionality: diff --git a/savings_class.rb b/savings_class.rb index ced1d5f2..340278a1 100644 --- a/savings_class.rb +++ b/savings_class.rb @@ -1,4 +1,7 @@ -require "./account_class.rb" +module Bank + class Savings < Account + end +end #Create a `SavingsAccount` class which should inherit behavior from the `Account` class. It should include the following updated functionality: #- The initial balance cannot be less than $10. If it is, this will `raise` an `ArgumentError` From 83710953691d74990564ae7e8c970690587b9790 Mon Sep 17 00:00:00 2001 From: Wesley Willis Date: Thu, 8 Oct 2015 15:15:04 -0700 Subject: [PATCH 5/7] add more details to withdraw_using_check method --- account_class.rb | 19 +++++++++++++++---- checking_class.rb | 30 ++++++++++++++++++++++++++++++ savings_class.rb | 3 +++ 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/account_class.rb b/account_class.rb index 31cfc2d9..95f1cda7 100644 --- a/account_class.rb +++ b/account_class.rb @@ -5,15 +5,26 @@ class Account def initialize(balance) #creates ID# @account_id = generate_id - @balance = balance + @balance = balance_restriction(balance) @time = account_opened + + #prevents initial balance from being a negative amount - if balance < 0 - raise Exception.new, "No negative balance allowed! Live within your means!" - end + #if balance < 0 + # raise Exception.new, "No negative balance allowed! Live within your means!" + #end end #method to create an ID number, not unique number yet + + def balance_restriction (balance) + if balance < 0 + raise Exception.new("No negative balance allowed! Live within your means!") + else + return balance + end + end + def generate_id user_id = rand(1000..9000) return user_id diff --git a/checking_class.rb b/checking_class.rb index 10bdeb1d..1d58b74c 100644 --- a/checking_class.rb +++ b/checking_class.rb @@ -1,5 +1,35 @@ module Bank class Checking < Account + + def initialize(balance) + super(balance) + end + + #method for withdrawal + def withdrawal(subtract_money) + if (@balance - subtract_money - 1) >= 0 + @balance = (@balance - subtract_money - 1) + #returns updated account balance + return @balance + else + #rejects negative balance, and returns current balance + puts "Your withdrawal was rejected. You only have #{@balance} dollars." + puts "You are not allowed to overdraft. Try a smaller withdrawal." + end + end + + + def withdraw_using_check(subtract_money) + if (@balance - subtract_money.abs) >= -10 + @balance = (@balance - subtract_money.abs) + #returns updated account balance with a transaction fee of $1 removed from balance + return @balance + else + #rejects negative balance, and returns current balance + puts "Your withdrawal was rejected. You only have #{@balance} dollars." + puts "You are not allowed to overdraft more than $10. Try a smaller withdrawal." + end + end end end diff --git a/savings_class.rb b/savings_class.rb index 340278a1..fcdc5dcc 100644 --- a/savings_class.rb +++ b/savings_class.rb @@ -1,5 +1,8 @@ module Bank class Savings < Account + def initialize + super + end end end From 7483509aaf1bc2207c4f84d3416667d9382dc420 Mon Sep 17 00:00:00 2001 From: Wesley Willis Date: Thu, 8 Oct 2015 15:35:29 -0700 Subject: [PATCH 6/7] fix withdraw check method --- checking_class.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/checking_class.rb b/checking_class.rb index 1d58b74c..7b9639ba 100644 --- a/checking_class.rb +++ b/checking_class.rb @@ -3,6 +3,7 @@ class Checking < Account def initialize(balance) super(balance) + @check_count = 0 end #method for withdrawal @@ -23,6 +24,13 @@ def withdraw_using_check(subtract_money) if (@balance - subtract_money.abs) >= -10 @balance = (@balance - subtract_money.abs) #returns updated account balance with a transaction fee of $1 removed from balance + #check_count = 0 + @check_count += 1 + if @check_count > 3 + transaction_fee = 2 + @balance = @balance - transaction_fee + end + puts @check_count return @balance else #rejects negative balance, and returns current balance @@ -30,6 +38,10 @@ def withdraw_using_check(subtract_money) puts "You are not allowed to overdraft more than $10. Try a smaller withdrawal." end end + + def reset_checks + @check_count = 0 + end end end From 1597defa2d23bfa4353910834d5a984e8e6cfc4c Mon Sep 17 00:00:00 2001 From: Wesley Willis Date: Thu, 8 Oct 2015 16:17:48 -0700 Subject: [PATCH 7/7] add all base requirements to assignment --- savings_class.rb | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/savings_class.rb b/savings_class.rb index fcdc5dcc..36d194ad 100644 --- a/savings_class.rb +++ b/savings_class.rb @@ -1,7 +1,35 @@ module Bank class Savings < Account - def initialize - super + def initialize(balance) + super(balance) + @transaction_fee = 2 + end + + def balance_restriction (balance) + if balance < 10 + raise Exception.new("Your balance is not allowed to go below $10!") + else + return balance + end + end + + def interest(rate) + previous_balance = @balance + @balance = previous_balance + (@balance * rate)/100 + interest_earned = @balance - previous_balance + return "Your balance is #{@balance} dollars and you have earned #{interest_earned} dollars in interest" + end + + def withdrawal(subtract_money) + if (@balance - subtract_money - @transaction_fee) >= 10 + @balance = (@balance - subtract_money - @transaction_fee) + #returns updated account balance + return @balance + else + #rejects negative balance, and returns current balance + puts "Your withdrawal was rejected. You only have #{@balance} dollars." + puts "You are not allowed to overdraft. Try a smaller withdrawal." + end end end end