diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..5008ddfc Binary files /dev/null and b/.DS_Store differ diff --git a/MoneyMarketAccount.rb b/MoneyMarketAccount.rb new file mode 100644 index 00000000..659e1128 --- /dev/null +++ b/MoneyMarketAccount.rb @@ -0,0 +1,38 @@ +module Bank + + class MoneyMarketAccount < SavingsAccount + attr_reader :transactions + + def initialize(id, balance, open_date) + @account_id = id.to_i + @balance = balance.to_i * 100 + @open_date = open_date + @mm_account_fee = 0 + @transactions = 6 + @act_withdraw_fee = 100_00 + @mm_min_balance = 10_000_00 + @min_balance = 0 + + if @balance < @mm_min_balance + raise StandardError, "You cannot open an account with that little money." + end + + end + + def withdraw(amount) + if @balance >= @mm_min_balance + if @transactions > 0 + super + @transactions -= 1 + end + else + puts "You must deposit at least #{@mm_min_balance - @balance} before you can withdraw any more." + end + end + + def reset_transactions + @transactions = 6 + end + + end +end diff --git a/README.md b/README.md index 25fd4d2a..b6e5c7b2 100644 --- a/README.md +++ b/README.md @@ -73,24 +73,23 @@ Create an `Account` class which should have the following functionality: **Account ID** - (Fixnum) a unique identifier corresponding to an account **Owner ID** - (Fixnum) a unique identifier corresponding to an owner - diff --git a/account.rb b/account.rb new file mode 100644 index 00000000..8befe651 --- /dev/null +++ b/account.rb @@ -0,0 +1,93 @@ +module Bank + + class Account + attr_reader :balance, :account_id, :owner, :all_accounts, :open_date + + def initialize(id, balance, open_date) + + @account_id = id + @balance = balance * 100 + @open_date = open_date + @min_balance = 0 + @act_withdraw_fee = 0 + + if balance.to_i < @min_balance + raise StandardError, "You cannot open an account with that little money." + end + end + + def withdraw(withdraw_amt) + withdraw_to_cents = withdraw_amt * 100 + + if (@balance - withdraw_to_cents) < (@min_balance + @act_withdraw_fee) + puts "You cannot withdraw that much. Your current balance is #{@balance} cents" + elsif @mm_min_balance > 0 + if (@balance - withdraw_to_cents) > (-@mm_min_balance) + @balance -= withdraw_to_cents + puts "Your account balance is now #{@balance} cents." + else + @balance -= (withdraw_to_cents + @act_withdraw_fee) + puts "You've withdrawn your account below #{@mm_min_balance}, so you'll be charged #{@act_withdraw_fee} cents." + puts "You must deposit enough for your account to be above #{@mm_min_balance} cents before you can withdraw any more." + puts "Your new balance is #{@balance} cents." + end + else + @balance -= (withdraw_to_cents + @act_withdraw_fee) + puts "Your account balance is now #{@balance} cents." + end + end + + def deposit(deposit_amt) + deposit_to_cents = deposit_amt * 100 + + if @mm_min_balance > 0 + if @balance >= 10_000_00 + @balance += deposit_to_cents + puts "Your previous account balance was #{@balance - deposit_to_cents} cents." + puts "It is now #{@balance} cents." + @transactions -= 1 + elsif @balance + deposit_to_cents >= 10_000_00 + @balance += deposit_to_cents + puts "Your previous account balance was #{@balance - deposit_to_cents} cents." + puts "It is now #{@balance} cents." + else + @balance += deposit_to_cents + @transactions -= 1 + puts "Your previous account balance was #{@balance - deposit_to_cents} cents." + puts "It is now #{@balance} cents." + puts "You still need to deposit #{@mm_min_balance - @balance} before you can withdraw any more." + end + + else + @balance += deposit_to_cents + puts "Your previous account balance was #{@balance - deposit_to_cents} cents." + puts "It is now #{@balance} cents." + end + end + + def show_balance + puts "Your current balance is #{@balance} cents" + end + + def assign_owner(first_name, last_name, address) + @owner = Bank::Owner.new(first_name, last_name, address) + end + + def self.all + @all_accounts = [] + + CSV.read("./support/accounts.csv").each do |line| + y = Bank::Account.new(line[0].to_i, line[1].to_i, line[2]) + @all_accounts.push(y) + end + + return @all_accounts + end + + def self.find(id) + Bank::Account.all.find do |account_instance| + account_instance.account_id == id + end + end + end +end diff --git a/bankaccount.rb b/bankaccount.rb index cf02bacd..a69dbe1e 100644 --- a/bankaccount.rb +++ b/bankaccount.rb @@ -1,60 +1,122 @@ +require "csv" +require "pry" + module Bank class Owner - attr_reader :first_name, :last_name, :address - - def initialize(first_name, last_name, address) + attr_reader :first_name, :last_name, :street_address, :owner_id + def initialize(owner_id, last_name, first_name, street_address, city, state) + @owner_id = id @first_name = first_name @last_name = last_name - @address = address + @street_address = street_address + @city = city + @state = state + end + + def self.all + all_owners = [] + + CSV.read("./support/owners.csv").each do |line| + y = Bank::Owner.new(line[0].to_i, line[1], line[2], line[3], line[4], line[5]) + all_owners.push(y) + end + + return all_owners end + def self.find(id) + Bank::Owner.all.find do |account_instance| + account_instance.owner_id == id + end + end end class Account - attr_reader :balance, :id, :owner + attr_reader :balance, :account_id, :owner, :all_accounts, :open_date - def initialize(id, initial_balance) - # another way of generating an error if user starts with negative balance - # while initial_balance < 0 - # puts "You cannot open an account in debt." - # puts "Please enter a new opening balance: " - # initial_balance = gets.chomp.to_i - # end + def initialize(id, balance, open_date) - if initial_balance < 0 + if balance.to_i < 0 raise StandardError, "You cannot open an account in debt." end - @balance = initial_balance - @id = id + @account_id = id + @balance = balance + @open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %Q") end def withdraw(withdraw_amt) while (@balance - withdraw_amt) < 0 - puts "You cannot overdraft your account. Your current balance is $#{@balance}" + puts "You cannot overdraft your account. Your current balance is #{@balance} cents" puts "Please enter a new withdrawl amount: " withdraw_amt = gets.chomp.to_i end @balance -= withdraw_amt - puts "Your previous account balance was $#{@balance + withdraw_amt}." - puts "It is now $#{@balance}." + puts "Your previous account balance was #{@balance + withdraw_amt} cents." + puts "It is now #{@balance} cents." end def deposit(deposit_amt) @balance += deposit_amt - puts "Your previous account balance was $#{@balance - deposit_amt}." - puts "It is now $#{@balance}." + puts "Your previous account balance was #{@balance - deposit_amt} cents." + puts "It is now #{@balance} cents." end def show_balance - puts "Your current balance is $#{@balance}" + puts "Your current balance is #{@balance} cents" end def assign_owner(first_name, last_name, address) @owner = Bank::Owner.new(first_name, last_name, address) end + + def self.all + @all_accounts = [] + + CSV.read("./support/accounts.csv").each do |line| + y = Bank::Account.new(line[0].to_i, line[1].to_i, line[2]) + @all_accounts.push(y) + end + + return @all_accounts + end + + def self.find(id) + Bank::Account.all.find do |account_instance| + account_instance.account_id == id + end + end + + # working on this still + # def self.match_owner + # Bank::Account.all + # + # CSV.read("./support/accounts.csv").each do |line| + # binding.pry + # account = CSV.read("./support/account_owners.csv").find(line[0]) + # owner = CSV.read("./support/owners.csv").find(account[1]) + # Bank::Owner.new(owner) + # end + + # take the account id (line[0] in each loop) and find which owners_id within account_owners.csv it shares, + # then take that owners_id, switch over to the owners.cvs, and initialize a new Owner based on that + + # end + end + + class SavingsAccount < Account + def initialize(id, balance, open_date) + super + if balance.to_i < 0 + raise StandardError, "You cannot open an account with less than $10." + end + end + + end + + end diff --git a/bankaccountw3.rb b/bankaccountw3.rb new file mode 100644 index 00000000..55e34206 --- /dev/null +++ b/bankaccountw3.rb @@ -0,0 +1,15 @@ +require "csv" +require "pry" + +require "./account.rb" +require "./savings.rb" +require "./owner.rb" +require "./checkingaccount.rb" +require "./MoneyMarketAccount.rb" + + +# testing to see if they work: +# Account class: y +# savings: y +# checking: y +# Money Market class: this one still has issues :( diff --git a/checkingaccount b/checkingaccount new file mode 100644 index 00000000..e69de29b diff --git a/checkingaccount.rb b/checkingaccount.rb new file mode 100644 index 00000000..ee813588 --- /dev/null +++ b/checkingaccount.rb @@ -0,0 +1,39 @@ +module Bank + + class CheckingAccount < Account + attr_reader :free_checks + + def initialize(id, balance, open_date) + super + + @act_withdraw_fee = 100 + @free_checks = 3 + end + + def withdraw(withdraw_amt) + super + end + + def withdraw_using_check(amount) + withdraw_to_cents = amount * 100 + + if (@balance - withdraw_to_cents) < (@min_balance - 1000) + puts "You cannot withdraw that much. Your current balance is #{@balance} cents" + elsif @free_checks > 0 + @balance -= withdraw_to_cents + @free_checks -= 1 + puts "Your account balance is now #{@balance} cents." + else + @balance -= (withdraw_to_cents + 200) + puts "You already used up your free checks for this month, so you've been charged an extra $2." + puts "Your new balance is #{@balance} cents." + end + end + + def reset_checks + @free_checks = 3 + end + + + end +end diff --git a/owner.rb b/owner.rb new file mode 100644 index 00000000..65efd6f0 --- /dev/null +++ b/owner.rb @@ -0,0 +1,33 @@ +# figure out how to add to Bank module +module Bank + + class Owner + attr_reader :first_name, :last_name, :street_address, :owner_id + + def initialize(owner_id, last_name, first_name, street_address, city, state) + @owner_id = owner_id + @first_name = first_name + @last_name = last_name + @street_address = street_address + @city = city + @state = state + end + + def self.all + all_owners = [] + + CSV.read("./support/owners.csv").each do |line| + y = Bank::Owner.new(line[0].to_i, line[1], line[2], line[3], line[4], line[5]) + all_owners.push(y) + end + + return all_owners + end + + def self.find(id) + Bank::Owner.all.find do |account_instance| + account_instance.owner_id == id + end + end + end +end diff --git a/savings.rb b/savings.rb new file mode 100644 index 00000000..3f5f7422 --- /dev/null +++ b/savings.rb @@ -0,0 +1,23 @@ +module Bank + + class SavingsAccount < Account + def initialize(id, balance, open_date) + super + + @min_balance = 10_00 + @act_withdraw_fee = 200 + + if @balance < @min_balance + raise StandardError, "You cannot open an account with less than $10." + end + end + + def add_interest(rate) + interest = @balance * (rate/100) + @balance += interest + + puts "You've earned #{interest} cents in interest, and your new balance is #{@balance}" + end + + end +end