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

Wave 3 Bank Account #68

Open
wants to merge 11 commits into
base: rlh/master
Choose a base branch
from
Binary file added .DS_Store
Binary file not shown.
38 changes: 38 additions & 0 deletions MoneyMarketAccount.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module Bank

class MoneyMarketAccount < SavingsAccount
attr_reader :transactions

def initialize(id, balance, open_date)
@account_id = id.to_i
@balance = balance.to_i * 100
@open_date = open_date
@mm_account_fee = 0
@transactions = 6
@act_withdraw_fee = 100_00
@mm_min_balance = 10_000_00
@min_balance = 0

if @balance < @mm_min_balance
raise StandardError, "You cannot open an account with that little money."
end

end

def withdraw(amount)
if @balance >= @mm_min_balance
if @transactions > 0
super
@transactions -= 1
end
else
puts "You must deposit at least #{@mm_min_balance - @balance} before you can withdraw any more."
end
end

def reset_transactions
@transactions = 6
end

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

class Account
attr_reader :balance, :account_id, :owner, :all_accounts, :open_date

def initialize(id, balance, open_date)

@account_id = id
@balance = balance * 100
@open_date = open_date
@min_balance = 0
@act_withdraw_fee = 0

if balance.to_i < @min_balance
raise StandardError, "You cannot open an account with that little money."
end
end

def withdraw(withdraw_amt)
withdraw_to_cents = withdraw_amt * 100

if (@balance - withdraw_to_cents) < (@min_balance + @act_withdraw_fee)
puts "You cannot withdraw that much. Your current balance is #{@balance} cents"
elsif @mm_min_balance > 0
if (@balance - withdraw_to_cents) > (-@mm_min_balance)
@balance -= withdraw_to_cents
puts "Your account balance is now #{@balance} cents."
else
@balance -= (withdraw_to_cents + @act_withdraw_fee)
puts "You've withdrawn your account below #{@mm_min_balance}, so you'll be charged #{@act_withdraw_fee} cents."
puts "You must deposit enough for your account to be above #{@mm_min_balance} cents before you can withdraw any more."
puts "Your new balance is #{@balance} cents."
end
else
@balance -= (withdraw_to_cents + @act_withdraw_fee)
puts "Your account balance is now #{@balance} cents."
end
end

def deposit(deposit_amt)
deposit_to_cents = deposit_amt * 100

if @mm_min_balance > 0
if @balance >= 10_000_00
@balance += deposit_to_cents
puts "Your previous account balance was #{@balance - deposit_to_cents} cents."
puts "It is now #{@balance} cents."
@transactions -= 1
elsif @balance + deposit_to_cents >= 10_000_00
@balance += deposit_to_cents
puts "Your previous account balance was #{@balance - deposit_to_cents} cents."
puts "It is now #{@balance} cents."
else
@balance += deposit_to_cents
@transactions -= 1
puts "Your previous account balance was #{@balance - deposit_to_cents} cents."
puts "It is now #{@balance} cents."
puts "You still need to deposit #{@mm_min_balance - @balance} before you can withdraw any more."
end

else
@balance += deposit_to_cents
puts "Your previous account balance was #{@balance - deposit_to_cents} cents."
puts "It is now #{@balance} cents."
end
end

def show_balance
puts "Your current balance is #{@balance} cents"
end

def assign_owner(first_name, last_name, address)
@owner = Bank::Owner.new(first_name, last_name, address)
end

def self.all
@all_accounts = []

CSV.read("./support/accounts.csv").each do |line|
y = Bank::Account.new(line[0].to_i, line[1].to_i, line[2])

Choose a reason for hiding this comment

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

I would use a more meaningful variable name rather than y

@all_accounts.push(y)
end

return @all_accounts

Choose a reason for hiding this comment

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

By using an instance variable in a class method this could be a tricky scenario if you try to use this instance variable again later without first calling this class method where the variable is set

end

def self.find(id)
Bank::Account.all.find do |account_instance|
account_instance.account_id == id
end
end
end
end
104 changes: 83 additions & 21 deletions bankaccount.rb
Original file line number Diff line number Diff line change
@@ -1,60 +1,122 @@
require "csv"
require "pry"

module Bank

class Owner
attr_reader :first_name, :last_name, :address

def initialize(first_name, last_name, address)
attr_reader :first_name, :last_name, :street_address, :owner_id

def initialize(owner_id, last_name, first_name, street_address, city, state)
@owner_id = id
@first_name = first_name
@last_name = last_name
@address = address
@street_address = street_address
@city = city
@state = state
end

