From b79bdfe503a4328712f3ff1f93473a1f8a762833 Mon Sep 17 00:00:00 2001 From: Kari Bancroft Date: Thu, 8 Oct 2015 11:13:05 -0700 Subject: [PATCH 1/3] Add wave 3 --- README.md | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 25fd4d2a..b6e5c7b2 100644 --- a/README.md +++ b/README.md @@ -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 - From 5011563e680f8c84d566c5b6599c20256211bdc4 Mon Sep 17 00:00:00 2001 From: Sarah Date: Thu, 8 Oct 2015 14:36:46 -0700 Subject: [PATCH 2/3] first part of primary requirements complete --- bankv2.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bankv2.rb b/bankv2.rb index eb30abc1..b90b0647 100644 --- a/bankv2.rb +++ b/bankv2.rb @@ -18,7 +18,7 @@ class Account #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 From a9732733b97c2cdbd16de1b143532096d67f54ad Mon Sep 17 00:00:00 2001 From: Sarah Date: Mon, 12 Oct 2015 21:03:32 -0700 Subject: [PATCH 3/3] added a method for adding a new owner from a hash --- bankv2.rb | 68 +++++++++++++++++++++------------------------ checking_account.rb | 44 +++++++++++++++++++++++++++++ owner.rb | 46 ++++++++++++++++++++++++++++++ savings_account.rb | 28 +++++++++++++++++++ 4 files changed, 150 insertions(+), 36 deletions(-) create mode 100644 checking_account.rb create mode 100644 owner.rb create mode 100644 savings_account.rb diff --git a/bankv2.rb b/bankv2.rb index b90b0647..782abf3a 100644 --- a/bankv2.rb +++ b/bankv2.rb @@ -1,21 +1,11 @@ -# 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, "You cannot open an account with a negative balance." @@ -23,20 +13,23 @@ def initialize (id, balance, open_date) @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 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 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 +# +# 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" diff --git a/checking_account.rb b/checking_account.rb new file mode 100644 index 00000000..da406e24 --- /dev/null +++ b/checking_account.rb @@ -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 + # 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 + if @check > 3 + @balance = @balance - 200 + end + return @balance + end + end + + def reset_checks + @checks = 0 + end + +end diff --git a/owner.rb b/owner.rb new file mode 100644 index 00000000..1b69463f --- /dev/null +++ b/owner.rb @@ -0,0 +1,46 @@ +require "./bankv2.rb" + +class Owner < Bank::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) + 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"}) diff --git a/savings_account.rb b/savings_account.rb new file mode 100644 index 00000000..a0545a82 --- /dev/null +++ b/savings_account.rb @@ -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 + 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 + @balance += @interest + return @interest + end + +end + +savings = Savings.new(1212, 3414, "3/27/99 11:30")