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

Jackie - Bank Account #33

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
18657e3
created initial structure of module and class
jackiewatanabe Feb 21, 2017
49f6f01
initialized with ID and initial balance
jackiewatanabe Feb 21, 2017
26b1e13
added withdraw method
jackiewatanabe Feb 21, 2017
22f4fcf
added deposit method
jackiewatanabe Feb 21, 2017
8d3b6de
added balance attr_reader so balance can be accessed any time
jackiewatanabe Feb 21, 2017
abfe8f3
updated attr_reader to go inside class Account
jackiewatanabe Feb 21, 2017
69429f1
added if/else statement in initialize to make sure initial balance is…
jackiewatanabe Feb 21, 2017
16af257
updated if/else statement to include initial balances of 0
jackiewatanabe Feb 21, 2017
150a523
added :id as a reader attribute
jackiewatanabe Feb 21, 2017
09f980a
added start and update balance local variables in withdraw method
jackiewatanabe Feb 22, 2017
ff4a411
added conditional to account for a withdraw amount that's negative
jackiewatanabe Feb 22, 2017
8928a43
added conditional to deposit method to require amount greater than ze…
jackiewatanabe Feb 22, 2017
52127dd
created an Owner class that takes in user info hashes
jackiewatanabe Feb 22, 2017
c5eda71
added test for initializing owner info
jackiewatanabe Feb 22, 2017
5641ef2
created Accounts.all class method and updated spec file to check for …
jackiewatanabe Feb 22, 2017
d8d361e
added test to check if eveverything in Array is an Account. Also crea…
jackiewatanabe Feb 23, 2017
78ec7a3
added tests to check ID/balance of first and last elements
jackiewatanabe Feb 23, 2017
f680527
created separate it/do's for each test
jackiewatanabe Feb 23, 2017
d6a10e4
created Account.find class method and set up test to ensure it return…
jackiewatanabe Feb 23, 2017
461974a
added tests to ensure .find class method can find the first and last …
jackiewatanabe Feb 23, 2017
760a46b
created test to check for accounts that don't exist and added code in…
jackiewatanabe Feb 23, 2017
1b8ec98
refactored .find class method to get rid of if/else when raising argu…
jackiewatanabe Feb 23, 2017
4efca9d
refactored code in initialize, withdraw, and deposit methods to get r…
jackiewatanabe Feb 23, 2017
21b764f
refactored specs code to get rid of unnecessary variables, instead us…
jackiewatanabe Feb 23, 2017
bc5e8ca
refactored code back to add variable @account_array set to Bank::Acco…
jackiewatanabe Feb 23, 2017
b034bd1
created class files for SavingsAccount and CheckingAccount
jackiewatanabe Feb 23, 2017
240f03e
changed file name to savings_account.rb and added initialize super
jackiewatanabe Feb 24, 2017
e9b3eb7
added 'require_relative 'account'' and also added conditionals and su…
jackiewatanabe Feb 24, 2017
2b8a2b8
adjusted withdraw method to account for withdrawals that will put acc…
jackiewatanabe Feb 24, 2017
352a576
added add_interest method to SavingsAccount and created test
jackiewatanabe Feb 24, 2017
f06688f
restructured add_interest rate and test to only show interest rate
jackiewatanabe Feb 24, 2017
ec2bcdf
adjusted test to check for only interest added on add_interest method
jackiewatanabe Feb 24, 2017
62f197a
created test to make sure add_interest updates balance with the calcu…
jackiewatanabe Feb 24, 2017
945477b
created CheckingAccount subclass with updated withdraw method. Added …
jackiewatanabe Feb 24, 2017
fa780e1
added test to make sure balance is not modified if fee would put it n…
jackiewatanabe Feb 24, 2017
4dd4b1c
wrote test to check if withdraw_using check reduces balance. Added me…
jackiewatanabe Feb 24, 2017
826af7c
wrote test to make sure withdraw_check method returns modified balanc…
jackiewatanabe Feb 24, 2017
2376c12
created test to make sure method allows withdrawing checks that puts …
jackiewatanabe Feb 24, 2017
4f7eff0
added test to see if method outputs warning if account goes below neg…
jackiewatanabe Feb 24, 2017
b1fbb50
added test and code to make sure check is a positive number
jackiewatanabe Feb 24, 2017
16f2c49
created tests to allow three free checks and then apply 2 dollar fee …
jackiewatanabe Feb 24, 2017
87242c6
created tests to check reset checks method. created method to reset c…
jackiewatanabe Feb 24, 2017
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
94 changes: 94 additions & 0 deletions lib/account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
require 'csv'

