Skip to content
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
16 changes: 16 additions & 0 deletions dummy_file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# die.rb
module Bank

class Die
def initialize
end

def roll
return rand(1..6)
end

end
end

die = Die.new
puts die
70 changes: 70 additions & 0 deletions lib/account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
require 'csv'
require 'date'
require_relative 'owner'

module Bank
class Account
attr_reader :id, :balance , :open_date
attr_accessor :owner

@@all_accounts = []

def initialize(id, balance, open_date='2010-12-21 12:21:12 -0800')
raise ArgumentError.new("balance must be >= 0") if balance < 0
@id = id
@balance = balance
@open_date = open_date
@@all_accounts << self
end


def withdraw(withdrawal_amount)
raise ArgumentError.new("Withdrawal amount must be >= 0") if withdrawal_amount < 0
if withdrawal_amount > @balance
puts "You don't have enough in your account to withdraw that amount!"
else @balance -= withdrawal_amount
end
return @balance
end

def deposit(deposit_amount)
raise ArgumentError.new("Deposit amount must be >= 0") if deposit_amount < 0
@balance += deposit_amount
end

def self.reset_all_accounts_for_test
@@all_accounts = []
end

def self.read_csv
CSV.open("./support/accounts.csv").each do |acct|
acct_id = acct[0].to_i
acct_balance_dollars = acct[1].to_i / 100.0
acct_date = DateTime.parse(acct[2])
self.new(acct_id, acct_balance_dollars, acct_date)
end
end

def self.all
@@all_accounts
end

def self.find(id)
found_accounts = @@all_accounts.select {|acct| acct.id == id}
raise ArgumentError.new("That account doesn't exist!") if found_accounts[0]==nil
return found_accounts[0]
end

def self.add_owners_to_all_accounts
self.read_csv
Bank::Owner.read_csv

account_owners_csv = CSV.open("./support/account_owners.csv")
account_owners_csv.each {|pair|
account_id = pair[0].to_i
owner_id = pair[1].to_i
self.find(account_id).owner = Bank::Owner.find(owner_id)
}
end
end
end
46 changes: 46 additions & 0 deletions lib/checking_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require 'csv'
require 'date'
require_relative 'account'


module Bank

class CheckingAccount < Account

def initialize(id, balance, open_date='2010-12-21 12:21:12 -0800')
super(id, balance, open_date)
@free_checks_used = 0
end

def withdraw(withdrawal_amount)
raise ArgumentError.new("Withdrawal amount must be >= 0") if withdrawal_amount < 0
if withdrawal_amount > (@balance - 1)
puts "You don't have enough in your account to withdraw that amount!"
else @balance -= (withdrawal_amount + 1)
end
return @balance
end

def withdraw_using_check(withdrawal_amount)
raise ArgumentError.new("Withdrawal amount must be >= 0") if withdrawal_amount < 0

if @free_checks_used < 3
if withdrawal_amount > (@balance + 10)
puts "You don't have enough in your account to withdraw that amount, even with your $10 overdraft allowance!"
else @balance -= (withdrawal_amount)
@free_checks_used += 1
end
else
if withdrawal_amount > (@balance + 10 - 2)
puts "You don't have enough in your account to withdraw that amount and pay the check fee, even with your $10 overdraft allowance!"
else @balance -= (withdrawal_amount + 2)
end
end
return @balance
end

def reset_checks
@free_checks_used = 0
end
end
end
69 changes: 69 additions & 0 deletions lib/money_market_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
require 'csv'
require 'date'
require_relative 'account'

module Bank

class MoneyMarketAccount < Account


def initialize(id, balance, open_date='2010-12-21 12:21:12 -0800')
super(id, balance, open_date)
raise ArgumentError.new("balance must be >= 10,000") if balance < 10000
@transactions_used = 0
@transactions_allowed = true
end

def transaction_count
@transactions_used
end

def reset_transactions
@transactions_used = 0
end

def withdraw(withdrawal_amount)
if @transactions_allowed

if @transactions_used < 6
@transactions_used += 1
super(withdrawal_amount)
if @balance < 10000
@balance -= 100
@transactions_allowed = false
puts "Your account is now too low. You must make a deposit to allow more transactions."
return @balance
end
else
puts "You have already used all your transactions this month."
@balance
end
else
puts "Withdrawal not allowed. Account balance is too low. You must make a deposit to re-enable transactions. "
return @balance
end
end

def deposit(deposit_amount)
if !(@transactions_allowed)
@transactions_allowed = true
super(deposit_amount)
else
if @transactions_used < 6
@transactions_used += 1
super(deposit_amount)
else puts "You have already used all your transactions this month."
@balance
end
end
end

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

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

module Bank
class Owner
attr_reader :id, :last_name, :first_name, :street_address, :city, :state

@@all_owners = []

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


def self.reset_all_owners_for_test
@@all_owners = []
end

def self.read_csv
CSV.open("./support/owners.csv").each do |owner|
owner_id = owner[0].to_i
owner_last_name = owner[1].to_s
owner_first_name = owner[2].to_s
owner_street_address = owner[3].to_s
owner_city = owner[4].to_s
owner_state = owner[5].to_s
self.new(id:owner_id, last_name:owner_last_name, first_name:owner_first_name, street_address:owner_street_address, city:owner_city, state:owner_state)
end
end

def self.all
@@all_owners
end

def self.find(id)
found_accounts = @@all_owners.select {|owner| owner.id.to_i == id.to_i}
raise ArgumentError.new("That account doesn't exist!") if found_accounts[0]==nil
return found_accounts[0]
end
end
end
30 changes: 30 additions & 0 deletions lib/savings_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require 'csv'
require 'date'
require_relative 'account'


module Bank
class SavingsAccount < Account

def initialize(id, balance, open_date='2010-12-21 12:21:12 -0800')
super(id, balance, open_date)
raise ArgumentError.new("balance must be >= 10") if balance < 10
end

def withdraw(withdrawal_amount)
raise ArgumentError.new("Withdrawal amount must be >= 0") if withdrawal_amount < 0
if withdrawal_amount > (@balance - 12)
puts "You don't have enough in your account to withdraw that amount!"
else @balance -= (withdrawal_amount + 2)
end
return @balance
end

def add_interest(rate)
raise ArgumentError.new("Interest rate must be > 0") if rate <= 0
interest = @balance * (rate/100)
@balance += interest
return interest
end
end
end
Loading