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

Danielle - BankAccounts Waves 1-3 #9

Open
wants to merge 11 commits into
base: 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
72 changes: 72 additions & 0 deletions account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
require 'csv'
require_relative 'owner'

module Bank
class Account
MINIMUM_BALANCE = 0

attr_accessor :id, :balance, :date, :accounts

def initialize(id, balance, date = nil)
@id = id #account id
@balance = balance #in cents
@date = date

unless @balance >= Bank::Account::MINIMUM_BALANCE
raise ArgumentError.new("A new account cannot be created with less than $#{ MINIMUM_BALANCE }.")
end
end

def add_owner(id, lname, fname, address, city, state)
Bank::Owner.new(id, lname, fname, address, city, state)
end

#withdraws specified amount, will not allow withdrawl if remaining balance is less than 0.
def withdraw(amount)
if amount <= @balance && (@balance - amount >= self.class::MINIMUM_BALANCE)
@balance -= amount
else
puts "Your account does not contain enough to withdraw the amount requested."
end
return @balance
end

#deposits specified amount
def deposit(amount)
@balance += amount
return @balance
end

# return collection of Account instances
def self.all
accounts = []
CSV.read('support/accounts.csv').each do |line|
accounts << self.new(line[0].to_i, line[1].to_i, line[2])
end
return accounts
end

# returns an instance of Account where value of the id matches the parameter
def self.find(id)
all.each do |i|
if i.id == id
return i
end
end
puts "No account with ID ##{ id }."
end

### am able to retrieve account/owner information but have not yet been able to associate them and combine stored values ###
# creates relationship between accounts and owners
def self.acct_with_owner
owner_accounts = []
CSV.read('support/account_owners.csv').each do |line|
puts Account.find(line[0].to_i)
puts Owner.find(line[1].to_i)
# owner_accounts << (Account.find(line[0].to_i), Owner.find(line[1].to_i))
end
owner_accounts
end

end
end
37 changes: 37 additions & 0 deletions checkingaccount.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require_relative 'account'

class CheckingAccount < Bank::Account
TRANSACTION_FEE = 100 # cents
CHECK_WITHDRAWL_FEE = 200 # cents
MAX_OVERDRAFT = 1000 # cents

attr_accessor :checks_remaining

def initialize(id, balance, date)
super(id, balance, date)
@checks_remaining = 3
end

# withdrawl with transaction fee
def withdraw(amount)
amount += TRANSACTION_FEE
super(amount)
end

# withdrawl fee activated if more than 3 checks used, overdraft limit
def withdraw_using_check(amount)
amount += CHECK_WITHDRAWL_FEE if @checks_remaining <= 0
if amount <= @balance + MAX_OVERDRAFT
@balance -= amount
@checks_remaining -= 1
else
puts "Your account does not contain enough to withdraw the amount requested. You may not overdraft more than $#{ '%.2f' % (MAX_OVERDRAFT / 100.0)}."
end
return @balance
end

# resets check count to avoid transaction fee
def reset_checks
@checks_remaining = 3
end
end
42 changes: 42 additions & 0 deletions owner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require 'csv'

module Bank
class Owner
attr_accessor :id, :last_name, :first_name, :address, :city, :state

def initialize(id, lname, fname, address, city, state)
@id = id
@last_name = lname
@first_name = fname
@address = address
@city = city
@state = state
end

def owner_info
puts "Owner's id: #{ @id }"
puts "Owner's name: #{ @name }"
puts "Owner's address: #{ @address }, #{ @city }, #{ @state }"
end

# returns a collection of Owner instances
def self.all
owners = []
CSV.read('support/owners.csv').each do |line|
owners << Bank::Owner.new(line[0].to_i, line[1], line[2], line[3], line[4], line[5])
end
return owners
end

# returns an instance of Owner based on id parameter
def self.find(id)
all.each do |i|
if i.id == id
return i
end
end
puts "There is no owner with ID ##{ id }."
end

end
end
31 changes: 31 additions & 0 deletions savingsaccount.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require_relative 'account'

class SavingsAccount < Bank::Account
MINIMUM_BALANCE = 1000 # in cents
TRANSACTION_FEE = 200 # in cents

attr_accessor :id, :balance, :date

def initialize(id, balance, date)
@id = id
@balance = balance
@date = date

unless @balance >= self.class::MINIMUM_BALANCE
raise ArgumentError.new("A new account cannot be created with less than $#{ '%.2f' % (self.class::MINIMUM_BALANCE / 100.0) }.")
end
end

# maintain minimum balance in account including transaction fee
def withdraw(amount)
amount += TRANSACTION_FEE
super(amount)
end

# add interest rate as specified or default, returns interest
def add_interest(rate = 0.25)
interest = @balance * rate/100
@balance += interest
return interest
end
end