forked from AdaGold/BankAccounts
-
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
Wave 3 Bank Account #68
Open
hougland
wants to merge
11
commits into
Ada-C4:rlh/master
Choose a base branch
from
hougland:rlh/master
base: rlh/master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b79bdfe
Add wave 3
kariabancroft 4c57049
?
hougland 0d7f655
Merge remote-tracking branch 'upstream/master' into rlh/master
hougland 28220dc
first draft of initial files for wave 3
hougland 8f46c8a
adding random file that I don't really know what it is
hougland f69da1b
added checking account file and updated withdrawl functionality
hougland 9a96fcf
finished adding withdraw_using_check(amount) functionality
hougland 7a9d54b
finished primary requirements for W3
hougland 33383c3
added MoneyMarketAccount and started building withdraw method
hougland 3c701ac
finished first draft of all optional pieces
hougland 8fa8639
finished what I'll be able to do before Tuesday.
hougland File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Bank | ||
|
||
class MoneyMarketAccount < SavingsAccount | ||
attr_reader :transactions | ||
|
||
def initialize(id, balance, open_date) | ||
@account_id = id.to_i | ||
@balance = balance.to_i * 100 | ||
@open_date = open_date | ||
@mm_account_fee = 0 | ||
@transactions = 6 | ||
@act_withdraw_fee = 100_00 | ||
@mm_min_balance = 10_000_00 | ||
@min_balance = 0 | ||
|
||
if @balance < @mm_min_balance | ||
raise StandardError, "You cannot open an account with that little money." | ||
end | ||
|
||
end | ||
|
||
def withdraw(amount) | ||
if @balance >= @mm_min_balance | ||
if @transactions > 0 | ||
super | ||
@transactions -= 1 | ||
end | ||
else | ||
puts "You must deposit at least #{@mm_min_balance - @balance} before you can withdraw any more." | ||
end | ||
end | ||
|
||
def reset_transactions | ||
@transactions = 6 | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
module Bank | ||
|
||
class Account | ||
attr_reader :balance, :account_id, :owner, :all_accounts, :open_date | ||
|
||
def initialize(id, balance, open_date) | ||
|
||
@account_id = id | ||
@balance = balance * 100 | ||
@open_date = open_date | ||
@min_balance = 0 | ||
@act_withdraw_fee = 0 | ||
|
||
if balance.to_i < @min_balance | ||
raise StandardError, "You cannot open an account with that little money." | ||
end | ||
end | ||
|
||
def withdraw(withdraw_amt) | ||
withdraw_to_cents = withdraw_amt * 100 | ||
|
||
if (@balance - withdraw_to_cents) < (@min_balance + @act_withdraw_fee) | ||
puts "You cannot withdraw that much. Your current balance is #{@balance} cents" | ||
elsif @mm_min_balance > 0 | ||
if (@balance - withdraw_to_cents) > (-@mm_min_balance) | ||
@balance -= withdraw_to_cents | ||
puts "Your account balance is now #{@balance} cents." | ||
else | ||
@balance -= (withdraw_to_cents + @act_withdraw_fee) | ||
puts "You've withdrawn your account below #{@mm_min_balance}, so you'll be charged #{@act_withdraw_fee} cents." | ||
puts "You must deposit enough for your account to be above #{@mm_min_balance} cents before you can withdraw any more." | ||
puts "Your new balance is #{@balance} cents." | ||
end | ||
else | ||
@balance -= (withdraw_to_cents + @act_withdraw_fee) | ||
puts "Your account balance is now #{@balance} cents." | ||
end | ||
end | ||
|
||
def deposit(deposit_amt) | ||
deposit_to_cents = deposit_amt * 100 | ||
|
||
if @mm_min_balance > 0 | ||
if @balance >= 10_000_00 | ||
@balance += deposit_to_cents | ||
puts "Your previous account balance was #{@balance - deposit_to_cents} cents." | ||
puts "It is now #{@balance} cents." | ||
@transactions -= 1 | ||
elsif @balance + deposit_to_cents >= 10_000_00 | ||
@balance += deposit_to_cents | ||
puts "Your previous account balance was #{@balance - deposit_to_cents} cents." | ||
puts "It is now #{@balance} cents." | ||
else | ||
@balance += deposit_to_cents | ||
@transactions -= 1 | ||
puts "Your previous account balance was #{@balance - deposit_to_cents} cents." | ||
puts "It is now #{@balance} cents." | ||
puts "You still need to deposit #{@mm_min_balance - @balance} before you can withdraw any more." | ||
end | ||
|
||
else | ||
@balance += deposit_to_cents | ||
puts "Your previous account balance was #{@balance - deposit_to_cents} cents." | ||
puts "It is now #{@balance} cents." | ||
end | ||
end | ||
|
||
def show_balance | ||
puts "Your current balance is #{@balance} cents" | ||
end | ||
|
||
def assign_owner(first_name, last_name, address) | ||
@owner = Bank::Owner.new(first_name, last_name, address) | ||
end | ||
|
||
def self.all | ||
@all_accounts = [] | ||
|
||
CSV.read("./support/accounts.csv").each do |line| | ||
y = Bank::Account.new(line[0].to_i, line[1].to_i, line[2]) | ||
@all_accounts.push(y) | ||
end | ||
|
||
return @all_accounts | ||
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. By using an instance variable in a class method this could be a tricky scenario if you try to use this instance variable again later without first calling this class method where the variable is set |
||
end | ||
|
||
def self.find(id) | ||
Bank::Account.all.find do |account_instance| | ||
account_instance.account_id == id | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,122 @@ | ||
require "csv" | ||
require "pry" | ||
|
||
module Bank | ||
|
||
class Owner | ||
attr_reader :first_name, :last_name, :address | ||
|
||
def initialize(first_name, last_name, address) | ||
attr_reader :first_name, :last_name, :street_address, :owner_id | ||
|
||
def initialize(owner_id, last_name, first_name, street_address, city, state) | ||
@owner_id = id | ||
@first_name = first_name | ||
@last_name = last_name | ||
@address = address | ||
@street_address = street_address | ||
@city = city | ||
@state = state | ||
end | ||
|
||
def self.all | ||
all_owners = [] | ||
|
||
CSV.read("./support/owners.csv").each do |line| | ||
y = Bank::Owner.new(line[0].to_i, line[1], line[2], line[3], line[4], line[5]) | ||
all_owners.push(y) | ||
end | ||
|
||
return all_owners | ||
end | ||
|
||
def self.find(id) | ||
Bank::Owner.all.find do |account_instance| | ||
account_instance.owner_id == id | ||
end | ||
end | ||
end | ||
|
||
class Account | ||
attr_reader :balance, :id, :owner | ||
attr_reader :balance, :account_id, :owner, :all_accounts, :open_date | ||
|
||
def initialize(id, initial_balance) | ||
# another way of generating an error if user starts with negative balance | ||
# while initial_balance < 0 | ||
# puts "You cannot open an account in debt." | ||
# puts "Please enter a new opening balance: " | ||
# initial_balance = gets.chomp.to_i | ||
# end | ||
def initialize(id, balance, open_date) | ||
|
||
if initial_balance < 0 | ||
if balance.to_i < 0 | ||
raise StandardError, "You cannot open an account in debt." | ||
end | ||
|
||
@balance = initial_balance | ||
@id = id | ||
@account_id = id | ||
@balance = balance | ||
@open_date = DateTime.strptime(open_date, "%Y-%m-%d %H:%M:%S %Q") | ||
end | ||
|
||
def withdraw(withdraw_amt) | ||
while (@balance - withdraw_amt) < 0 | ||
puts "You cannot overdraft your account. Your current balance is $#{@balance}" | ||
puts "You cannot overdraft your account. Your current balance is #{@balance} cents" | ||
puts "Please enter a new withdrawl amount: " | ||
withdraw_amt = gets.chomp.to_i | ||
end | ||
|
||
@balance -= withdraw_amt | ||
puts "Your previous account balance was $#{@balance + withdraw_amt}." | ||
puts "It is now $#{@balance}." | ||
puts "Your previous account balance was #{@balance + withdraw_amt} cents." | ||
puts "It is now #{@balance} cents." | ||
end | ||
|
||
def deposit(deposit_amt) | ||
@balance += deposit_amt | ||
puts "Your previous account balance was $#{@balance - deposit_amt}." | ||
puts "It is now $#{@balance}." | ||
puts "Your previous account balance was #{@balance - deposit_amt} cents." | ||
puts "It is now #{@balance} cents." | ||
end | ||
|
||
def show_balance | ||
puts "Your current balance is $#{@balance}" | ||
puts "Your current balance is #{@balance} cents" | ||
end | ||
|
||
def assign_owner(first_name, last_name, address) | ||
@owner = Bank::Owner.new(first_name, last_name, address) | ||
end | ||
|
||
def self.all | ||
@all_accounts = [] | ||
|
||
CSV.read("./support/accounts.csv").each do |line| | ||
y = Bank::Account.new(line[0].to_i, line[1].to_i, line[2]) | ||
@all_accounts.push(y) | ||
end | ||
|
||
return @all_accounts | ||
end | ||
|
||
def self.find(id) | ||
Bank::Account.all.find do |account_instance| | ||
account_instance.account_id == id | ||
end | ||
end | ||
|
||
# working on this still | ||
# def self.match_owner | ||
# Bank::Account.all | ||
# | ||
# CSV.read("./support/accounts.csv").each do |line| | ||
# binding.pry | ||
# account = CSV.read("./support/account_owners.csv").find(line[0]) | ||
# owner = CSV.read("./support/owners.csv").find(account[1]) | ||
# Bank::Owner.new(owner) | ||
# end | ||
|
||
# take the account id (line[0] in each loop) and find which owners_id within account_owners.csv it shares, | ||
# then take that owners_id, switch over to the owners.cvs, and initialize a new Owner based on that | ||
|
||
# end | ||
end | ||
|
||
class SavingsAccount < Account | ||
def initialize(id, balance, open_date) | ||
super | ||
if balance.to_i < 0 | ||
raise StandardError, "You cannot open an account with less than $10." | ||
end | ||
end | ||
|
||
|
||
end | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
require "csv" | ||
require "pry" | ||
|
||
require "./account.rb" | ||
require "./savings.rb" | ||
require "./owner.rb" | ||
require "./checkingaccount.rb" | ||
require "./MoneyMarketAccount.rb" | ||
|
||
|
||
# testing to see if they work: | ||
# Account class: y | ||
# savings: y | ||
# checking: y | ||
# Money Market class: this one still has issues :( |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module Bank | ||
|
||
class CheckingAccount < Account | ||
attr_reader :free_checks | ||
|
||
def initialize(id, balance, open_date) | ||
super | ||
|
||
@act_withdraw_fee = 100 | ||
@free_checks = 3 | ||
end | ||
|
||
def withdraw(withdraw_amt) | ||
super | ||
end | ||
|
||
def withdraw_using_check(amount) | ||
withdraw_to_cents = amount * 100 | ||
|
||
if (@balance - withdraw_to_cents) < (@min_balance - 1000) | ||
puts "You cannot withdraw that much. Your current balance is #{@balance} cents" | ||
elsif @free_checks > 0 | ||
@balance -= withdraw_to_cents | ||
@free_checks -= 1 | ||
puts "Your account balance is now #{@balance} cents." | ||
else | ||
@balance -= (withdraw_to_cents + 200) | ||
puts "You already used up your free checks for this month, so you've been charged an extra $2." | ||
puts "Your new balance is #{@balance} cents." | ||
end | ||
end | ||
|
||
def reset_checks | ||
@free_checks = 3 | ||
end | ||
|
||
|
||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 would use a more meaningful variable name rather than
y