Skip to content
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

Open
wants to merge 9 commits into
base: lrg/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions AddressHashes.rb

This file was deleted.

6 changes: 6 additions & 0 deletions BankofLauren.rb
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"
30 changes: 14 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<!--
## Wave 3
Create a `SavingsAccount` class which should inherit behavior from the `Account` class. It should include updated logic with the following functionality:
- An updated `initialize` method:
- The initial balance cannot be less than $10. If it is, this will `raise` an `ArgumentError`
- An updated `withdraw` method:
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 methods:
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.

Create a `CheckingAccount` class which should inherit behavior from the `Account` class. It should include updated logic with the following functionality:
- `#withdraw(amount)`: The input amount gets taken out of the account as result of an ATM transaction. 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.
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
Expand All @@ -101,16 +100,15 @@ Create a `CheckingAccount` class which should inherit behavior from the `Account

## Optional:

Create a `MoneyMarketAccount` class with a minimum of 6 specs. The class should inherit behavior from the `Account` class.
Create a `MoneyMarketAccount` class which should inherit behavior from the `Account` class.
- A maximum of 6 transactions (deposits or withdrawals) are allowed per month on this account type
- `self.new(id, initial_balance)`: creates a new instance with the instance variable `id` and 'initial_balance' assigned
- The initial balance cannot be less than $10,000 - this will `raise` an `ArgumentError`
- `#withdraw(amount)`: The input amount gets taken out of the account as result of an ATM transaction. Returns the updated account balance.
- The initial balance cannot be less than $10,000 - this will `raise` an `ArgumentError`
- Updated withdrawal logic:
- 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
- `#deposit(amount)`. Returns the updated account balance.
- Updated deposit logic:
- Each transaction will be counted against the maximum number of transactions
- Exception to the above: A deposit performed to reach or exceed the minimum balance of $10,000 is not counted as part of the 6 transactions.
- `#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.
- `#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.
- `#reset_transactions`: Resets the number of transactions to zero
-->
67 changes: 46 additions & 21 deletions BankOfLauren.rb → bank_classes/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
Expand All @@ -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)

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?

@open_date = array_of_accounts[@@number_of_accounts][2]
@@number_of_accounts += 1
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In your self.all method below it might make more sense to use an each loop on the array_of_accounts rather that using a while loop

Expand Down Expand Up @@ -47,42 +48,65 @@ def self.find(id)
# ### Error handling

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the find method above, I would recommend using a more meaningful variable name rather than x

# - 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)

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watch your indentation in this block, when you start an if block you only need to indent within the block rather than at the start of the block

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)
Expand Down Expand Up @@ -117,7 +141,8 @@ def deposit(deposit_amount)
end
end
end
end

end


# #### Optional:
Expand Down
44 changes: 44 additions & 0 deletions bank_classes/checking_account_class.rb
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

Choose a reason for hiding this comment

The 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.

66 changes: 66 additions & 0 deletions bank_classes/money_market_account_class.rb
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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like you're using this value 10_000_00 a lot so it would be a good place to use a constant instead

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

Choose a reason for hiding this comment

The 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
39 changes: 39 additions & 0 deletions bank_classes/savings_account_class.rb
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like you're doing this to_i operation more than once so it seems like it would be worthwhile to store in a variable

return interest.to_i
end

end

end