Skip to content
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
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
-->
125 changes: 125 additions & 0 deletions account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
module Bank

require 'csv'

class Account

# @@min_balance = 0

attr_accessor :balance, :account_id, :owner

def initialize(account_id, balance, datetime_open, owner = nil)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of the default attribute for the owner

@account_id = account_id
@balance = balance
@withdrawal_fee = 0
@min_balance = 0
if balance < @min_balance
raise ArgumentError.new("Cannot start an account with a negative balance.")
end
@datetime_open = DateTime.strptime(datetime_open, "%Y-%m-%d %H:%M:%S %z")
@owner = owner
end

def self.all
accounts_csv = CSV.read("./support/accounts.csv")
accounts_instances = []
accounts_csv.each do |row|
accounts_instances.push(Account.new(row[0], row[1].to_i, row[2]))
end
return accounts_instances
end

def self.find(id)
self.all.find do |line|
line.account_id.to_i == id
end
# new_account = Account.new(matched_id[0], matched_id[1], matched_id[2])
# puts new_account
end

def self.everything

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job putting everything together!

account_owners_csv = CSV.read("./support/account_owners.csv")
everything_array = []
account_owners_csv.each do |line|
each_account = self.find(line[0].to_i)
each_owner = Bank::Owner.find(line[1].to_i)
each_account.assign_owner(each_owner)
everything_array.push(each_account)
end
return everything_array
end

def withdraw(withdraw_amount)
# returns updated balance
if withdraw_amount > (@balance + @withdrawal_fee)
puts "Not enough money in account"
puts "The current balance is only: #{@balance}"
else
@balance = (@balance - withdraw_amount - @withdrawal_fee)
puts "Updated balance is: #{@balance}"
end
end

def deposit(deposit_amount)
# returns updated balance
@balance += deposit_amount
puts "Updated balance is: #{@balance}"
end

def add_interest(rate)
interest = @balance * rate/100
puts "The interest earned on the account is: $#{interest.to_i}"
@balance = @balance + interest
puts "The new balance is: $#{@balance.to_i}"
end


# def assign_owner(owner_hash)
# @owner = owner
# # puts "The owner of this account is #{@owner.first_name} #{@owner.last_name}."
# end
end

class Owner

attr_reader :owner_id, :first_name, :last_name, :street, :city, :state, :zip

def initialize(owner_hash)
@owner_id = owner_hash[:owner_id]
@first_name = owner_hash[:first_name]
@last_name = owner_hash[:last_name]
@street = owner_hash[:street]
@city = owner_hash[:city]
@state = owner_hash[:state]
@zip = owner_hash[:zip]
end

def self.all
owners_csv = CSV.read("./support/owners.csv")
owners_array = []
owners_csv.each do |row|
owner_hash = {:owner_id => row[0], :last_name => row[1], :first_name => row[2], :street => row[3], :city => row[4], :state => row[5]}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would split this out onto separate lines to make it more readable

owners_array.push Owner.new(owner_hash)
end
return owners_array
end

def self.find(id)
self.all.find do |line|
line.owner_id.to_i == id
end
end

# def self.everything
# account_owners_csv = CSV.read("./support/account_owners.csv")
# everything_array = []
# account_owners_csv.each do |line|
# each_owner = self.find(line[1].to_i)
# each_account = Bank::Account.find(line[0].to_i)
# each_owner.account = each_account
# everything_array.push(each_owner)
# end
# return everything_array
# end
end
end
4 changes: 4 additions & 0 deletions bank.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require "./account.rb"
require "./savings_account.rb"
require "./checking_account.rb"
require "./moneymarket_account.rb"
46 changes: 34 additions & 12 deletions bankaccount_w1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@ module Bank

class Account

attr_accessor :balance, :account_id
attr_accessor :balance, :account_id, :owner

def initialize(account_id, balance, datetime_open) #owner = nil)
def initialize(account_id, balance, datetime_open, owner = nil)
@account_id = account_id

@balance = balance
if balance < 0
raise ArgumentError.new("Cannot start an account with a negative balance.")
end

