-
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
Bank Account Wave 3 #60
base: ald/master
Are you sure you want to change the base?
Changes from all commits
b79bdfe
21446c6
26cd30b
f6f3f2c
1895e8d
0a164bc
e2a3007
8aa860e
49c2b41
e9611d8
5502c52
744b04b
0e440e1
282de13
0ae6743
3bae0c5
12cc77e
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,7 +1,6 @@ | ||
require 'pry' | ||
require 'csv' | ||
|
||
module Bank | ||
require 'pry' | ||
require 'csv' | ||
|
||
class Account | ||
|
||
|
@@ -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 | ||
@@account_list.push(self) | ||
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. 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 | ||
|
@@ -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 | ||
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. 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 | ||
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. In the |
||
|
@@ -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 | ||
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. When we use variables with more than one "word" we should separate those with the |
||
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 | ||
|
||
|
@@ -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}" | ||
|
@@ -123,6 +137,7 @@ def self.find(id) #returns an instance of Account where the value of the id fiel | |
end | ||
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. 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 | ||
|
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' |
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 | ||
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. 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 | ||
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. Nice job using the |
||
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 |
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) | ||
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 don't think you need the |
||
@withdrawalfee = 1 | ||
@min_initial_balance = 10000 | ||
@transactions = 6 | ||
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 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 |
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)) | ||
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. 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 | ||
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, 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 |
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.
I like that you're using a variable to store this fee