From 61d3cd35132341505d4f06fa1b09c44ebb48a2d7 Mon Sep 17 00:00:00 2001 From: Danielle Schrimmer Date: Tue, 23 Aug 2016 11:03:22 -0700 Subject: [PATCH 01/11] Created account and owner classes, all baseline requirements complete. Error when calling owner method in account file. --- account.rb | 40 ++++++++++++++++++++++++++++++++++++++++ owner.rb | 20 ++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 account.rb create mode 100644 owner.rb diff --git a/account.rb b/account.rb new file mode 100644 index 00000000..e8684601 --- /dev/null +++ b/account.rb @@ -0,0 +1,40 @@ +require_relative 'owner' + +module Bank + class Account + attr_accessor :id, :balance + + def initialize(id, balance) + @id = id + @balance = balance + + unless @balance >= 0 + raise ArgumentError.new("A new account cannot be created with initial negative balance.") + end + end + + def add_owner(name, address, phone) + Bank::Owner.new(@id, name, address, phone) + end + + def withdraw(amount) + if amount <= @balance + @balance -= amount + return @balance + else + puts "Your account does not contain enough to withdraw the amount requested." + return @balance + end + end + + def deposit(amount) + @balance += amount + return @balance + end + + def balance + return @balance + end + + end +end diff --git a/owner.rb b/owner.rb new file mode 100644 index 00000000..e14da441 --- /dev/null +++ b/owner.rb @@ -0,0 +1,20 @@ +module Bank + class Owner + attr_accessor :name, :address, :phone + + def initialize(id, name, address, phone) + @id = id + @name = name + @address = address + @phone = phone + end + + def owner_info + puts "Owner's id: #{ @id }" + puts "Owner's name: #{ @name }" + puts "Owner's address: #{ @address }" + puts "Owner's phone: #{ @phone }" + end + + end +end From 0a58a975101e4201b91b4ab9834136a018664a43 Mon Sep 17 00:00:00 2001 From: Danielle Schrimmer Date: Tue, 23 Aug 2016 15:25:11 -0700 Subject: [PATCH 02/11] Wave one complete with optional enhancements. Can create accounts with ID and positive balance, handles negative withdrawls, owner can be added after account has been created. --- account.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/account.rb b/account.rb index e8684601..b05a23af 100644 --- a/account.rb +++ b/account.rb @@ -32,9 +32,9 @@ def deposit(amount) return @balance end - def balance - return @balance - end - end end + +# a = Bank::Account.new(1234, 40) +# o = a.add_owner("danielle", "909 green way", 5555555) +# o.owner_info From cd33075b7bc961eb26d714baf646d5027b234a5a Mon Sep 17 00:00:00 2001 From: Danielle Schrimmer Date: Wed, 24 Aug 2016 14:53:06 -0700 Subject: [PATCH 03/11] Meets basic requirements for Wave 2: reads CSV, returns collection of Account instances, returns an instance of Account where id field matches passed parameter. --- account.rb | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/account.rb b/account.rb index b05a23af..742f87ed 100644 --- a/account.rb +++ b/account.rb @@ -1,12 +1,14 @@ +require 'csv' require_relative 'owner' module Bank class Account - attr_accessor :id, :balance + attr_accessor :id, :balance, :date, :accounts - def initialize(id, balance) + def initialize(id, balance, date = nil) @id = id @balance = balance + @date = date unless @balance >= 0 raise ArgumentError.new("A new account cannot be created with initial negative balance.") @@ -32,9 +34,34 @@ def deposit(amount) return @balance end + # return collection of Account instances + def self.all + accounts = [] + CSV.read('support/accounts.csv').each do |line| + accounts << self.new(line[0].to_i, line[1].to_i, line[2]) + end + return accounts + end + + # returns an instance of Account where value of the id matches the parameter + def self.find(id) + self.all.each do |i| + if i.id == id + return i + end + end + puts "No account with this id number." + end + end end # a = Bank::Account.new(1234, 40) # o = a.add_owner("danielle", "909 green way", 5555555) # o.owner_info +# a.deposit(10) +# a.balance +# a.withdraw(60) +# a.balance +# a.withdraw(30) +# a.balance From aacff1f374fc2700991fff2b435dc1fe3c181ca7 Mon Sep 17 00:00:00 2001 From: Danielle Schrimmer Date: Wed, 24 Aug 2016 15:03:20 -0700 Subject: [PATCH 04/11] Updated owner account that reads in csv of owners. Account file updated to reflect updated owner fields. --- account.rb | 4 ++-- owner.rb | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/account.rb b/account.rb index 742f87ed..5cdf2c9b 100644 --- a/account.rb +++ b/account.rb @@ -15,8 +15,8 @@ def initialize(id, balance, date = nil) end end - def add_owner(name, address, phone) - Bank::Owner.new(@id, name, address, phone) + def add_owner(id, lname, fname, address, city, state) + Bank::Owner.new(id, lname, fname, address, city, state) end def withdraw(amount) diff --git a/owner.rb b/owner.rb index e14da441..86b67da2 100644 --- a/owner.rb +++ b/owner.rb @@ -1,19 +1,31 @@ +require 'csv' + module Bank class Owner attr_accessor :name, :address, :phone - def initialize(id, name, address, phone) + def initialize(id, lname, fname, address, city, state) @id = id - @name = name + @last_name = lname + @first_name = fname @address = address - @phone = phone + @city = city + @state = state end def owner_info puts "Owner's id: #{ @id }" puts "Owner's name: #{ @name }" - puts "Owner's address: #{ @address }" - puts "Owner's phone: #{ @phone }" + puts "Owner's address: #{ @address }, #{ @city }, #{ @state }" + end + + # returns a collection of Owner instances + def self.all + owners = [] + CSV.read('support/owners.csv').each do |line| + owners << Bank::Owner.new(line[0], line[1], line[2], line[3], line[4], line[5]) + end + return owners end end From 904f311793d8715a3d820d5431bdd46852786614 Mon Sep 17 00:00:00 2001 From: Danielle Schrimmer Date: Thu, 25 Aug 2016 08:28:49 -0700 Subject: [PATCH 05/11] Included some optional enhancements to Wave 2. In progress: associating accounts with owners. --- account.rb | 32 ++++++++++++++++++-------------- owner.rb | 14 ++++++++++++-- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/account.rb b/account.rb index 5cdf2c9b..71768b00 100644 --- a/account.rb +++ b/account.rb @@ -6,8 +6,8 @@ class Account attr_accessor :id, :balance, :date, :accounts def initialize(id, balance, date = nil) - @id = id - @balance = balance + @id = id #account id + @balance = balance #in cents @date = date unless @balance >= 0 @@ -19,6 +19,7 @@ def add_owner(id, lname, fname, address, city, state) Bank::Owner.new(id, lname, fname, address, city, state) end + #withdraws specified amount, will not allow withdrawl if remaining balance is less than 0. def withdraw(amount) if amount <= @balance @balance -= amount @@ -29,6 +30,7 @@ def withdraw(amount) end end + #deposits specified amount def deposit(amount) @balance += amount return @balance @@ -45,23 +47,25 @@ def self.all # returns an instance of Account where value of the id matches the parameter def self.find(id) - self.all.each do |i| + all.each do |i| if i.id == id return i end end - puts "No account with this id number." + puts "No account with ID ##{ id }." + end + + ### am able to retrieve account/owner information but have not yet been able to associate them and combine stored values ### + # creates relationship between accounts and owners + def self.acct_with_owner + owner_accounts = [] + CSV.read('support/account_owners.csv').each do |line| + puts Account.find(line[0].to_i) + puts Owner.find(line[1].to_i) + # owner_accounts << (Account.find(line[0].to_i), Owner.find(line[1].to_i)) + end + owner_accounts end end end - -# a = Bank::Account.new(1234, 40) -# o = a.add_owner("danielle", "909 green way", 5555555) -# o.owner_info -# a.deposit(10) -# a.balance -# a.withdraw(60) -# a.balance -# a.withdraw(30) -# a.balance diff --git a/owner.rb b/owner.rb index 86b67da2..c7874dda 100644 --- a/owner.rb +++ b/owner.rb @@ -2,7 +2,7 @@ module Bank class Owner - attr_accessor :name, :address, :phone + attr_accessor :id, :last_name, :first_name, :address, :city, :state def initialize(id, lname, fname, address, city, state) @id = id @@ -23,10 +23,20 @@ def owner_info def self.all owners = [] CSV.read('support/owners.csv').each do |line| - owners << Bank::Owner.new(line[0], line[1], line[2], line[3], line[4], line[5]) + owners << Bank::Owner.new(line[0].to_i, line[1], line[2], line[3], line[4], line[5]) end return owners end + # returns an instance of Owner based on id parameter + def self.find(id) + all.each do |i| + if i.id == id + return i + end + end + puts "There is no owner with ID ##{ id }." + end + end end From 96cf455c2cbe689c20241422e0ce529d64ec698b Mon Sep 17 00:00:00 2001 From: Danielle Schrimmer Date: Thu, 25 Aug 2016 14:59:14 -0700 Subject: [PATCH 06/11] Includes basic savings account functionalities and updates account to return withdraw outside of loop. --- account.rb | 3 +-- savingsaccount.rb | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 savingsaccount.rb diff --git a/account.rb b/account.rb index 71768b00..1c2cd608 100644 --- a/account.rb +++ b/account.rb @@ -23,11 +23,10 @@ def add_owner(id, lname, fname, address, city, state) def withdraw(amount) if amount <= @balance @balance -= amount - return @balance else puts "Your account does not contain enough to withdraw the amount requested." - return @balance end + return @balance end #deposits specified amount diff --git a/savingsaccount.rb b/savingsaccount.rb new file mode 100644 index 00000000..f6c74125 --- /dev/null +++ b/savingsaccount.rb @@ -0,0 +1,34 @@ +require_relative 'account' + +class SavingsAccount < Bank::Account + attr_accessor :id, :balance, :date + + def initialize(id, balance, date) + @id = id + @balance = balance + @date = date + + unless @balance >= 1000 + raise ArgumentError.new("A new account cannot be created with less than $10.") + end + end + + def withdraw(amount) + transaction_fee = 200 + total_cost = amount + transaction_fee + if total_cost <= @balance && @balance - total_cost >=1000 + @balance -= total_cost + else + puts "Your account does not contain enough to withdraw the amount requested. You must maintain a $10 minimum balance in your Savings Account." + end + return @balance + end + + def add_interest(rate = 0.25) + interest = @balance * rate/100 + @balance += interest + return interest + end +end + +a = SavingsAccount.new(123, 1001, "hello") From b0f1238e111cc46674935add0f83dedaa75e2646 Mon Sep 17 00:00:00 2001 From: Danielle Schrimmer Date: Thu, 25 Aug 2016 15:56:58 -0700 Subject: [PATCH 07/11] Add basic functionality of checking account and comments to both files --- checkingaccount.rb | 39 +++++++++++++++++++++++++++++++++++++++ savingsaccount.rb | 4 ++-- 2 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 checkingaccount.rb diff --git a/checkingaccount.rb b/checkingaccount.rb new file mode 100644 index 00000000..deb1ed15 --- /dev/null +++ b/checkingaccount.rb @@ -0,0 +1,39 @@ +require_relative 'account' + +class CheckingAccount < Bank::Account + attr_accessor :checks_remaining + + def initialize(id, balance, date) + super(id, balance, date) + @checks_remaining = 3 + end + + # withdrawl with $1 fee, balance cannot go below $0 + def withdraw(amount) + transaction_fee = 100 #in cents + total_cost = amount + transaction_fee + if total_cost <= @balance + @balance -= total_cost + else + puts "Your account does not contain enough to withdraw the amount requested." + end + return @balance + end + + # withdrawl with $2 fee if more than 3 checks used, cannot withdraw more than $10 below current balance + def withdraw_using_check(amount) + amount += 200 if @checks_remaining <= 0 + if amount <= @balance + 1000 + @balance -= amount + @checks_remaining -= 1 + else + puts "Your account does not contain enough to withdraw the amount requested. You may not overdraft more than $10." + end + return @balance + end + + # resets check count to avoid $2 transaction fee + def reset_checks + @checks_remaining = 3 + end +end diff --git a/savingsaccount.rb b/savingsaccount.rb index f6c74125..8df609b4 100644 --- a/savingsaccount.rb +++ b/savingsaccount.rb @@ -13,6 +13,7 @@ def initialize(id, balance, date) end end + # withdrawl fee $2, must maintain $10 minimum balance in account def withdraw(amount) transaction_fee = 200 total_cost = amount + transaction_fee @@ -24,11 +25,10 @@ def withdraw(amount) return @balance end + # add interest rate as specified or default 0.25, returns interest def add_interest(rate = 0.25) interest = @balance * rate/100 @balance += interest return interest end end - -a = SavingsAccount.new(123, 1001, "hello") From bfa60f0ea20c3ed179cffa2cd473bea8f229a751 Mon Sep 17 00:00:00 2001 From: Danielle Schrimmer Date: Fri, 26 Aug 2016 10:14:05 -0700 Subject: [PATCH 08/11] Implement minimum balance and transaction fee constats. --- account.rb | 6 ++++-- checkingaccount.rb | 7 ++++--- savingsaccount.rb | 14 ++++++++------ 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/account.rb b/account.rb index 1c2cd608..63dbd23d 100644 --- a/account.rb +++ b/account.rb @@ -3,6 +3,8 @@ module Bank class Account + MINIMUM_BALANCE = 0 + attr_accessor :id, :balance, :date, :accounts def initialize(id, balance, date = nil) @@ -10,8 +12,8 @@ def initialize(id, balance, date = nil) @balance = balance #in cents @date = date - unless @balance >= 0 - raise ArgumentError.new("A new account cannot be created with initial negative balance.") + unless @balance >= Bank::Account::MINIMUM_BALANCE + raise ArgumentError.new("A new account cannot be created with less than $#{ MINIMUM_BALANCE }.") end end diff --git a/checkingaccount.rb b/checkingaccount.rb index deb1ed15..40e01925 100644 --- a/checkingaccount.rb +++ b/checkingaccount.rb @@ -1,6 +1,8 @@ require_relative 'account' class CheckingAccount < Bank::Account + TRANSACTION_FEE = 100 # cents + attr_accessor :checks_remaining def initialize(id, balance, date) @@ -10,9 +12,8 @@ def initialize(id, balance, date) # withdrawl with $1 fee, balance cannot go below $0 def withdraw(amount) - transaction_fee = 100 #in cents - total_cost = amount + transaction_fee - if total_cost <= @balance + total_cost = amount + TRANSACTION_FEE + if (@balance) - total_cost >= MINIMUM_BALANCE @balance -= total_cost else puts "Your account does not contain enough to withdraw the amount requested." diff --git a/savingsaccount.rb b/savingsaccount.rb index 8df609b4..b873e6da 100644 --- a/savingsaccount.rb +++ b/savingsaccount.rb @@ -1,6 +1,9 @@ require_relative 'account' class SavingsAccount < Bank::Account + MINIMUM_BALANCE = 1000 # in cents + TRANSACTION_FEE = 200 # in cents + attr_accessor :id, :balance, :date def initialize(id, balance, date) @@ -8,19 +11,18 @@ def initialize(id, balance, date) @balance = balance @date = date - unless @balance >= 1000 - raise ArgumentError.new("A new account cannot be created with less than $10.") + unless @balance >= self.class::MINIMUM_BALANCE + raise ArgumentError.new("A new account cannot be created with less than $#{ '%.2f' % (self.class::MINIMUM_BALANCE / 100.0) }.") end end - # withdrawl fee $2, must maintain $10 minimum balance in account + # maintain $10 minimum balance in account including transaction fee def withdraw(amount) - transaction_fee = 200 - total_cost = amount + transaction_fee + total_cost = amount + TRANSACTION_FEE if total_cost <= @balance && @balance - total_cost >=1000 @balance -= total_cost else - puts "Your account does not contain enough to withdraw the amount requested. You must maintain a $10 minimum balance in your Savings Account." + puts "Your account does not contain enough to withdraw the amount requested. You must maintain a $#{ '%.2f' % (self.class::MINIMUM_BALANCE / 100.0) } minimum balance in your Savings Account." end return @balance end From f37ddb461cb48d286858c589a2ccaf21e0fc5ee3 Mon Sep 17 00:00:00 2001 From: Danielle Schrimmer Date: Fri, 26 Aug 2016 10:20:01 -0700 Subject: [PATCH 09/11] Add overdraft constat --- checkingaccount.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/checkingaccount.rb b/checkingaccount.rb index 40e01925..9c5baba8 100644 --- a/checkingaccount.rb +++ b/checkingaccount.rb @@ -2,6 +2,8 @@ class CheckingAccount < Bank::Account TRANSACTION_FEE = 100 # cents + CHECK_WITHDRAWL_FEE = 200 # cents + MAX_OVERDRAFT = 1000 # cents attr_accessor :checks_remaining @@ -21,19 +23,19 @@ def withdraw(amount) return @balance end - # withdrawl with $2 fee if more than 3 checks used, cannot withdraw more than $10 below current balance + # withdrawl fee activated if more than 3 checks used, overdraft limit def withdraw_using_check(amount) - amount += 200 if @checks_remaining <= 0 - if amount <= @balance + 1000 + amount += CHECK_WITHDRAWL_FEE if @checks_remaining <= 0 + if amount <= @balance + MAX_OVERDRAFT @balance -= amount @checks_remaining -= 1 else - puts "Your account does not contain enough to withdraw the amount requested. You may not overdraft more than $10." + puts "Your account does not contain enough to withdraw the amount requested. You may not overdraft more than $#{ '%.2f' % (MAX_OVERDRAFT / 100.0)}." end return @balance end - # resets check count to avoid $2 transaction fee + # resets check count to avoid transaction fee def reset_checks @checks_remaining = 3 end From 55e74af9c0017b68a0af44f191f80596d9a21259 Mon Sep 17 00:00:00 2001 From: Danielle Schrimmer Date: Fri, 26 Aug 2016 10:36:50 -0700 Subject: [PATCH 10/11] Use parent class withdrawl method with updated amount incl. transaction fee. --- checkingaccount.rb | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/checkingaccount.rb b/checkingaccount.rb index 9c5baba8..8e193e2f 100644 --- a/checkingaccount.rb +++ b/checkingaccount.rb @@ -12,15 +12,10 @@ def initialize(id, balance, date) @checks_remaining = 3 end - # withdrawl with $1 fee, balance cannot go below $0 + # withdrawl with transaction fee def withdraw(amount) - total_cost = amount + TRANSACTION_FEE - if (@balance) - total_cost >= MINIMUM_BALANCE - @balance -= total_cost - else - puts "Your account does not contain enough to withdraw the amount requested." - end - return @balance + amount += TRANSACTION_FEE + super(amount) end # withdrawl fee activated if more than 3 checks used, overdraft limit From 35c8ddb257953ee50a50d218b4854e12e2629e96 Mon Sep 17 00:00:00 2001 From: Danielle Schrimmer Date: Fri, 26 Aug 2016 10:50:03 -0700 Subject: [PATCH 11/11] Adjust withdraw method in account to account for minimum balance to reuse super method in savings account. --- account.rb | 2 +- savingsaccount.rb | 13 ++++--------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/account.rb b/account.rb index 63dbd23d..5165e092 100644 --- a/account.rb +++ b/account.rb @@ -23,7 +23,7 @@ def add_owner(id, lname, fname, address, city, state) #withdraws specified amount, will not allow withdrawl if remaining balance is less than 0. def withdraw(amount) - if amount <= @balance + if amount <= @balance && (@balance - amount >= self.class::MINIMUM_BALANCE) @balance -= amount else puts "Your account does not contain enough to withdraw the amount requested." diff --git a/savingsaccount.rb b/savingsaccount.rb index b873e6da..1fa7f676 100644 --- a/savingsaccount.rb +++ b/savingsaccount.rb @@ -16,18 +16,13 @@ def initialize(id, balance, date) end end - # maintain $10 minimum balance in account including transaction fee + # maintain minimum balance in account including transaction fee def withdraw(amount) - total_cost = amount + TRANSACTION_FEE - if total_cost <= @balance && @balance - total_cost >=1000 - @balance -= total_cost - else - puts "Your account does not contain enough to withdraw the amount requested. You must maintain a $#{ '%.2f' % (self.class::MINIMUM_BALANCE / 100.0) } minimum balance in your Savings Account." - end - return @balance + amount += TRANSACTION_FEE + super(amount) end - # add interest rate as specified or default 0.25, returns interest + # add interest rate as specified or default, returns interest def add_interest(rate = 0.25) interest = @balance * rate/100 @balance += interest