forked from AdaGold/BankAccounts
-
Notifications
You must be signed in to change notification settings - Fork 38
Ashton's Bank Account #31
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
ashtn
wants to merge
48
commits into
Ada-C7:master
Choose a base branch
from
ashtn: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
48 commits
Select commit
Hold shift + click to select a range
f7f6582
Added skip to specs document to create space on terminal& 1st test ca…
0840db6
2nd test case passed
858f111
Fu=irst test case and 3 assertions passed
06dd983
first test case and 3 asserstions passed
72f2817
Withdraw test case passed
241938e
giving up for now
0e4b4d9
Yay, they passed, that pesky put slash print
4e5531d
Account.all returns an array, so exciteing, but my code is a hot mess
e097a96
refactoring spec code, to account for account hash
3c8be93
All of wave 1 is refactored for account hash
711fc66
5 of 6 .all assertions passed
60e0560
Started Account.find - code and test are broken though
fff6b59
Added before and @accounts to specs, 2 assertions in wave 2 pass
3198a9d
.find works in .rb file yayyyy
d8a3da0
Whooo return an account that exits, thanks chris
02c15ad
Wave 2 complete
feecde5
specs uncommented out
732ff2d
Created Savings and Checking class stubs
c40b4d5
refactored spec to account for hash, first test passed
d4af7a6
passed first savings account test
e63333c
Withdraw test writted for checking account
b34ced5
Withdraw applies 1 dollar fee in checking
7eec7ed
Balance is not modified on attempted overdraft in checking
654a604
Savings account starting balance less than 10 raises error
8920e59
Savings Withdaw applies 2 dollar fee
79d1cad
Outputs warning at attempted overdraft
bc499cd
Savings withdraw applies 2 dollar fee
3f36b43
savings outputs warning message on attempted overdraft
553a1bc
savings doesnt modify balance at attempted over draft
a50dacb
savings fee, will no modify or overdraft account
c354aba
check_withdraw reduces balance
a8ed7eb
check_withdraw returns modified balance
fc915f2
check_withdraw allows balance to reach -10
5f754b4
edit to check_withdraw method to allow balance to reach -10
9229fee
test commit with git add .
446e26c
checking account doesnt modify account in attempted overdraft
6497ef8
check_withdraw requires postive number
42093a0
check_withdraw allow 3 free uses
0e81240
check_withdraw method passed all tests
fa9c1b4
forgot to add checking.rb
86050bd
Specs for Checking_account subclass have all passed
b09c465
add_interest returns calculated interst
2170655
add_interest updates balance with interest
84b3933
all tests are complete for savings sub class
71347e6
Fixed savings withdraw false pass
45590b3
refactored account initialize
6309173
refactored savings.rb
5d1990b
checking if github is linked
ashtn 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 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,91 @@ | ||
| require 'csv' | ||
| require 'pry' | ||
|
|
||
|
|
||
|
|
||
| module Bank | ||
|
|
||
| class Account | ||
|
|
||
| attr_accessor :balance | ||
| attr_accessor :id, :opendatetime#, :accounts | ||
|
|
||
| @@accounts = nil | ||
| def initialize(account_hash) | ||
|
|
||
| @id = account_hash[:id].to_i | ||
| @balance = account_hash[:balance].to_i | ||
| @opendatetime = account_hash[:opendatetime] | ||
|
|
||
| raise ArgumentError.new "Account balance should not start with a negative number" if @balance < 0 | ||
| @balance = @balance | ||
|
|
||
| end #end of initialize | ||
|
|
||
|
|
||
| def self.all | ||
|
|
||
| if @@accounts == nil | ||
|
|
||
| @@accounts = [] | ||
|
|
||
| CSV.read("support/accounts.csv").each do |row| | ||
| account = { | ||
| id: row[0], | ||
| balance: row[1], | ||
| opendatetime: row[2] | ||
| } | ||
|
|
||
| @@accounts << Bank::Account.new(account) | ||
|
|
||
| end | ||
| end | ||
| return @@accounts | ||
| end #end self.all | ||
|
|
||
|
|
||
| # def self.accounts | ||
| # @@accounts #= @@accounts | ||
| # end | ||
|
|
||
|
|
||
| def self.find(id) | ||
|
|
||
| @@accounts.find do |account| | ||
|
|
||
| if account.id == id | ||
| return account | ||
| end | ||
| end | ||
|
|
||
| raise ArgumentError.new "#{id} returned no results" | ||
| end #end self.find | ||
|
|
||
|
|
||
| def withdraw(amount) | ||
|
|
||
| if amount < 0 | ||
| raise ArgumentError.new "Withdrawal amount cannot be negative number" | ||
| else | ||
| if @balance < amount | ||
| print "Your account is going to be overdrawn" | ||
| @balance = @balance | ||
| elsif @balance >= amount | ||
| return @balance -= amount | ||
| end | ||
| end | ||
| end #end of withdraw method | ||
|
|
||
| def deposit(deposit_amount) | ||
|
|
||
| if deposit_amount < 0 | ||
| raise ArgumentError.new "Deposit amount cannot be negative number" | ||
| else | ||
| @balance += deposit_amount | ||
| end | ||
| end #end of deposit method | ||
|
|
||
|
|
||
| end #end of class | ||
|
|
||
| end #end of module |
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,61 @@ | ||
|
|
||
| require 'csv' | ||
| require 'pry' | ||
| require_relative 'account.rb' | ||
|
|
||
|
|
||
| module Bank | ||
| class CheckingAccount < Account | ||
|
|
||
| attr_accessor :checks | ||
|
|
||
| def initialize(account) | ||
| super | ||
| @checks = 3 | ||
| end | ||
|
|
||
|
|
||
| def withdraw(amount) | ||
|
|
||
| if @balance - (amount + 1) < 1 | ||
| print "Insufficient Funds" | ||
| return @balnace = @balance | ||
| end | ||
| super | ||
| return @balance -= 1 | ||
|
|
||
| end | ||
|
|
||
|
|
||
| def check_withdraw(amount) | ||
|
|
||
| if amount < 0 | ||
| print "Cannot enter negative amount" | ||
| return @balance | ||
| end | ||
|
|
||
| check_fee = 0 | ||
|
|
||
| if @checks < 1 | ||
| check_fee = 2 | ||
| end | ||
|
|
||
| if @balance - (amount + check_fee) < (-10) | ||
| print "Insufficient Funds" | ||
| @balnace = @balance | ||
| else | ||
| @balance = @balance - (amount + check_fee) | ||
| @checks -= 1 | ||
| return @balance | ||
| end | ||
|
|
||
| end | ||
|
|
||
|
|
||
| def reset_checks | ||
| @checks = 3 | ||
| 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,46 @@ | ||
| require 'csv' | ||
| require 'pry' | ||
| require_relative 'account.rb' | ||
|
|
||
|
|
||
| module Bank | ||
| class SavingsAccount < Account | ||
|
|
||
| def initialize(account) | ||
|
|
||
| raise ArgumentError.new "Savings Accounts must have an Initial Balance of $10" if account[:balance] < 10 | ||
| super | ||
|
|
||
| end | ||
|
|
||
| def withdraw(amount) | ||
|
|
||
| if (@balance - (amount + 2) ) < 10 | ||
| puts "Insufficient Funds" | ||
| return @balance | ||
| end | ||
| super | ||
| return @balance - 2 | ||
|
|
||
| end | ||
|
|
||
|
|
||
| def add_interest(rate) | ||
|
|
||
| if rate < 0 | ||
| print "We do not accept negative rates" | ||
| return @balance | ||
| else | ||
| interest = @balance * (rate/100) | ||
| @balance += interest | ||
| return interest | ||
| end | ||
|
|
||
| end | ||
|
|
||
|
|
||
| end | ||
| end | ||
|
|
||
| new_account = Bank::SavingsAccount.new({balance: 10}) | ||
| puts new_account.balance |
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.
You should be able to call the
withdrawmethod from withincheck_withdraw.