def self.all
all_owners = []

CSV.read("./support/owners.csv").each do |line|
y = Bank::Owner.new(line[0].to_i, line[1], line[2], line[3], line[4], line[5])
all_owners.push(y)
end

return all_owners
end

def self.find(id)
Bank::Owner.all.find do |account_instance|
account_instance.owner_id == id
end
end
end

class Account
attr_reader :balance, :id, :owner
attr_reader :balance, :account_id, :owner, :all_accounts, :open_date

def initialize(id, initial_balance)
# another way of generating an error if user starts with negative balance
# while initial_balance < 0
# puts "You cannot open an account in debt."
# puts "Please enter a new opening balance: "
# initial_balance = gets.chomp.to_i
# end
def initialize(id, balance, open_date)

if initial_balance < 0
if balance.to_i < 0
raise StandardError, "You cannot open an account in debt."
end

@balance = initial_balance
@id = id
@account_id = id
@balance = balance
@open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %Q")
end

def withdraw(withdraw_amt)
while (@balance - withdraw_amt) < 0
puts "You cannot overdraft your account. Your current balance is $#{@balance}"
puts "You cannot overdraft your account. Your current balance is #{@balance} cents"
puts "Please enter a new withdrawl amount: "
withdraw_amt = gets.chomp.to_i
end

@balance -= withdraw_amt
puts "Your previous account balance was $#{@balance + withdraw_amt}."
puts "It is now $#{@balance}."
puts "Your previous account balance was #{@balance + withdraw_amt} cents."
puts "It is now #{@balance} cents."
end

def deposit(deposit_amt)
@balance += deposit_amt
puts "Your previous account balance was $#{@balance - deposit_amt}."
puts "It is now $#{@balance}."
puts "Your previous account balance was #{@balance - deposit_amt} cents."
puts "It is now #{@balance} cents."
end

def show_balance
puts "Your current balance is $#{@balance}"
puts "Your current balance is #{@balance} cents"
end

def assign_owner(first_name, last_name, address)
@owner = Bank::Owner.new(first_name, last_name, address)
end

def self.all
@all_accounts = []

CSV.read("./support/accounts.csv").each do |line|
y = Bank::Account.new(line[0].to_i, line[1].to_i, line[2])
@all_accounts.push(y)
end

return @all_accounts
end

def self.find(id)
Bank::Account.all.find do |account_instance|
account_instance.account_id == id
end
end

# working on this still
# def self.match_owner
# Bank::Account.all
#
# CSV.read("./support/accounts.csv").each do |line|
# binding.pry
# account = CSV.read("./support/account_owners.csv").find(line[0])
# owner = CSV.read("./support/owners.csv").find(account[1])
# Bank::Owner.new(owner)
# end

# take the account id (line[0] in each loop) and find which owners_id within account_owners.csv it shares,
# then take that owners_id, switch over to the owners.cvs, and initialize a new Owner based on that

# end
end

class SavingsAccount < Account
def initialize(id, balance, open_date)
super
if balance.to_i < 0
raise StandardError, "You cannot open an account with less than $10."
end
end


end


end
15 changes: 15 additions & 0 deletions bankaccountw3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "csv"
require "pry"

require "./account.rb"
require "./savings.rb"
require "./owner.rb"
require "./checkingaccount.rb"
require "./MoneyMarketAccount.rb"


# testing to see if they work:
# Account class: y
# savings: y
# checking: y
# Money Market class: this one still has issues :(
Empty file added checkingaccount
Empty file.
39 changes: 39 additions & 0 deletions checkingaccount.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module Bank

class CheckingAccount < Account
attr_reader :free_checks

def initialize(id, balance, open_date)
super

@act_withdraw_fee = 100
@free_checks = 3
end

def withdraw(withdraw_amt)
super
end

def withdraw_using_check(amount)
withdraw_to_cents = amount * 100

if (@balance - withdraw_to_cents) < (@min_balance - 1000)
puts "You cannot withdraw that much. Your current balance is #{@balance} cents"
elsif @free_checks > 0
@balance -= withdraw_to_cents
@free_checks -= 1
puts "Your account balance is now #{@balance} cents."
else
@balance -= (withdraw_to_cents + 200)
puts "You already used up your free checks for this month, so you've been charged an extra $2."
puts "Your new balance is #{@balance} cents."
end
end

def reset_checks
@free_checks = 3
end


end
end
Loading