Skip to content
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
605e211
Created Bank module and Account class. Account iinitialization requir…
annamm77 Feb 29, 2016
08aa4c7
Created Owner class. Initializes with a hash that includes name, addr…
annamm77 Feb 29, 2016
09ce462
Simplifled Owner Class to just include a name key iin the hash. Creat…
annamm77 Feb 29, 2016
bc1cec1
Just added :name to Account class attr:accessor in aa fruitless effor…
annamm77 Feb 29, 2016
7922efe
Edited define_user method so that its input will uupdate @name. It st…
annamm77 Mar 1, 2016
db047cc
Began Wave 2 requirements.
annamm77 Mar 2, 2016
9fcfa1f
Bank::Account creation loop works... omg!
annamm77 Mar 2, 2016
de4ede0
Removed redundant "acct_array" from self.all
annamm77 Mar 2, 2016
a69289e
Began work on self.find method.
annamm77 Mar 2, 2016
8650137
Self.find can now identify matching ID nums!
annamm77 Mar 2, 2016
8fa2c7e
self.find WORKS! I think?
annamm77 Mar 3, 2016
94f97df
AccountError doesnt work because strings arent integers..
annamm77 Mar 3, 2016
fa980ca
Fixed Argument Error Loop!
annamm77 Mar 3, 2016
cc01f61
Forgot that self.find method also needs strings convereted to integer…
annamm77 Mar 3, 2016
197978c
Created SavingsAccount Class.
annamm77 Mar 3, 2016
577dfe8
SavingsAccount add_interest method added.
annamm77 Mar 3, 2016
a8091cd
CheckingAccount has withdraw_using_check method
annamm77 Mar 3, 2016
6c91bb6
Self.Find now returns correct bank::account instance
annamm77 Mar 3, 2016
6cbee06
Cleaned out comments. Tested all methods. Seems functional for primar…
annamm77 Mar 3, 2016
3327d73
Fixing "magic numbers". Done with Account class.
annamm77 Mar 4, 2016
7791c0f
Extracted magic numbers in SavingsAccount, updated @transaction_fee a…
annamm77 Mar 4, 2016
66e0c58
Removed magic numbers from CheckingAccount.
annamm77 Mar 4, 2016
d43f3ae
moved @checknum from Accounts to CheckingAccount
annamm77 Mar 4, 2016
93888f6
Functional. Tested all methods. Small output edits for readability.
annamm77 Mar 4, 2016
8d709c8
Used super in subclass methods. Proofreading and full test done.
annamm77 Mar 4, 2016
310e807
Withdraw method now returns current balance
annamm77 Mar 4, 2016
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
135 changes: 135 additions & 0 deletions accounts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
require 'csv'

module Bank

class Account
attr_accessor :id, :balance, :opendate, :transaction_fee, :balance_min,
:withdrawl_bal_min

def initialize(id, balance, opendate)

@id = id
@balance = balance
@opendate = opendate
@transaction_fee = 0
@balance_min = 0
@withdrawl_bal_min = 0

unless @balance.is_a?(Integer) && @balance >= @balance_min
raise ArgumentError.new("New accounts must begin with a balance of $#{@balance_min} or more.")
end

end

def self.all
all_accts = CSV.read("./support/accounts.csv")
all_accts.each do |n|
n=0
id = all_accts[n][0].to_i
bal = all_accts[n][1].to_i
date = all_accts[2]
Bank::Account.new(id, bal, date)
end
end

def self.find(id_num)
id_num=id_num.to_s

all_accts = CSV.read("./support/accounts.csv")

all_accts.length.times do |n|
if all_accts[n].include?"#{id_num}"
id = all_accts[n][0].to_i
bal = all_accts[n][1].to_i
date = all_accts[n][2]
return Bank::Account.new(id, bal, date)
else
return nil
end
end
end

def withdraw(amount)
@amount = amount + @transaction_fee

if @balance - @amount < @withdrawl_bal_min
puts "Withdrawal Failure. Insufficient Funds. Your current balance is $#{@balance}."
return @balance
elsif @balance - @amount >= @withdrawl_bal_min
@balance = @balance - @amount
puts "Withdrawal processed. Your current balance is: $#{@balance}."
return @balance
end
end

def deposit(amount)
@amount = amount
@balance = @balance + @amount
return "Deposit processed. Your current balance is $#{@balance}."
end

def check_balance
return "Your current balance is $#{@balance}."
end
end

class SavingsAccount < Account

def initialize(id, balance, opendate)
super
@transaction_fee = 2
@balance_min = 10
@withdrawl_bal_min = 10

unless @balance.is_a?(Integer) && @balance >= @balance_min
raise ArgumentError.new("New accounts must begin with a balance of $#{@balance_min} or more.")
end

end

def add_interest(rate)
interest = @balance * rate/100
@balance = @balance + interest
puts "$#{interest} in interest added."
return interest
end

end

class CheckingAccount < Account
def initialize(id, balance, opendate)
super
@transaction_fee = 1
@balance_min = 0
@withdrawl_bal_min = 0
@checknum = 3
@check_bal_min = -10
@no_checks_fee = 2

unless @balance.is_a?(Integer) && @balance >= @balance_min
raise ArgumentError.new("New accounts must begin with a balance of $#{@balance_min} or more.")
end
end

def withdraw_using_check(amount)
if @balance - amount >= @check_bal_min && @checknum > 0
@balance = @balance - amount
@checknum = @checknum - 1
return "Check Withdrawl Processed. Your current balance is $#{@balance}."
elsif @balance - amount >= @check_bal_min && @checknum <= 0
@balance = @balance - (amount + @no_checks_fee)
@checknum = @checknum - 1
return "Check Withdrawl Processed. No-Checks Fee Incured." +
" Your current balance is $#{@balance}."
else
return "Check Withdrawal Failure. Insufficient Funds. Your current balance is $#{@balance}."
end
end

def reset_checks
return @checknum = 3
end

end

end