module Bank

class Account

attr_reader :id, :balance, :open_date

def initialize(id, balance, open_date = nil)
@id = id
raise ArgumentError.new "The initial balance must not be a negative number" if balance < 0

@balance = balance



# raise ArgumentError.new("The initial balance must not be a negative number") if balance < 0
#
# @id = id
# @balance = balance

# owner1 = Bank::Owner.new(owner)

# @owner = owner
# @account = Accounts.all
# @owner = Bank::Owner.new(owner_info_hash)
# @owner_name = owner1.name


end

def self.all
accounts = []
CSV.open("../support/accounts.csv").each do |line|
id = line[0]
balance = line[1].to_i
open_date = line[2]

new_account = Account.new(id, balance, open_date)
accounts << new_account
# accounts[ line[0] ] = line[1..-1]
# puts line
# accounts[line[0]] = line[1..-1]

end
return accounts
end


def self.find(search_id)
# new_search = Account.all
match = nil

Bank::Account.all.each do |account|
if account.id == search_id
match = search_id
break
else
match = nil
end
end

raise ArgumentError.new("There are no accounts with that ID") if match == nil

return match


end

def withdraw(money_to_withdraw)
raise ArgumentError.new "The amount to withdraw must be greater than zero" if money_to_withdraw < 0 #requires positive withdrawal amount
if money_to_withdraw > @balance #requires withdrawal amount less than balance
puts "Amount to withdraw must be greater than balance"
else
@balance -= money_to_withdraw
end
return @balance
end

def deposit(money_to_deposit)
raise ArgumentError.new "The deposit amount must be greater than zero" if money_to_deposit < 0
# start_balance = @balance
# updated_balance = start_balance + money_to_deposit
@balance += money_to_deposit

end

# def add_owner
#
# end

end

end
64 changes: 64 additions & 0 deletions lib/checking_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
require_relative 'account'
require 'csv'

module Bank
class CheckingAccount < Account
attr_reader :check_count
def initialize(id, balance, open_date = nil)
super
@check_count = 0
end


def withdraw(withdrawal_amount)
if @balance - (withdrawal_amount + 1) < 0
puts "Warning! This withdrawal will cause you to overdraft!"
# return @balance
else
super(withdrawal_amount)
@balance -= 1.0
end
return @balance

end

def withdraw_using_check(check)
raise ArgumentError.new("Check cannot be a negative amount") if check < 0
if @check_count < 3
if (@balance - check) < -10
puts "Warning! This withdrawal will cause you to be under more than ten dollars!"
# return @balance

return @balance
else
@check_count += 1
@balance -= check
end

else
if (@balance - (check + 2.0)) < -10
puts "Warning! This withdrawal will cause you to be under more than ten dollars!"
return @balance
else
@check_count += 1
@balance = @balance - check - 2.0
end
end
end

def reset_checks
@check_count = 0
end

end
end

# 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
# #reset_checks: Resets the number of checks used to zero
18 changes: 18 additions & 0 deletions lib/owner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Bank

class Owner

attr_reader :name, :address, :account_type

def initialize(owner_info_hash)
@name = owner_info_hash[:name]
@address = owner_info_hash[:address]
@account_type = owner_info_hash[:account_type]
end
end

end


# Create an Owner class which will store information about those who own the Accounts.
# This should have info like name and address and any other identifying information that an account owner would have.
46 changes: 46 additions & 0 deletions lib/savings_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require_relative 'account'
require 'csv'

module Bank

class SavingsAccount < Account
attr_accessor :calculated_interest

def initialize(id, balance, open_date = nil)
super(id, balance, open_date = nil)
raise ArgumentError.new "The initial balance must not be less than 10" if balance < 10
@calculated_interest = nil
end

def withdraw(money_to_withdraw)
if @balance - (money_to_withdraw + 2) < 10
puts "Warning! This withdrawal will put you under the $10 account minimum!"
return @balance
else
super(money_to_withdraw)
return @balance -= 2.0
end
end

def add_interest(rate)
raise ArgumentError.new("interest rate must be greater than 0") if rate < 0
@calculated_interest = balance * rate / 100
@balance += @calculated_interest
return @calculated_interest

end

# def calculate_interest(rate)
# @calculated_interest = balance * rate / 100
# end

end
end


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