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-accounts.rb b/bank-accounts.rb index 8068530b..34dc7eaa 100644 --- a/bank-accounts.rb +++ b/bank-accounts.rb @@ -6,13 +6,15 @@ module Bank class Account + @@min_balance = 0 + attr_reader :balance, :owner, :open_date, :ident - def initialize(ident, balance, open_date) + def initialize(ident, open_date, balance) @ident = ident - @balance = balance - raise ArgumentError.new("Your intial balance can't be negative") if balance < 0 @open_date = DateTime.strptime(open_date, '%Y-%m-%d %H:%M:%S %z') + @balance = balance + raise ArgumentError.new("Insufficient initial balance") if balance < @@min_balance end def self.all @@ -53,8 +55,8 @@ def assign_to_owner(person) # pass in an instance of Owner end def withdraw(withdraw_amount) - if @balance - withdraw_amount < 0 - puts "Insufficient funds. Withdraw denied." + if @balance - withdraw_amount < @@min_balance + puts "Insufficient new balance. Withdraw denied." @balance else @balance -= withdraw_amount diff --git a/bank-master.rb b/bank-master.rb new file mode 100644 index 00000000..d5f70217 --- /dev/null +++ b/bank-master.rb @@ -0,0 +1,4 @@ +require "./bank-accounts.rb" +require "./savings-account.rb" +require "./checking-account.rb" +require "./money-market.rb" diff --git a/checking-account.rb b/checking-account.rb new file mode 100644 index 00000000..20595aa5 --- /dev/null +++ b/checking-account.rb @@ -0,0 +1,35 @@ +module Bank + class CheckingAccount < Account + attr_reader :used_checks + + def initialize(ident, open_date, balance) + super + @used_checks = 0 + end + + def withdraw(withdraw_amount) + super(withdraw_amount + 100) + end + + def withdraw_using_check(amount) + if @balance - amount < -1000 + puts "Insufficient new balance. Check denied." + @balance + else + @used_checks += 1 + if @used_checks > 3 + @balance = @balance - amount - 200 + else + @balance -= amount + end + end + end + + def reset_checks + @used_checks = 0 + end + + + end + +end diff --git a/money-market.rb b/money-market.rb new file mode 100644 index 00000000..ad61aaa3 --- /dev/null +++ b/money-market.rb @@ -0,0 +1,58 @@ +module Bank + class MoneyMarketAccount < Account + attr_reader :transactions_permitted, :transaction_count, :balance + + @@min_balance = 1000000 + + def initialize(ident, open_date, balance) + super + @transaction_count = 0 + @transactions_permitted = true # this only refers to minimum balance concerns, not to transaction count + end + + def withdraw(withdraw_amount) + if @balance - withdraw_amount < 0 # balance can never go negative + puts "Insufficient new balance. Withdraw denied." + @balance + elsif @balance - withdraw_amount < @@min_balance && @transactions_permitted + @transactions_permitted = false + @balance = @balance - withdraw_amount - 10000 + elsif + @transaction_count < 6 && @transactions_permitted + @transaction_count += 1 + @balance -= withdraw_amount + else + @balance + end + end + + def deposit(deposit_amount) + if !@transactions_permitted + @balance += deposit_amount + if @balance >= @@min_balance + @transactions_permitted = true + @balance + else + @transactions_permitted = false + @balance + end + elsif @transaction_count < 6 + @transaction_count += 1 + @balance += deposit_amount + else + @balance + end + end + + def reset_transaction_count + @transaction_count = 0 + end + + def add_interest(rate) + interest = @balance * rate/100 + @balance += interest + return interest + end + + end +end diff --git a/savings-account.rb b/savings-account.rb new file mode 100644 index 00000000..0d88650f --- /dev/null +++ b/savings-account.rb @@ -0,0 +1,16 @@ +module Bank + class SavingsAccount < Account + @@min_balance = 1000 + + def withdraw(withdraw_amount) + super(withdraw_amount + 200) + end + + def add_interest(rate) + interest = @balance * rate/100 + @balance += interest + return interest + end + + end +end