diff --git a/AddressHashes.rb b/AddressHashes.rb deleted file mode 100644 index 848d3f74..00000000 --- a/AddressHashes.rb +++ /dev/null @@ -1,21 +0,0 @@ -ADDRESS_HASHES = { - -# name: { -# street_one: "", -# stree_two: "", -# city: "", -# state: "", -# country: "", -# zip: 00000 -# }, - -b: { - street_one: "", - stree_two: "", - city: "", - state: "", - country: "", - zip: 00000 -}, - -} diff --git a/BankofLauren.rb b/BankofLauren.rb new file mode 100644 index 00000000..080f19b0 --- /dev/null +++ b/BankofLauren.rb @@ -0,0 +1,6 @@ +require "pry" + +require "./bank_classes/account_class.rb" +require "./bank_classes/checking_account_class.rb" +require "./bank_classes/savings_account_class.rb" +require "./bank_classes/money_market_account_class.rb" 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 - diff --git a/BankOfLauren.rb b/bank_classes/account_class.rb similarity index 72% rename from BankOfLauren.rb rename to bank_classes/account_class.rb index f545b4f8..609d9c31 100644 --- a/BankOfLauren.rb +++ b/bank_classes/account_class.rb @@ -1,6 +1,7 @@ #WELCOME TO THE BANK OF LAUREN # require "csv" +require "pry" # Create a `Bank` module which will contain your `Account` class and any future bank account logic. module Bank @@ -15,11 +16,11 @@ class Account attr_reader :balance # - A new account should be created with an ID and an initial balance - def initialize + def initialize(open_deposit_min = 0) array_of_accounts = CSV.read("./support/accounts.csv") @account_num = array_of_accounts[@@number_of_accounts][0] initial_deposit = array_of_accounts[@@number_of_accounts][1] - @balance = open_deposit_check(initial_deposit.to_i) + @balance = open_deposit_check(initial_deposit.to_i, open_deposit_min) @open_date = array_of_accounts[@@number_of_accounts][2] @@number_of_accounts += 1 end @@ -47,42 +48,65 @@ def self.find(id) # ### Error handling # - A new account cannot be created with initial negative balance - this will `raise` an `ArgumentError` (Google this) # begin - def open_deposit_check(initial_deposit) - transacting = true - while transacting do - if initial_deposit <= 0 - raise Exception.new("New accounts must be opened with a positive balance.") - else - transacting = false + def open_deposit_check(initial_deposit, open_deposit_min) + if initial_deposit <= open_deposit_min + raise Exception.new("New accounts must be opened with a balance of at least #{open_deposit_min}.") end return initial_deposit.to_i end - end # - Should have a `withdraw` method that accepts a single parameter which represents the amount of money that will be withdrawn. This method should return the updated account balance. - def withdraw (withdraw_amount) + def withdraw (withdraw_amount, fee = 0, min_balance = 0) transacting = true while transacting do - withdraw_check = withdraw_amount + + withdraw_check = (withdraw_amount + fee) if withdraw_check < 0 - puts "You cannot withdaw #{withdraw_amount}. Your account currently have a blance of #{@balance}." + puts "You cannot withdaw a negative amount. Your account currently have a blance of #{@balance}." print "Would you like to withdaw a differnt amount? " diff_amount = gets.chomp.downcase + if diff_amount == "yes" || diff_amount == "y" - puts "How much would you like to withdraw? " - withdraw_amount = gets.chomp.to_i - transacting = true + print "How much would you like to withdraw? >> " + withdraw_amount = gets.to_i + else + transacting = false + end + + elsif (@balance - withdraw_check) <= min_balance + print "You cannot withdaw #{withdraw_check}" + if fee > 0 + print ", #{withdraw_amount} plus the #{fee} fee" + puts ". Your account currently has a blance of #{@balance}." + print "Would you like to withdaw a differnt amount? " + diff_amount = gets.chomp.downcase + end + + if diff_amount == "yes" || diff_amount == "y" + print "How much would you like to withdraw? >> " + withdraw_amount = gets.to_i else transacting = false end + else balance_before = @balance - @balance = @balance - withdraw_check - puts "Your balance was #{balance_before}. You have withdrawn #{withdraw_amount}. Your balance is now #{@balance}." + @balance -= withdraw_check + print "Your balance was #{balance_before}. You have withdrawn #{withdraw_amount}" + + if fee != 0 + print " plus a #{fee} fee." + else + print ". " + end + + puts "Your balance is now #{@balance}." transacting = false + end - end - end + end #of do while + return @balance + end # of withdraw method # - Should have a `deposit` method that accepts a single parameter which represents the amount of money that will be deposited. def deposit(deposit_amount) @@ -117,7 +141,8 @@ def deposit(deposit_amount) end end end - end + +end # #### Optional: diff --git a/bank_classes/checking_account_class.rb b/bank_classes/checking_account_class.rb new file mode 100644 index 00000000..5acd8f3b --- /dev/null +++ b/bank_classes/checking_account_class.rb @@ -0,0 +1,44 @@ +require "pry" + +# Create a `CheckingAccount` class which should inherit behavior from the `Account` class. It should include the following updated functionality: +# - Updated withdrawal functionality: +module Bank + +# require "./account_class.rb" + + class CheckingAccount < Account + + def initialize + @checks_used = 0 + end + +# Each withdrawal 'transaction' incurs a fee of $1 that is taken out of the balance. + def withdraw(withdraw_amount, fee = 100, min_balance = -10_00) + #inherits these from account_class withdraw: + + # 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. + @balance = super(withdraw_amount, fee, min_balance) + end #of withdraw method + +# - `#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. +# calls withdraw method which: + # - Allows the account to go into overdraft up to -$10 but not any lower + def withdraw_using_check(withdraw_amount) + if @checks_used < 3 + withdraw(withdraw_amount, fee = 0) + @checks_used += 1 +# - The user is allowed three free check uses in one month, but any subsequent use adds a $2 transaction fee + else + withdraw(withdraw_amount, fee = 200) + end + end + + # # - `#reset_checks`: Resets the number of checks used to zero + def reset_checks + @checks_used = 0 + end + + end #of CheckingAccount class + +end #end of medule diff --git a/bank_classes/money_market_account_class.rb b/bank_classes/money_market_account_class.rb new file mode 100644 index 00000000..d1ed6e97 --- /dev/null +++ b/bank_classes/money_market_account_class.rb @@ -0,0 +1,66 @@ + +require "pry" + +module Bank + + # Create a `MoneyMarketAccount` class which should inherit behavior from the `Account` class. + class MoneyMarketAccount < Account + + # - The initial balance cannot be less than $10,000 - this will `raise` an `ArgumentError` + # - A maximum of 6 transactions (deposits or withdrawals) are allowed per month on this account type + def initialize + super(10_000_00) + @transactions_used = 0 + end + +# - Updated withdrawal logic: + def withdraw(withdraw_amount) + min_balance = (checking_min_balance + fee) + # - If a withdrawal causes the balance to go below $10,000, a fee of $100 is imposed and no more transactions are allowed until the balance is increased using a deposit transaction. + # - Each transaction will be counted against the maximum number of transactions + if @transactions_used < 6 + @balance = super(withdraw_amount) + if @balance < 10_000_00 + @balance -= 100_00 + @transactions_used = 6 + else + @transactions_used += 1 + end + else + puts "You have reached your transaction limit of 6 for this month. Please contact your banker if you have any questions." + end + end #of withdraw method + +# - Updated deposit logic: + def deposit(deposit_amount) +# - Exception to the below: A deposit performed to reach or exceed the minimum balance of $10,000 is not counted as part of the 6 transactions. + if (@balance < 10_000_00) && ((@balance + deposit_amount) >= 10_000_00) + super(deposit_amount) + elsif (@balance < 10_000_00) && ((@balance + deposit_amount) <= 10_000_00) + puts "Your balance is less that that minium requirement of 10,000.00" + puts "Please deposit a minium of #{10_000_00 - @balance} to gain access to your account again." +# - Each transaction will be counted against the maximum number of transactions + elsif @transactions_used < 6 + super(deposit_amount, fee = 0) + @transactions_used += 1 + else + puts "You have reached your transaction limit of 6 for this month. Please contact your banker if you have any questions." + end + 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). +# - Note** This is the same as the `SavingsAccount` interest. + interest = (@balance * (rate/100)) + @balance += interest.to_i + return interest.to_i + end + +# - `#reset_transactions`: Resets the number of transactions to zero + def reset_transactions + @transactions_used = 0 + end + + end + +end diff --git a/bank_classes/savings_account_class.rb b/bank_classes/savings_account_class.rb new file mode 100644 index 00000000..8eb07de0 --- /dev/null +++ b/bank_classes/savings_account_class.rb @@ -0,0 +1,39 @@ +require "pry" + +# Create a `SavingsAccount` class which should inherit behavior from the `Account` class. +module Bank + +# require "./account_class.rb" + + class SavingsAccount < Account +# It should include the following updated functionality: + +# - The initial balance cannot be less than $10. If it is, this will `raise` an `ArgumentError` + def initialize + super(10_00) + end + +# - Updated withdrawal functionality: + def withdraw(withdraw_amount, fee = 200, checking_min_balance = 10_00) + min_balance = (checking_min_balance + fee) + #inherits this functionality from account_class withdraw, parameters set to savings' specifications: + # 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 + # 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. + @balance = super(withdraw_amount, fee, min_balance) + end #of withdraw method + +# It should include the following new method: + 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 = (@balance * (rate/100)) + @balance += interest.to_i + return interest.to_i + end + + end + +end