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/bank.rb b/bank.rb new file mode 100644 index 00000000..68173bfd --- /dev/null +++ b/bank.rb @@ -0,0 +1,18 @@ +require "pry" +require "./bankaccounts.rb" +require "./savings.rb" +require "./checking.rb" +require "./moneymarket.rb" + + + +# Savings Account tests +# s = Bank::SavingsAccount.new("1212","10000","1999-03-27 11:30:09 -0800") +# s2 = Bank::SavingsAccount.new("4444","99999999","1999-03-27 11:30:09 -0800") + +# Checking Account tests +# c = Bank::CheckingAccount.new("5555","10000","1999-03-27 11:30:09 -0800") + +# MoneyMarketAccount tests +# m = Bank::MoneyMarketAccount.new("666","10000000","1999-03-27 11:30:09 -0800") +# m2 = Bank::MoneyMarketAccount.new("777","500","1999-03-27 11:30:09 -0800") # this should fail diff --git a/bankaccounts.rb b/bankaccounts.rb index 22a6157a..6a589364 100644 --- a/bankaccounts.rb +++ b/bankaccounts.rb @@ -6,24 +6,23 @@ class Account attr_reader :id, :balance, :open_date attr_accessor :owner - def initialize(id, initial_balance, open_date, owner = nil) + def initialize(id, initial_balance, open_date) @balance = initial_balance.to_i if initial_balance.to_i < 0 raise ArgumentError, "Invalid Balance: Balance may not be negative." end @id = id.to_i @open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %z") - @owner = owner + @owner = nil end def withdraw(withdraw_amount) if withdraw_amount > @balance puts "Warning: Can not withdraw more than is in account. Transaction terminated." - return @balance else @balance -= withdraw_amount - return @balance end + return @balance end def deposit(deposit_amount) @@ -32,12 +31,9 @@ def deposit(deposit_amount) end def self.all - accounts_array = [] - CSV.read('support/accounts.csv').map do |account| - x = Bank::Account.new(account[0],account[1],account[2]) - accounts_array.push(x) - end - return accounts_array + accounts_array = CSV.read('support/accounts.csv').map do |account| + Bank::Account.new(account[0],account[1],account[2]) + end end def self.find(id) @@ -88,5 +84,4 @@ def self.find(id) end end - end diff --git a/checking.rb b/checking.rb new file mode 100644 index 00000000..ff545cbe --- /dev/null +++ b/checking.rb @@ -0,0 +1,44 @@ + +module Bank + class CheckingAccount < Account + attr_reader :checks_used + + def initialize(id, initial_balance, open_date) + super(id, initial_balance, open_date) + @checks_used = 0 + end + + def withdraw(withdraw_amount) + fee = 100 + if withdraw_amount > (@balance + 100) + puts "Warning: Can not withdraw more than is in account. Transaction terminated." + return @balance + else + @balance -= (withdraw_amount + fee) + puts "There is a transaction fee of $1.00." + return @balance + end + end + + def withdraw_using_check(withdraw_amount) + fee = 200 + if withdraw_amount > (@balance + 1000) + puts "Warning: Can not overdraft account more than $10.00. Transaction terminated." + elsif @checks_used < 3 + @balance -= withdraw_amount + @checks_used += 1 + else + puts "You have used up your 3 free check withdrawals this month." + puts "There is a transaction fee of $2.00" + @balance -= (withdraw_amount + fee) + @checks_used += 1 + end + return @balance + end + + def reset_checks + @checks_used = 0 + end + + end +end diff --git a/moneymarket.rb b/moneymarket.rb new file mode 100644 index 00000000..c9ae35e1 --- /dev/null +++ b/moneymarket.rb @@ -0,0 +1,60 @@ +module Bank + class MoneyMarketAccount < SavingsAccount + MAX_TRANSACTIONS = 6 + def initialize(id, initial_balance, open_date) + super(id, initial_balance, open_date) + @current_transactions = 0 + @transaction_ban = false + @min_balance = 1000000 + if initial_balance.to_i < @min_balance + raise ArgumentError, "Invalid Balance: Balance may not be less than $10,000.00" + end + end + + def withdraw(withdraw_amount) + fee = 10000 + if @current_transactions >= MAX_TRANSACTIONS + puts "You have already used up your maximum amount of transactions this month. Transaction terminated." + elsif @transaction_ban == true + puts "Transaction denied. Balance must be increased with a deposit before further transactions." + elsif (@balance - withdraw_amount) < @min_balance + puts "A $100.00 fee will be incurred for balance going below $10,000.00." + puts "No more transactions allowed until the balance is increased." + @transaction_ban = true + @balance -= (withdraw_amount + fee) + @current_transactions += 1 + else + @balance -= withdraw_amount + @current_transactions += 1 + end + return @balance + end + + def deposit(deposit_amount) + if @balance < @min_balance + @balance += deposit_amount + if @balance > @min_balance + @transaction_ban = false + end + else + @balance += deposit_amount + @current_transactions += 1 + end + return @balance + end + + def add_interest(rate) + if @transaction_ban == true + puts "Transaction's banned until balance is at a minimum of $10,000." + else + super(rate) + end + end + + def reset_transactions + @current_transactions = 0 + end + + + end +end diff --git a/savings.rb b/savings.rb new file mode 100644 index 00000000..797b2228 --- /dev/null +++ b/savings.rb @@ -0,0 +1,31 @@ +module Bank + + class SavingsAccount < Account + FEE = 200 + def initialize(id, initial_balance, open_date) + super(id, initial_balance, open_date) + @min_balance = 1000 + if initial_balance.to_i < @min_balance + raise ArgumentError, "Invalid Balance: Balance may not be less than $10.00" + end + end + + def withdraw(withdraw_amount) + if (@balance - withdraw_amount) < @min_balance + puts "Warning: Balance may not go under $10.00. Transaction terminated." + else + @balance -= (withdraw_amount + FEE) + puts "There is a transaction fee of $#{FEE/100}.00." + end + return @balance + end + + def add_interest(rate) + interest = @balance * (rate.to_f / 100) + @balance += interest + return interest + end + + end + +end