diff --git a/BankAccounts.rb b/BankAccounts.rb index 6294fed3..bd4adf04 100644 --- a/BankAccounts.rb +++ b/BankAccounts.rb @@ -5,6 +5,9 @@ module Bank class Account + MIN_BALANCE = 0 + FEE = 0 + attr_reader :balance, :owner, :account_id def initialize(account_id, initial_balance, open_date) @@ -14,8 +17,8 @@ def initialize(account_id, initial_balance, open_date) end def withdraw(amount) - if amount <= @balance - @balance -= amount + if amount <= @balance - self.class::MIN_BALANCE - self.class::FEE + @balance -= (amount + self.class::FEE) else puts "Your balance is #{@balance}. You cannot withdraw #{amount} at this time." return @balance @@ -27,8 +30,8 @@ def deposit(amount) end def check_initial_balance(initial_balance) - if initial_balance < 0 - raise ArgumentError.new("Your initial balance must be positive!") + if initial_balance < self.class::MIN_BALANCE + raise ArgumentError.new("Your initial balance must be more than #{self.class::MIN_BALANCE}!") else return initial_balance end diff --git a/CheckingAccount.rb b/CheckingAccount.rb new file mode 100644 index 00000000..2ed0a593 --- /dev/null +++ b/CheckingAccount.rb @@ -0,0 +1,36 @@ +module Bank + + class CheckingAccount < Account + + FEE = 100 + + def initialize (account_id, initial_balance, open_date) + super + @free_check = 3 + end + + def withdraw_using_check(amount) + if @free_check > 0 + check_fee = 0 + else + check_fee = 200 + end + + if (amount + check_fee) <= (@balance + 1000) + @balance -= (amount + check_fee) + @free_check -= 1 + else + puts "Your account cannot overdraft by more than 1000. Your balance is #{@balance} so you cannot write a check for #{amount} at this time." + end + return @balance + end + + def reset_checks + @free_check = 3 + end + + + + end + +end diff --git a/MoneyMarketAccount.rb b/MoneyMarketAccount.rb new file mode 100644 index 00000000..160eabb0 --- /dev/null +++ b/MoneyMarketAccount.rb @@ -0,0 +1,50 @@ +module Bank + + class MoneyMarketAccount < SavingsAccount + + MIN_BALANCE = 1000000 + + attr_reader :transaction_count + + def initialize (account_id, initial_balance, open_date) + super + @transaction_count = 0 + end + + def withdraw(amount) + if account_frozen? || transaction_count_exceeded? + return @balance + elsif amount <= @balance - self.class::MIN_BALANCE + @balance -= amount + else + @balance -= (amount + 10000) + end + @transaction_count += 1 + return @balance + end + + def deposit(amount) + if transaction_count_exceeded? + return @balance + elsif account_frozen? && (@balance + amount) >= self.class::MIN_BALANCE + else + @transaction_count += 1 + end + super + end + + def account_frozen? + @balance < self.class::MIN_BALANCE + end + + def transaction_count_exceeded? + @transaction_count >= 6 + end + + def reset_transactions + @transaction_count = 0 + 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/SavingsAccount.rb b/SavingsAccount.rb new file mode 100644 index 00000000..3cf69713 --- /dev/null +++ b/SavingsAccount.rb @@ -0,0 +1,21 @@ +module Bank + + class SavingsAccount < Account + + MIN_BALANCE = 1000 + FEE = 200 + + def initialize (account_id, initial_balance, open_date) + super + end + + def add_interest(rate) + interest = @balance * (rate/100) + @balance += interest + return interest + end + + + end + +end diff --git a/bank.rb b/bank.rb new file mode 100644 index 00000000..481c5ea8 --- /dev/null +++ b/bank.rb @@ -0,0 +1,4 @@ +require "./BankAccounts.rb" +require "./SavingsAccount.rb" +require "./CheckingAccount.rb" +require "./MoneyMarketAccount.rb"