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
114 changes: 114 additions & 0 deletions lib/account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
require 'csv'
require 'ap'
module Bank
class Account

attr_reader :id, :balance, :open_date
def initialize(id, balance, open_date ="")
raise ArgumentError.new("balance must be >= 0") if balance < 0
@id = id
@balance = balance
@open_date = open_date

end

@@account_all = []

@@csv = []
CSV.read("./support/accounts.csv").each do |account|
@@csv << {id: account[0].to_i, balance: account[1].to_i, open_date: account[2]}
end


def self.csv
return @@csv
end

@@csv.each do |account|
@@account_all << self.new(account[:id].to_i, account[:balance].to_i, account[:open_date])
end

def self.all
return @@account_all
end


def self.find(entered_id)
@@account_all.each do |account|
if account.id == entered_id
return account
end
end
raise ArgumentError.new "Entered ID doesn't exist"
end


def withdraw(amount)
if amount < 0
raise ArgumentError.new "Negative amount entered for withdrawal"
else
new_balance = @balance - amount
if new_balance < 0
puts "Withdrawal amount greater than the current balance"
@balance = @balance
else
@balance = new_balance
end
end
end

def deposit(amount)
if amount < 0
raise ArgumentError.new "Minus amount deposited"
else
new_balance = @balance + amount
@balance = new_balance
end

end

end

# class Owner
# attr_reader :last_name, :first_name, :address
# def initialize(last_name, first_name, address)
# @last_name = last_name
# @first_name = first_name
# @address = address
# end
#
# @@owner = []
# @@csv = []
# # CSV.read("../support/accounts.csv").each do |account|
# # @@csv << {id: account[0].to_i, balance: account[1].to_i, open_date: account[2]}
# # end
# CSV.read("../support/owners.csv").each do |owner|
# @@owner << {last_name: owner[1], first_name: owner[2], address: owner[3]}
# end
# # ap @@owner[0].last_name
# # puts Bank::Account.csv
# # puts @@owner
#
#
# def self.merge_info
# n = 0
# @@owner.length.times do |n|
# Bank::Account.csv[n].merge!(@@owner[n])
# n +=1
# end
# end
#
#
#
#
# end




end

# a = Bank::Account.new(12334, 5000)
# puts a.id
# Bank::Owner.merge_info
# ap Bank::Account.csv
18 changes: 18 additions & 0 deletions lib/account_hyunji.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Bank
class Account
attr_reader :balance, :id
def initialize(id, initial_balance)
@balance = initial_balance
@id = id
if @balance < 0
raise ArgumentError.new "Initial balance is negative"
end
end

def withdraw(amount)
end

def deposit(amount)
end
end
end
61 changes: 61 additions & 0 deletions lib/checking_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
require_relative 'account'

module Bank
class CheckingAccount < Bank::Account
# attr_reader :id, :balance
attr_accessor :num_withdrawal
def initialize(id, balance)
super(id, balance)
# @id = id
# @balance = balance
# raise ArgumentError.new("balance must be >= 10") if balance < 10
@num_withdrawal = 0
end

def withdraw(amount)
if @balance - (amount + 1) < 0
puts "balance must be greater than 0"
return @balance
else
return @balance = @balance - (amount + 1)
end
end

def withdraw_using_check(amount)
if amount < 0
puts "Withdrawl amount must be greater than 0"
else
if @balance - amount < -10
puts "balance must be greater than -10"
return @balance
else
if @num_withdrawal >= 3
return @balance = @balance - (amount + 2)
else
@num_withdrawal += 1
# puts @num_withdrawal
return @balance = @balance - amount
end
end
end
end

def reset_checks
@num_withdrawal = 0
return "reset"
end

end
end

# a = Bank::CheckingAccount.new(1234, 5000)
# a.withdraw_using_check(10)
# puts a.balance
# a.withdraw_using_check(10)
# puts a.balance
# a.withdraw_using_check(10)
# puts a.balance
# a.withdraw_using_check(10)
# puts a.balance

# puts Bank::CheckingAccount.new(1234, 5000)
89 changes: 89 additions & 0 deletions lib/money_market.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
require_relative 'account'

module Bank
class MoneyMarket < Bank::Account
attr_accessor :num_transaction
def initialize(id, balance)
super(id, balance)
@num_transaction = 0
raise ArgumentError.new("Balance cannot be less than $10,000") if @balance < 10000
end

def withdraw(amount)
if @num_transaction < 6
if (@balance - amount) < 10000
@num_transaction += 1
puts "Balance is lower than 10000. Charged $100 fee"
# puts @balance - (amount + 100)
@balance = @balance - (amount + 100)
else
@num_transaction += 1
@balance = (@balance - amount)
end
else
puts "Maximum Number of Transactions has reached."
return @balance
end
end

def deposit(amount)
if amount < 0
raise ArgumentError.new "Minus amount deposited"
else
if @num_transaction < 6
@balance = @balance + amount
@num_transaction += 1
else
if @balance < 10000
if (@balance + amount) > 10000
@balance = (@balance + amount)
@num_transaction = @num_transaction
puts "deposit balance< 10000 #{@num_transaction}"
else
puts "Maximum Number of Transactions has reached."
end
else
puts "Maximum Number of Transactions has reached."
end
end
end
end

def add_interest(rate)
if rate < 0
puts "Requires a positive rate"
else
interest = @balance * rate
@balance = @balance + (@balance * rate)
return interest
end
end

def reset_transactions
@num_transaction = 0
end



end
end


a = Bank::MoneyMarket.new(1, 10000)
a.deposit(30)
puts a.balance
a.deposit(30)
puts a.balance
a.deposit(30)
puts a.balance
a.withdraw(50)
puts a.balance
a.withdraw(50)
puts a.balance
a.withdraw(50)
puts a.balance
a.deposit(500)
puts a.balance
a.deposit(500)
puts a.balance
puts a.num_transaction
41 changes: 41 additions & 0 deletions lib/savings_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require_relative 'account'

module Bank
class SavingsAccount < Bank::Account
# attr_reader :id, :amount
def initialize(id, balance)
super(id, balance)
# @id = id
# @balance = balance
raise ArgumentError.new("balance must be greater than 10") if balance < 10
end

def withdraw(withdraw_amount)
if @balance - (withdraw_amount + 2) < 10
puts "balance must be >= 10"
return @balance
else
return @balance = @balance - (withdraw_amount + 2)
end
end

def add_interest(rate)
if rate < 0
puts "Requires a positive rate"
else
interest = @balance * rate
@balance = @balance + (@balance * rate)
return interest
end
end

# a = Bank::SavingsAccount.new(1223, 5000)
# puts a.withdraw(500)
# puts a.balance


end
end

# a = Bank::SavingsAccount.new(1000, 10000)
# puts a
16 changes: 16 additions & 0 deletions lib/test_super_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require_relative 'account'

module Bank
class Test < Bank::Account
def initialize(id, balance)
super(id, balance)
end

def deposit(amount)
super(amount)
@balance = @balance + 10
end
end
end
a = Bank::Test.new(1234, 5000)
puts a.deposit(50)
Loading