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/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/bankaccounttest.rb b/bankaccounttest.rb index 35e71bf9..b7dac3bd 100644 --- a/bankaccounttest.rb +++ b/bankaccounttest.rb @@ -1,21 +1,24 @@ require 'csv' - +# require "./bankrequirefiles.rb" module Bank class Account - attr_accessor :id, :balance, :amount + attr_accessor :id, :balance, :opendate, :amount # :file @@number_of_accounts = 0 - def initialize() - account_array = CSV.read("./support/accounts.csv") - @id = account_array[@@number_of_accounts][0] - @balance = account_array[@@number_of_accounts][1] - @opendate = account_array[@@number_of_accounts][2] - # @opendate = opendate + def initialize(id, balance) + # account_array = CSV.read("./support/accounts.csv") + # @id = account_array[@@number_of_accounts][0] + # @balance = account_array[@@number_of_accounts][1] + # @opendate = account_array[@@number_of_accounts][2] + # @account_id = account_id - @balance = @balance.to_i - # @amount = amount.to_i + @id = id + @balance = balance.to_i + @opendate = opendate + # @fee = fee + @amount = amount.to_i if @balance < 0 raise ArgumentError.new("Cannot create a new account with a negative balance") @@ -23,25 +26,25 @@ def initialize() puts "You deposited #{@balance} dollars." puts "Your new balance is #{@balance} dollars." end - @@number_of_accounts += 1 + # @@number_of_accounts += 1 end #end statement for initialize method begining on line 10 - def withdraw - puts "Type the amount you would like to withdraw:" - @amount = gets.chomp.to_i - if @balance - @amount < 0 - puts ("Cannot withdraw an amount that will make the balance negative.") + def withdrawal(amount) + # puts "Type the amount you would like to withdraw:" + # @amount = gets.chomp.to_i + if @balance - amount.to_i < 0 + puts "Cannot withdraw an amount that will make the balance negative." puts "Your current balance is #{@balance}." else - @balance -= @amount + @balance -= amount.to_i puts "Your new balance is: #{@balance} dollars." end#end statment for the if/else beginning on line 32 end#end for withdraw method beginning on line 29 - def deposit - puts "Type the amount you would like to deposit:" - @amount = gets.chomp.to_i - @balance += @amount + def deposit(amount) + # puts "Type the amount you would like to deposit:" + # @amount = gets.chomp.to_i + @balance += amount.to_i puts "Your new balance is #{@balance} dollars." end#end statement for deposit method beginning on line 41 @@ -50,21 +53,28 @@ def balance end #end for balance method begining on line 48 def self.all - @@number_of_accounts = 0 - all_accounts_array = [] - account_array = CSV.read("./support/accounts.csv") - while @@number_of_accounts < account_array.length do - account_name = "Account" + @@number_of_accounts.to_s - account_name = Account.new() - all_accounts_array.push(account_name) + account_array = [] + CSV.read("./support/accounts.csv").each do |account| + print account + p = Account.new(account[0], account[1], account[2]) + account_array.push(p) end - return all_accounts_array + # @@number_of_accounts = 0 + # all_accounts_array = [] + # account_array = CSV.read("./support/accounts.csv") + # while @@number_of_accounts < account_array.length do + # account = "Account" + @@number_of_accounts.to_s + # account_name = Account.new() + # all_accounts_array.push(account_name) + # @@number_of_accounts += 1 + # end + # return all_accounts_array end#end statement for self.all method beginning on line 52 def self.find(id) account_array = self.all # print account_array - return account_array.find {|i| i.id == id.to_s} + return account_array.each do |i| i.id.to_i == id} end end#end for the account class on line 4 diff --git a/bankrequirefiles.rb b/bankrequirefiles.rb new file mode 100644 index 00000000..bd5a3fe4 --- /dev/null +++ b/bankrequirefiles.rb @@ -0,0 +1,3 @@ +require "./bankaccounttest.rb" +require "./savingsaccountclass.rb" +require "./checkingaccountclass.rb" diff --git a/checkingaccountclass.rb b/checkingaccountclass.rb new file mode 100644 index 00000000..2fbd0200 --- /dev/null +++ b/checkingaccountclass.rb @@ -0,0 +1,43 @@ +# require "./bankaccounttest.rb" +# require "./bankrequirefiles.rb" +module Bank + class CheckingAccount < Account + def initialize(id, balance) + super + @checks_written = 0 + if @balance < 1000 + raise ArgumentError.new("An initial deposit of at least ten dollars (1000 cents) is required to open an account.") + end#end of if balance in the initialize method + end#end of def initialize method + + def withdrawal(amount) + super + # if amount > @balance + # puts "Cannot perform withdrawal because the account will become negative" + # print @balance + # else + @balance -= (amount + 100) + puts "Your new balance is #{@balance}, which includes a $1 (100 cent) withdrawal fee." + # end of if amount > @balance block + end#end of withdrawal method + + def withdrawal_using_check(check_amount) + if check_amount > (@balance - 1000) + puts "Cannot perform transaction because the check amount is greater than the balance amount by ten dollars below zero." + else + if @checks_written < 3 + @balance -= (check_amount) + puts "Your new balance is #{@balance}." + @checks_written += 1 + else + @balance -= (check_amount + 200) + puts "Your new balance is #{@balance}, which includes a $2 (200 cent) check withdrawal fee." + end#end if if @checks_written block + end#end of if @check_amount block + end#edn of def withdrawal_using_check method + + def reset_checks + @checks_written = 0 + end#end for reset checks method + end#end for class +end#end for module diff --git a/experimentbankaccount.rb b/experimentbankaccount.rb new file mode 100644 index 00000000..7f53a893 --- /dev/null +++ b/experimentbankaccount.rb @@ -0,0 +1,54 @@ +module Bank + class Account + attr_accessor :account_id, :account_balance, :amount + + def initialize(account_id, account_balance = 0) + @account_id = account_id + @account_balance = account_balance.to_i + @amount = amount.to_i + if @account_balance < 0 + raise ArgumentError.new("Cannot create a new account with a negative balance") + + else + puts "You deposited #{@amount} dollars." + puts "Your new balance is #{@account_balance} dollars." + end + end + + def withdraw(amount) + if @account_balance - @amount < 0 + puts ("Cannot withdraw an amount that will make the balance negative.") + puts "Your current balance is #{@account_balance}." + else + @account_balance -= @amount + puts "Your new balance is: #{@account_balance} dollars." + end + end + + def deposit(@amount) + @account_balance += @amount + puts "Your new balance is #{@account_balance} dollars." + end + + def balance + puts account_balance + end + + end +end +#extra code + + + +# @default_account_amount = 0 +# puts "Your default account balance is $0. Please enter the amount you wish to deposit in whole dollars:" +# @user_deposit = gets.chomp +# @integer_user_deposit = @user_deposit.to_i +# if @integer_user_deposit >= 0 +# beginning_account_amount = @default_deposit_amount.to_i + @integer_user_deposit +# puts "You deposited #{@integer_user_deposit} dollars." +# puts "Your new balance is #{beginning_account_amount} dollars." +# else +# raise ArgumentError, "Please enter an amount that is greater than zero." +# @user_deposit = gets.chomp +# end diff --git a/savingsaccountclass.rb b/savingsaccountclass.rb new file mode 100644 index 00000000..df644b61 --- /dev/null +++ b/savingsaccountclass.rb @@ -0,0 +1,33 @@ +# require "./bankaccounttest.rb"# require "./bankaccounttest.rb" +# require "./bankaccounttest.rb" +module Bank + class SavingsAccount < Account + # attr_accessor = :amount, :balance + def initialize(id, balance) + super + # @balance = balance + if @balance < 1000 + raise ArgumentError.new("An initial deposit of at least ten dollars (1000 cents) is required to open an account.") + end + end + + def savings_withdraw(withdraw) + withdrawal_amount = withdraw + 200 + if @balance - withdrawal_amount <= 1000 + puts "The account minimum balance is $10 (1000 cents). You cannot go below that minimum." + return @balance + else + @balance -= withdrawal_amount + end + end + + def add_interest(rate) + account_interest = @balance * rate/100 + @balance += account_interest + puts account_interest + # print @balance + end + + + end +end diff --git a/tryoutbankaccount.rb b/tryoutbankaccount.rb new file mode 100644 index 00000000..5b249498 --- /dev/null +++ b/tryoutbankaccount.rb @@ -0,0 +1,5 @@ +require 'csv' +# def show_all_accounts +s = CSV.read("./support/accounts.csv") +print s +# print s[-1]