forked from AdaGold/BankAccounts
-
Notifications
You must be signed in to change notification settings - Fork 38
Alison's Bank Accounts #47
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
Open
AlisonZ
wants to merge
33
commits into
Ada-C7:master
Choose a base branch
from
AlisonZ:master
base: 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
33 commits
Select commit
Hold shift + click to select a range
b092c16
sets up initial structure of module and class
AlisonZ a7faa32
adds show balance method and verifies that new objects are being inst…
AlisonZ 8f64dba
working withdraw method, needs to be tested with spec file
AlisonZ 9d1ca5b
withdraw method works and passes tests
AlisonZ 5d96b68
deposit feature working and passes tests
AlisonZ 66f4bf0
adds error for negative starting balances and all tests for Wave 1 ar…
AlisonZ 546ff3b
phase one features are working
AlisonZ 87df7fe
phase one is working and passes all tests
AlisonZ 1131b7a
code and tests for self.all are working thanks to chris video
AlisonZ ae34958
find tests for verifying an account and that the first matches the cs…
AlisonZ d24e5e5
wave one working except for open dates
AlisonZ d9f47c4
there is a new class savings that inherits from account and passes th…
AlisonZ 440ea50
holy cow the initialize works and i just wrote a test before code and…
AlisonZ e84065a
transaction fee is working and the test is all green
AlisonZ 8184e59
withdraw fee tests and code works
AlisonZ 339a8ca
not letting withdraws happen if fee would put account under 10; tests…
AlisonZ 9030ecf
holy cow all of the tests and code for savings account work
AlisonZ cac59ee
savings account interest is being tracked and tests all work.
AlisonZ 102fed7
changed interest to a local variable, tests still pass, savings accou…
AlisonZ e27d6b0
tests and code working for initializing and fee for withdraw method
AlisonZ b736ce5
trying to make variables of minimum and fee to share the load of with…
AlisonZ 4fcfd35
woohooooooo savings and checking withdraw are inheriting stuff from t…
AlisonZ dbfd30d
withdraw tests all done for checking working
AlisonZ cb2b142
test for withdraw using check working and new balance is being returned
AlisonZ 5008cf3
does not allow to go below -10
AlisonZ 3994ad1
doesn't allow to withdraw below -10 and requires a positive withdraw …
AlisonZ 760dae0
allows three free checks; there are some warnings about unused variab…
AlisonZ 3417c20
withdraw_using_checks method is a go
AlisonZ 88bacf4
reset checks method working
AlisonZ 221f959
all working, no errors.
AlisonZ 744f595
adds final forgotten test in savings spec. baseline is finished and e…
AlisonZ 664da91
managed merge conflict
AlisonZ 61f6739
submittinh hwk
AlisonZ 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
This file contains hidden or 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,83 @@ | ||
| #this is the new, second try at this | ||
| require "csv" | ||
| module Bank | ||
| class Account | ||
| attr_accessor :id, :balance, :opendate | ||
| def initialize (id, balance, opendate = nil ) | ||
| raise ArgumentError.new("You need some positive cash flow to open an account") if balance < 0 | ||
| @id = id | ||
| @balance = balance | ||
| @opendate = opendate | ||
| end | ||
|
|
||
|
|
||
| def self.all | ||
| accounts = [] | ||
|
|
||
| CSV.read("support/accounts.csv").each do |line| | ||
| id = line[0].to_i | ||
| balance = line[1].to_i | ||
| opendate = line[2] | ||
| account = Bank::Account.new(id, balance, opendate) | ||
| accounts << account | ||
| end | ||
| return accounts | ||
| end | ||
|
|
||
|
|
||
| def self.find(id) | ||
| accounts = Bank::Account.all | ||
| accounts.each do |account| | ||
| if account.id.to_i == id | ||
| return account | ||
| end | ||
| end | ||
| raise ArgumentError.new("this is not an account in our system") | ||
| end | ||
|
|
||
| def fee | ||
| 0 | ||
| end | ||
|
|
||
| def minimum | ||
| 0 | ||
| end | ||
|
|
||
|
|
||
| def withdraw (amount) | ||
| if amount > 0 | ||
| if @balance - amount < 0 || @balance - amount < minimum || @balance - (amount + fee) < minimum | ||
| puts "You do not have enough money to withdraw this amount" | ||
| else | ||
| @balance -=(amount + fee) | ||
| end | ||
| else | ||
| raise ArgumentError.new("You can only withdraw a positive amount of money") | ||
| end | ||
| return @balance | ||
| end | ||
|
|
||
|
|
||
| def deposit (amount) | ||
| if amount > 0 | ||
| @balance +=amount | ||
| return @balance | ||
| else | ||
| raise ArgumentError.new("need positive amt") | ||
| end | ||
|
|
||
| end | ||
|
|
||
|
|
||
| def show_balance | ||
| return @balance | ||
| end | ||
|
|
||
| end | ||
| end | ||
|
|
||
|
|
||
| # my_account = Bank::Account.new(16, 1000) | ||
| # puts my_account.show_balance | ||
| # puts my_account.withdraw(1200) | ||
|
|
||
This file contains hidden or 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,50 @@ | ||
| #creates a new subclass of Account class that is | ||
| require_relative 'account.rb' | ||
| module Bank | ||
| class CheckingAccount < Account | ||
| def initialize (id, balance, opendate = nil) | ||
| #super sets the instance variables found in the Account initialize method | ||
| super | ||
| @check_counter = 0 | ||
| end | ||
|
|
||
|
|
||
| #method which returns 1, so fee for any object in checking account is now 1 | ||
| def fee | ||
|
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. Interesting how you used this for the inheritance in Checking & Savings. |
||
| 1 | ||
| end | ||
|
|
||
| #method which returns 0 for the minimum for a checking account is now 0 | ||
| def minimum | ||
| 0 | ||
| end | ||
|
|
||
|
|
||
|
|
||
| def withdraw_using_check(amount) | ||
| check_fee = 0 | ||
|
|
||
| if @check_counter >= 3 | ||
| check_fee = 2 | ||
| end | ||
|
|
||
| if amount < 0 | ||
| puts "You must withdraw a positive amount" | ||
| else | ||
| if @balance - (amount + check_fee) < -10 | ||
| puts "You do not have enough money in your account for this" | ||
| else | ||
| @check_counter +=1 | ||
| @balance -=(amount + check_fee) | ||
| return @balance | ||
| end | ||
| end | ||
| end | ||
|
|
||
|
|
||
| def reset_checks | ||
| @check_counter = 0 | ||
| end | ||
| end | ||
|
|
||
| end | ||
This file contains hidden or 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,33 @@ | ||
| require_relative 'account.rb' | ||
|
|
||
| module Bank | ||
| class SavingsAccount < Account | ||
| def initialize (id, balance, opendate = nil) | ||
| super | ||
| # @fee = 2 | ||
| # @minimum = 10 | ||
| raise ArgumentError.new("You must have at least $10") if balance < 10 | ||
| end | ||
|
|
||
|
|
||
| def fee | ||
| 2 | ||
| end | ||
|
|
||
| def minimum | ||
| 10 | ||
| end | ||
|
|
||
|
|
||
| def add_interest(rate) | ||
| if rate > 0 | ||
| interest = @balance * rate/100 | ||
| @balance += interest | ||
| return interest | ||
| else | ||
| puts "Rate must be a positive amount" | ||
| end | ||
| end | ||
|
|
||
| end | ||
| end |
This file contains hidden or 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
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.
a more standard name would be
@open_date