-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bank of Lauren: Wave 3 #69
base: lrg/master
Are you sure you want to change the base?
Changes from all commits
b79bdfe
a9280fa
3155b6c
a9e8caa
c934f1e
37a290a
7854398
ae058d3
da4b900
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In your |
||
|
@@ -47,42 +48,65 @@ def self.find(id) | |
# ### Error handling | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the |
||
# - 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a user calls this method will they be specifying their own fee amount? I'd choose zero 👍 |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Watch your indentation in this block, when you start an |
||
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: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the way you've used comments throughout to keep track of what you're trying to accomplish. I'd recommend trying to keep the indentation of the comment the same as the indentation of the line above or below to make it more readable for yourself and others. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like you're using this value |
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe also a good place to use a constant to track the maximum number of transactions |
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like you're doing this |
||
return interest.to_i | ||
end | ||
|
||
end | ||
|
||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want the "user" of your accounts to be able to specify their own minimum deposit amount?