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

Bank Account Wave 3 #60

Open
wants to merge 17 commits into
base: ald/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
43 changes: 29 additions & 14 deletions Bank_Account.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'pry'
require 'csv'

module Bank
require 'pry'
require 'csv'

class Account

Expand All @@ -14,13 +13,14 @@ def initialize(account_id, balance, open_date, owner = nil)
@balance = balance.to_i
@open_date = open_date
@owner = owner
@withdrawalfee = 0

Choose a reason for hiding this comment

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

I like that you're using a variable to store this fee

@@account_list.push(self)

Choose a reason for hiding this comment

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

WHOA SLICK

confirm_initial_balance
account_info
end

def confirm_initial_balance
if @balance < 0 #Can improve on this later
if @balance < 0
raise ArgumentError.new("Balance must be integer value 0 or greater.")
end
end
Expand All @@ -35,23 +35,23 @@ def add_owner(owner) #adds owner from an existing owner, rather than making a ne
puts "\n#{@owner.first_name} is now the owner of account \##{@account_id}.\n"
end

def withdraw(withdrawal_amount)
# print "\nEnter value to be withdrawn: "
# withdrawal_amount = gets.chomp.to_i
if withdrawal_amount > @balance
puts "\nWithdrawal denied."
puts "Balance: #{@balance}\n"
return @balance
def reject_withdrawal

Choose a reason for hiding this comment

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

Nice use of a separate method to handle the withdrawal rejection

puts "\nWithdrawal denied."
puts "Balance: #{@balance}\n"
return @balance
end

def withdraw(withdrawal_amount, withdrawalcap = @balance)
if (withdrawal_amount + @withdrawalfee) > withdrawalcap
reject_withdrawal
else
@balance = @balance - withdrawal_amount
@balance -= withdrawal_amount + @withdrawalfee
puts "\nBalance after withdrawal: #{@balance}\n"
return @balance
end
end

def deposit(deposit_amount)
# print "\nEnter value to be deposited: "
# deposit_amount = gets.chomp.to_i
@balance = @balance + deposit_amount
puts "\nBalance after deposit: #{@balance}\n"
return @balance

Choose a reason for hiding this comment

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

In the generate_accounts method below, I would recommend using a more explicit variable name other than a

Expand Down Expand Up @@ -79,6 +79,16 @@ def self.find(id) #returns an instance of Account where the value of the id fiel
end
puts "\n#{idmatch}"
puts idmatch.balance

Choose a reason for hiding this comment

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

When we use variables with more than one "word" we should separate those with the _ so this should be id_match

return idmatch
end

def self.match_account_to_owner(account_owner, owner_list = Owner.read_owner_list)
account_owner.each do |a|
account = self.find(a[0]) #this is an account object that matches the csv
#now find owner
owner = Owner.find(a[1]) #this is the owner object
account.add_owner(owner) #add the corresponding owner to the account
end
end
end

Expand All @@ -99,6 +109,10 @@ def initialize(owner_id, last_name, first_name, street_address, city, state)
owner_info
end

def self.read_owner_list
@@owner_list
end

def owner_info
puts "\n Owner ID: #{@owner_id}"
puts " First name: #{@first_name}"
Expand All @@ -123,6 +137,7 @@ def self.find(id) #returns an instance of Account where the value of the id fiel
end

Choose a reason for hiding this comment

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

For the line above, do you think that ID should be stored as a string or an integer?

puts "\n#{idmatch}"
puts "\n#{idmatch.last_name}"
return idmatch
end

end
Expand Down
4 changes: 4 additions & 0 deletions Bank_master.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#use this file to combine required files
require './Bank_account.rb'
require './Savings_account.rb'
require './Checking_account.rb'
39 changes: 35 additions & 4 deletions Bank_program.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#just a bunch of tests to try out Bank_master.
require 'pry'
require './Bank_Account.rb'
require 'csv'
# require ./support/accounts.csv
require './Bank_master.rb'

accounts_csv = CSV.read("./support/accounts.csv")
owners_csv = CSV.read("./support/owners.csv")
account_owners_csv = CSV.read("./support/account_owners.csv")

#make a bank account manually
acct = Bank::Account.new(1212, 1235667, "1999-03-27 11:30:09 -0800")
acct = Bank::Account.new(1212, 1000, "1999-03-27 11:30:09 -0800")


