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

Wave 3 Bank Accounts #67

Open
wants to merge 27 commits into
base: jln/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b79bdfe
Add wave 3
kariabancroft Oct 8, 2015
8814190
Merge remote-tracking branch 'upstream/master' into jln/master
noglows Oct 8, 2015
8edeb3f
Made a new bank.rb file that requires all the different account types
noglows Oct 8, 2015
c364b4f
Broke the accounts into different files
noglows Oct 8, 2015
622f68c
Updated old bank.rb file - this will be deleted later
noglows Oct 8, 2015
f851166
Updated fee to a float
noglows Oct 8, 2015
73915bb
Updated withdraw logic so that edge cases are handled
noglows Oct 8, 2015
a04961a
Initial working checking account
noglows Oct 8, 2015
715cb38
Added the reset checks method
noglows Oct 8, 2015
b789fb0
Added money_market_account and modified account withdraw method to ac…
noglows Oct 8, 2015
2406a37
Fixed some money market issues
noglows Oct 9, 2015
cbb30ef
Fixed bug in withdraw method and added add_interest method to parent …
noglows Oct 9, 2015
aaa58fb
Fixed bugs in money market account
noglows Oct 9, 2015
8b98e5a
Modified checking and savings account to take dollars as input instea…
noglows Oct 9, 2015
06832af
Cleaning up files
noglows Oct 9, 2015
6a7a92d
Cleaning up file names
noglows Oct 9, 2015
c021e14
Created retired files folder
noglows Oct 9, 2015
7d83da6
All outputs to the user round to two decimal places
noglows Oct 9, 2015
35448bd
Fixed more rounding errors
noglows Oct 9, 2015
92ba7b1
Added comments to Money Market
noglows Oct 9, 2015
50509e6
Added comments to checking account
noglows Oct 9, 2015
0073289
Added comments to savings account
noglows Oct 9, 2015
f418c1f
Comment to bank.rb file
noglows Oct 9, 2015
3ee8881
Removed the to-do.txt file
noglows Oct 9, 2015
b10b425
Finished comment and fixed money market bug
noglows Oct 12, 2015
e2ef83e
Fixed Money Market withdrawal bug
noglows Oct 12, 2015
76268ff
Removed owner require from Account
noglows Oct 12, 2015
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
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
-->
202 changes: 7 additions & 195 deletions bank.rb
Original file line number Diff line number Diff line change
@@ -1,195 +1,7 @@
require 'csv'
require 'pry'

module Bank
class Account

attr_reader :balance, :id
attr_accessor :owner

def initialize(id, initial_balance, open_date)
@id = id.to_i
@balance = initial_balance.to_i/100.0
@open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %z")
#@owner = nil

# Raises an argument error if the initial balance is less than 0
if initial_balance.to_i < 0
raise ArgumentError, "The balance cannot be less than 0."
end
end

# Creates accounts from the accounts.csv file
def self.all
@accounts = []
accounts_csv = CSV.read("support/accounts.csv")
accounts_csv.each do |id, balance, date|
id = Bank::Account.new(id,balance,date)
@accounts.push(id)
end
#puts @accounts
return @accounts
end

# Finds the account with the ID that matches the passed parameter and returns the instance
def self.find(id_search)
found = @accounts.find do |account|
account.id == id_search
end
return found
end

# Links owners with accounts
def self.link_owner
self.all
Bank::Owner.all
accounts_with_owners = []
account_owners_csv = CSV.read("support/account_owners.csv")
account_owners_csv.each do |row|
account = self.find(row[0].to_i)
owner_account = Bank::Owner.find(row[1].to_i)
account.owner = owner_account
accounts_with_owners.push(account)
end
return accounts_with_owners
end

# ----------------------------------------- #
# Work below is extra #

# Displays (with formatting) the account details for all the accounts in accounts.csv
# (Made this on accident and didn't want to let it go to waste!)
def self.all_print_nice
if @accounts == nil
puts "There are no accounts."
else
@accounts.each do |account|
puts account
account.current_balance
end
end
return
end

# Finds an account by id passed in as a parameter and displays the account information nicely formatted
# (Made this on accident and didn't want to let it go to waste!)
def self.find_and_display(id_search)
found = @accounts.find do |account|
account.id == id_search
end
return found.current_balance
end
# end of extra work #
# ----------------------------------------#

# Method for withdrawing from account
def withdraw(amount_to_withdraw)
# Checks that the user is not withdrawing more than what is available in the account
if (@balance - amount_to_withdraw)< 0
puts "The requested withdrawal is more than the available funds."
puts "You only have $#{@balance} available for withdrawal."
return @balance
else
# makes the withdrawal and displays info to the user
@balance -= amount_to_withdraw
puts "You have withdrawn $#{amount_to_withdraw}."
puts "Your current balance is $#{@balance}"
return @balance
end
end

# Method for depositing into account
def deposit(amount_to_deposit)
# Makes the deposit and displays info to the user
@balance += amount_to_deposit
puts "You have deposited $#{amount_to_deposit}."
puts "Your current balance is $#{@balance}."
return @balance
end

# Displays current balance in the account
def current_balance
puts "The account with ID #{@id} currently has a balance of $#{@balance}."
puts "This account was set up on #{@open_date}"
end


end

class Owner
attr_reader :first_name, :last_name, :street, :city, :state, :id

def initialize(owner_hash)
@id = owner_hash[:id]
@first_name = owner_hash[:first_name]
@last_name = owner_hash[:last_name]
@street_address = owner_hash[:street_address]
@city = owner_hash[:city]
@state = owner_hash[:state]
end

# Method to display details of an owner instance
def print_owner_details
puts "The owner of this account is #{@first_name} #{@last_name}."
puts "Street: #{@street_address}"
puts "City: #{@city}"
puts "State: #{@state}"
end

# Creates accounts from the accounts.csv file
def self.all
owner_hash = Hash.new
@owners = []
owners_csv = CSV.read("support/owners.csv")
owners_csv.each do |id, last_name, first_name, street_address, city, state|
owner_hash[:id] = id.to_i
owner_hash[:last_name] = last_name
owner_hash[:first_name] = first_name
owner_hash[:street_address] = street_address
owner_hash[:city] = city
owner_hash[:state] = state
id = Bank::Owner.new(owner_hash)
@owners.push(id)
end
puts @owners
return @owners
end

# Finds the owner with the ID that matches the passed parameter and returns the instance
def self.find(id_search)
found = @owners.find do |owner|
owner.id == id_search
end
return found
end


# ----------------------------------------- #
# Work below is extra #

# Displays (with formatting) the owner details for all the accounts in owners.csv
def self.all_print_nice
if @owners == nil
puts "There are no accounts."
else
@owners.each do |owner|
owner.print_owner_details
end
end
return
end

# Finds an owner by id passed in as a parameter and displays the owner information nicely formatted
def self.find_and_display(id_search)
found = @owners.find do |owner|
owner.id == id_search
end
return found.print_owner_details
end

# end of extra work #
# ----------------------------------------#

end

end
# Master bank file
# Requires all the seperate class files for Bank Accounts
require './lib/account.rb'
require './lib/owner.rb'
require './lib/savings_account.rb'
require './lib/checking_account.rb'
require './lib/money_market_account.rb'
Loading