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 Accounts - Wave 3 #72

Open
wants to merge 7 commits into
base: KED/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
27 changes: 7 additions & 20 deletions BankAccounts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
module Bank
class Account
attr_reader :ident, :balance, :open_date
attr_accessor :owner
def initialize(ident, balance, open_date, owner = nil)
def initialize(ident, balance, open_date)
@ident = ident.to_i
@balance = balance.to_i
if @balance < 0
@min_balance = 0
check_valid_balance
@open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %z")
end
def check_valid_balance

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 used this method to check the balance, I would recommend adding whitespace between the end from a previous method and the def of a new method

if @balance < @min_balance
raise ArgumentError, "Not a valid initial balance!"
end
@open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %z")
@owner = owner
end
def withdraw(amount)
if amount > @balance
Expand All @@ -35,19 +37,4 @@ def self.find(id)
end
end
end

class Owner
attr_reader :id, :first, :last, :street_address, :city, :state, :zip
def initialize(owner_info)
@id = rand(1000000)
@first = owner_info[:first]
@last = owner_info[:last]
@street_address = owner_info[:street_address]
@city = owner_info[:city]
@state = owner_info[:state]
@zip = owner_info[:zip]
end
end
end

Bank::Account.find(1213)
28 changes: 28 additions & 0 deletions CheckingAccount.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require './BankAccounts.rb'
class CheckingAccount < Bank::Account

Choose a reason for hiding this comment

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

Same comment in this class with regards to adding some whitespace between method definitions to provide some additional logical separation

attr_reader :check_count
def initialize(ident, balance, open_date)
super
@check_count = 0
end
def withdraw(amount)
amount += 100
super
end
def withdraw_using_check(amount)
if amount > (@balance + 1000)
puts "Not enough fundz!"
else
if @check_count < 3
@balance -= (amount + 100)
@check_count += 1
else
@balance -= (amount + 300)
end
return @balance
end
end
def reset_checks
@check_count = 0
end
end
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
-->
24 changes: 24 additions & 0 deletions SavingsAccount.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require './BankAccounts.rb'
class SavingsAccount < Bank::Account
def initialize(ident, balance, open_date)
@ident = ident.to_i
@balance = balance.to_i
@min_balance = 1000
check_valid_balance
@open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %z")
end
def withdraw(amount)
if amount > (@balance - @min_balance - 200)
puts "You must maintain a $10 minimum balance!"
return @balance
else
super
@balance -= 200
end
end
def add_interest(rate)
interest = @balance * (rate.to_f/100)
@balance += interest
return interest
end
end