#withdraw money
Expand All @@ -18,6 +20,7 @@
#check amount in account
acct.check_balance

acct.withdraw(1000)

lizzie = Bank::Owner.new(123, "Borden", "Lizzie", "453 Magpie Lane", "Wilhelm", "MA")

Expand All @@ -35,6 +38,34 @@
Bank::Owner.generate_owners(owners_csv)
Bank::Owner.all
Bank::Owner.find(15)

puts "line 41ish"

#now pair up the owners and accounts
Bank::Account.match_account_to_owner(account_owners_csv)
Bank::Account.all


newsavings = Bank::SavingsAccount.new(23232, 1000,"1999-03-23 11:30:09 -0700")
Bank::Account.all
puts "line 49ish"
puts newsavings.balance.to_s
puts

toolowsavings = Bank::SavingsAccount.new(23232, 999,"1999-03-27 11:30:09 -0700")

newsavings.withdraw(20)
newsavings.deposit(22)
newsavings.add_interest(0.25)
newsavings.add_interest(10)
newsavings.withdraw(100000)

newchecking = Bank::CheckingAccount.new(34234, 20,"1989-03-23 11:30:09 -0700")
Bank::Account.all
puts newchecking.balance.to_s
newchecking.withdraw(19)
puts "Line 62ish"
newchecking.deposit(20)
newchecking.withdraw_using_check(10)
newchecking.withdraw_using_check(10)
newchecking.withdraw_using_check(10)
newchecking.withdraw_using_check(10)
44 changes: 44 additions & 0 deletions Checking_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module Bank
require 'pry'
require 'csv'

class CheckingAccount < Account
attr_reader :checks

def initialize (account_id, balance, open_date, owner = nil)
super(account_id, balance, open_date, owner = nil)
@withdrawalfee = 100
@withdrawalfee_nochecks = 200
@checks = 300

Choose a reason for hiding this comment

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

Should the checks be set to 300 or 3?

end

def withdraw_using_check(withdrawal_amount)
#I'm assuming that a withdrawal with a free check incurs $0 transaction fee, unlike regular withdrawals
if @checks > 0
if withdrawal_amount > (@balance + 1000)
reject_withdrawal
else
@checks -= 1
@balance -= withdrawal_amount
puts "\nBalance after withdrawal: #{@balance}\n"
puts @checks
return @balance
end
#if you don't have checks
else
if (withdrawal_amount + @withdrawalfee_nochecks) > (@balance + 1000)
reject_withdrawal

Choose a reason for hiding this comment

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

Nice job using the reject_withdrawal method from your Account class here

else
@balance -= withdrawal_amount + @withdrawalfee_nochecks
puts "\nBalance after withdrawal: #{@balance}\n"
return @balance
end
end
end


def reset_checks
@checks = 3
end
end
end
21 changes: 21 additions & 0 deletions Money_market_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Bank
require 'pry'

class MoneyMarketAccount < Account
attr_reader :checks, :transactions

def initialize (account_id, balance, open_date, owner = nil)
super(account_id, balance, open_date, owner = nil)

Choose a reason for hiding this comment

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

I don't think you need the owner = nil here since the optional parameter should take care of assigning the value above

@withdrawalfee = 1
@min_initial_balance = 10000
@transactions = 6

Choose a reason for hiding this comment

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

Since you use the max transactions throughout, this might be a good place to use a constant variable

end

def add_interest(rate)
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
-->
31 changes: 31 additions & 0 deletions Savings_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Bank
require 'pry'
require 'csv'
class SavingsAccount < Account

#change initialize class for the purpose of modifying withdrawal behavior
def initialize (account_id, balance, open_date, owner = nil)
super(account_id, balance, open_date, owner = nil)
@withdrawalfee = 200
end

# The initial balance cannot be less than $10. If it is, this will raise an ArgumentError
def confirm_initial_balance
if @balance < 1000
raise ArgumentError.new("Balance must be integer value 1000 or greater.")
end
end

def withdraw(withdrawal_amount, withdrawalcap = (@balance - 1000))

Choose a reason for hiding this comment

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

Can the user pass in their own withdrawal cap value? That seems like it would have unintended behavior based on the way you would want this to work

super(withdrawal_amount, withdrawalcap)
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.

Watch your indentation here, add one additional indent

@balance = @balance + interest
puts @balance.to_i.to_s
puts interest.to_i.to_s
return interest.to_i
end
end
end