Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arh/master #70

Open
wants to merge 13 commits into
base: arh/master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
30 changes: 14 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<!--
## Wave 3
Create a `SavingsAccount` class which should inherit behavior from the `Account` class. It should include updated logic with the following functionality:
- An updated `initialize` method:
- The initial balance cannot be less than $10. If it is, this will `raise` an `ArgumentError`
- An updated `withdraw` method:
Create a `SavingsAccount` class which should inherit behavior from the `Account` class. It should include the following updated functionality:
- The initial balance cannot be less than $10. If it is, this will `raise` an `ArgumentError`
- Updated withdrawal functionality:
- Each withdrawal 'transaction' incurs a fee of $2 that is taken out of the balance.
- Does not allow the account to go below the $10 minimum balance - Will output a warning message and return the original un-modified balance

It should include the following new methods:
It should include the following new method:
- `#add_interest(rate)`: Calculate the interest on the balance and add the interest to the balance. Return the **interest** that was calculated and added to the balance (not the updated balance).
- Input rate is assumed to be a percentage (i.e. 0.25).
- The formula for calculating interest is `balance * rate/100`
- Example: If the interest rate is 0.25% and the balance is $10,000, then the interest that is returned is $25 and the new balance becomes $10,025.

Create a `CheckingAccount` class which should inherit behavior from the `Account` class. It should include updated logic with the following functionality:
- `#withdraw(amount)`: The input amount gets taken out of the account as result of an ATM transaction. Each withdrawal 'transaction' incurs a fee of $1 that is taken out of the balance. Returns the updated account balance.
- Does not allow the account to go negative. Will output a warning message and return the original un-modified balance.
Create a `CheckingAccount` class which should inherit behavior from the `Account` class. It should include the following updated functionality:
- Updated withdrawal functionality:
- Each withdrawal 'transaction' incurs a fee of $1 that is taken out of the balance. Returns the updated account balance.
- Does not allow the account to go negative. Will output a warning message and return the original un-modified balance.
- `#withdraw_using_check(amount)`: The input amount gets taken out of the account as a result of a check withdrawal. Returns the updated account balance.
- Allows the account to go into overdraft up to -$10 but not any lower
- The user is allowed three free check uses in one month, but any subsequent use adds a $2 transaction fee
Expand All @@ -101,16 +100,15 @@ Create a `CheckingAccount` class which should inherit behavior from the `Account

## Optional:

Create a `MoneyMarketAccount` class with a minimum of 6 specs. The class should inherit behavior from the `Account` class.
Create a `MoneyMarketAccount` class which should inherit behavior from the `Account` class.
- A maximum of 6 transactions (deposits or withdrawals) are allowed per month on this account type
- `self.new(id, initial_balance)`: creates a new instance with the instance variable `id` and 'initial_balance' assigned
- The initial balance cannot be less than $10,000 - this will `raise` an `ArgumentError`
- `#withdraw(amount)`: The input amount gets taken out of the account as result of an ATM transaction. Returns the updated account balance.
- The initial balance cannot be less than $10,000 - this will `raise` an `ArgumentError`
- Updated withdrawal logic:
- If a withdrawal causes the balance to go below $10,000, a fee of $100 is imposed and no more transactions are allowed until the balance is increased using a deposit transaction.
- Each transaction will be counted against the maximum number of transactions
- `#deposit(amount)`. Returns the updated account balance.
- Updated deposit logic:
- Each transaction will be counted against the maximum number of transactions
- Exception to the above: A deposit performed to reach or exceed the minimum balance of $10,000 is not counted as part of the 6 transactions.
- `#add_interest(rate)`: Calculate the interest on the balance and add the interest to the balance. Return the interest that was calculated and added to the balance (not the updated balance). Note** This is the same as the `SavingsAccount` interest.
- `#add_interest(rate)`: Calculate the interest on the balance and add the interest to the balance. Return the interest that was calculated and added to the balance (not the updated balance).
- Note** This is the same as the `SavingsAccount` interest.
- `#reset_transactions`: Resets the number of transactions to zero
-->
70 changes: 40 additions & 30 deletions bankaccounttest.rb
Original file line number Diff line number Diff line change
@@ -1,47 +1,50 @@
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")

else
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

Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions bankrequirefiles.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require "./bankaccounttest.rb"
require "./savingsaccountclass.rb"
require "./checkingaccountclass.rb"
43 changes: 43 additions & 0 deletions checkingaccountclass.rb
Original file line number Diff line number Diff line change
@@ -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
54 changes: 54 additions & 0 deletions experimentbankaccount.rb
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions savingsaccountclass.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions tryoutbankaccount.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'csv'
# def show_all_accounts
s = CSV.read("./support/accounts.csv")
print s
# print s[-1]