@balance = balance
# @owner = owner
@datetime_open = DateTime.strptime(datetime_open, "%Y-%m-%d %H:%M:%S %z")
# @accounts_array = []
@datetime_open = datetime_open # DateTime.strptime(datetime_open, "%Y-%m-%d %H:%M:%S %z")
@owner = owner
end

def self.all
Expand All @@ -29,9 +26,23 @@ def self.all
end

def self.find(id)
self.all.find do |line|
self.all.find do |line|
line.account_id.to_i == id
end
# new_account = Account.new(matched_id[0], matched_id[1], matched_id[2])
# puts new_account
end

def self.everything
account_owners_csv = CSV.read("./support/account_owners.csv")
everything_array = []
account_owners_csv.each do |line|
each_account = self.find(line[0].to_i)
each_owner = Bank::Owner.find(line[1].to_i)
each_account.owner = each_owner
everything_array.push(each_account)
end
return everything_array
end

def withdraw(withdraw_amount)
Expand All @@ -48,7 +59,6 @@ def withdraw(withdraw_amount)

puts "Your updated balance is: #{@balance}"
end
end

def deposit(deposit_amount)
# returns updated balance
Expand All @@ -58,9 +68,9 @@ def deposit(deposit_amount)

# def assign_owner(owner_hash)
# @owner = owner
# puts "The owner of this account is #{@owner.first_name} #{@owner.last_name}."
# # puts "The owner of this account is #{@owner.first_name} #{@owner.last_name}."
# end

end

class Owner

Expand Down Expand Up @@ -91,6 +101,18 @@ def self.find(id)
line.owner_id.to_i == id
end
end

# def self.everything
# account_owners_csv = CSV.read("./support/account_owners.csv")
# everything_array = []
# account_owners_csv.each do |line|
# each_owner = self.find(line[1].to_i)
# each_account = Bank::Account.find(line[0].to_i)
# each_owner.account = each_account
# everything_array.push(each_owner)
# end
# return everything_array
# end
end
end

Expand Down
37 changes: 37 additions & 0 deletions checking_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module Bank

require 'csv'

class CheckingAccount < Account

def initialize(account_id, balance, datetime_open, owner = nil)
super
@withdrawal_fee = 1
@checks_used = 0
end

def withdraw_using_check(amount)
if @checks_used >= 3
@withdrawal_fee = 0
end
if (@balance - amount - @withdrawal_fee) < -10
puts "Unable to make this withdrawal"
else
@balance -= (amount + @withdrawal_fee)
puts @withdrawal_fee
puts "The new balance is: #{@balance}"
@checks_used += 1
end
return @balance
end

def add_interest(rate)
return "Not a function of this account."
end

def reset_checks
@checks_used = 0
@withdrawal_fee = 1
end
end
end
54 changes: 54 additions & 0 deletions moneymarket_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module Bank

require 'csv'

class MoneyMarket < Account

# @@min_balance = 10000

attr_accessor :transactions

def initialize(account_id, balance, datetime_open, owner = nil)
super
#max of 6 transactions (deposit or withdrawal)
#initial balance !< $10000 - will raise ArgumentError
@min_balance = 10000
@transactions = 0
@min_balance_fee = 100
end

# def transactions()
# @transactions += 1
# end

def withdraw(withdraw_amount)
if (@balance - withdraw_amount) < @min_balance && @transactions < 6
@balance -= (@min_balance_fee)
puts "A $100 fee is imposed for going below $10000"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you have variables that store these variables, I would use the variables in this error message b/c if the values changed, then you wouldn't need to change this message

end
if @transactions >= 6
puts "No more transactions left available this month."
else
@balance -= withdraw_amount
@transactions += 1
end
end

def deposit(deposit_amount)
if @balance >= @@min_balance
if @transactions < 6

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You use this 6 value a lot so it would be a great place to use a constant!

super
@transactions += 1
else
puts "No more transactions left available this month."
end
else
super
end
end

def reset_transactions
@transactions = 0
end
end
end
15 changes: 15 additions & 0 deletions savings_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Bank

require 'csv'

class SavingsAccount < Account

# @@min_balance = 10

def initialize(account_id, balance, datetime_open, owner = nil)
super

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@min_balance = 10
@withdrawal_fee = 2
end
end
end