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

Sat/master #74

Open
wants to merge 4 commits into
base: sat/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
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: 33 additions & 37 deletions bankv2.rb
Original file line number Diff line number Diff line change
@@ -1,42 +1,35 @@
# Update the Account class to be able to handle all of these fields from the CSV file used as input.
# For example, manually choose the data from the first line of the CSV file
# and ensure you can create a new instance of your Account using that data
# Add the following class methods to your existing Account class:
# self.all - returns a collection of Account instances, representing all of the Accounts described in the CSV.
#See below for the CSV file specifications
# self.find(id) - returns an instance of Account where the value of the id field in the CSV matches
#the passed parameter

require 'csv'

module Bank

class Account

attr_reader :balance, :id, :owner, :open_date
attr_reader :id, :balance, :open_date, :owner

#create instance variable for balance?
def initialize (id, balance, open_date)
if balance < 0

Choose a reason for hiding this comment

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

Watch out for your indentation here - you don't need an additional indent when you start your if statement, only inside the block of it

raise ArgumentError
raise ArgumentError, "You cannot open an account with a negative balance."
end
@balance = balance
@id = id
@open_date = open_date
@owner = owner
end


#self refers to the Account class. To access, try "Bank:Account.all"
#you could also call this Account.all
#to get a list of all accounts, you can do Bank::Account.all now that you've created this method
def self.all
accounts_csv = CSV.read("./support/accounts.csv")
#account_owner = Account.new(accounts_csv[0][0],accounts_csv[0][1], accounts_csv[0][2])
accounts_csv.map! do |row|
Account.new row [0].to_i, row [1].to_i, DateTime.parse(row [2])
binding.pry

Choose a reason for hiding this comment

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

Don't forget to remove binding.pry statements when you submit your code

end

return accounts_csv
end

# to locate an instance of an ID, you would run Bank::Account.find(id #)
def self.find(id)
return Account.all.find do |account|
account.id == id
Expand All @@ -46,7 +39,7 @@ def self.find(id)

def withdraw(take_money)
if take_money > @balance
puts "You have #{@balance} in your account. You can only widthdraw less than your total balance."
puts "You have #{@balance} in your account. You can only withdraw less than your total balance."
else @balance -= take_money

Choose a reason for hiding this comment

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

I think that you want this code within your else statement rather than as the conditional itself

else
   @balance -= take_money
   return @balance
end

return @balance
end
Expand All @@ -64,26 +57,32 @@ def add_owner
end
end
end
# class Owner
#
# attr_reader :first_name, :last_name, :street_1, :street_2, :city, :state, :zip, :ssn
#
# def initialize(owner_hash)
# @first_name = owner_hash[:first_name]
# @last_name = owner_hash[:last_name]
# @street_1 = owner_hash[:street_1]
# @street_2 = owner_hash[:street_2]
# @city = owner_hash[:city]
# @state = owner_hash[:state]
# @zip = owner_hash[:zip]
# @ssn = owner_hash[:ssn]
# end
# def print_info
# puts "#{@first_name} #{@last_name} is the owner of this account, from #{@city}, #{@state}."
# end
# end

# name = Bank::Owner.new({name: "Sarah", zip: "98933"})
# class Owner

Choose a reason for hiding this comment

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

Since you moved the Owner code to it's own file, I would delete this commented out section

#
# attr_reader :first_name, :last_name, :street_1, :street_2, :city, :state, :zip, :ssn
#
# def initialize(owner_hash)
# @first_name = owner_hash[:first_name]
# @last_name = owner_hash[:last_name]
# @street_1 = owner_hash[:street_1]
# @street_2 = owner_hash[:street_2]
# @city = owner_hash[:city]
# @state = owner_hash[:state]
# @zip = owner_hash[:zip]
# @ssn = owner_hash[:ssn]
# end
#
# bank
#
# def print_info
# puts "#{@first_name} #{@last_name} is the owner of this account, from #{@city}, #{@state}."
# end
# end
#
#
#
# # name = Bank::Owner.new({first_name: "Sarah", zip: "98933"})
#
# test = Bank::Account.new(2, 1, 3)
# puts test.id
Expand All @@ -92,9 +91,6 @@ def add_owner
# puts "Your withdraw is"
# puts test.withdraw(10)




# test2 = Bank::Account.new(-1, 3)
# puts puts test.id
# puts "Your deposit is"
Expand Down
44 changes: 44 additions & 0 deletions checking_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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
# #reset_checks: Resets the number of checks used to zero

require "./bankv2.rb"

class Checking < Bank::Account
def initialize (id, balance, open_date)
super
@check = 0
end

def withdraw(take_money)
super
@balance -= 100 if take_money > @balance

Choose a reason for hiding this comment

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

What if the 100 would take the user negative?

# return @balance
end

def withdraw_using_check(amount)
if @balance - amount <= -1000
puts "You cannot withdraw more than -$10.00 from your acount."
else
@balance -= amount
@check = @check + 1

Choose a reason for hiding this comment

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

This would be a great place to use a +=

if @check > 3
@balance = @balance - 200
end
return @balance
end
end

def reset_checks
@checks = 0
end

end
46 changes: 46 additions & 0 deletions owner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
require "./bankv2.rb"

class Owner < Bank::Account

Choose a reason for hiding this comment

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

Is the owner support to inherit behavior directly from the account?


attr_reader :first_name, :last_name, :street_1, :street_2, :city, :state, :zip, :ssn

def initialize(owner_hash)
@first_name = owner_hash[:first_name]
@last_name = owner_hash[:last_name]
@street_1 = owner_hash[:street_1]
@street_2 = owner_hash[:street_2]
@city = owner_hash[:city]
@state = owner_hash[:state]
@zip = owner_hash[:zip]
@ssn = owner_hash[:ssn]
@owner = []
end

def add_new_owner(owner)
@owner.push(owner)

Choose a reason for hiding this comment

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

Does this mean that an owner has an owner?

end

def print_info
puts "#{@first_name} #{@last_name} is the owner of this account, from #{@city}, #{@state}."
end
end

ruth = {

first_name: "Ruth",
last_name: "Bader Ginsburg",
street_1: "Supreme Court",
street_2: "Important Road",
city: "Washington",
state: "DC",
zip: "12121",
ssn: "1234567",
}

ruth = Bank::Account.new(1212, 300000, "12/3/5")

ruth.add_new_owner(Owner.new(ruth))

# s.add_new_planet(Planet.new(fremont))

# name = Bank::Owner.new({first_name: "Sarah", zip: "98933"})
28 changes: 28 additions & 0 deletions savings_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# #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.

require "./bankv2.rb"

class Savings < Bank::Account
def initialize (id, balance, open_date)
super
@balance = balance
if balance < 1000

Choose a reason for hiding this comment

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

Watch your indentation here as well

raise ArgumentError, "You need a minimum of $10.00 to open a savings account."
return balance
end
end

def add_interest(rate)
@interest = @balance * rate/100

Choose a reason for hiding this comment

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

Since the interest is being calculated for the purpose of this method's local rate, this should be a local variable and not an instance variable

@balance += @interest
return @interest
end

end

savings = Savings.new(1212, 3414, "3/27/99 11:30")