-
Notifications
You must be signed in to change notification settings - Fork 21
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
base: sat/master
Are you sure you want to change the base?
Sat/master #74
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't forget to remove |
||
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 | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that you want this code within your else
@balance -= take_money
return @balance
end |
||
return @balance | ||
end | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you moved the |
||
# | ||
# 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 | ||
|
@@ -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" | ||
|
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require "./bankv2.rb" | ||
|
||
class Owner < Bank::Account | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"}) |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
@balance += @interest | ||
return @interest | ||
end | ||
|
||
end | ||
|
||
savings = Savings.new(1212, 3414, "3/27/99 11:30") |
There was a problem hiding this comment.
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