-
Notifications
You must be signed in to change notification settings - Fork 39
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
Haby Randall Bank Accounts #30
base: master
Are you sure you want to change the base?
Conversation
…t reset_checks method
… failures at this point
Bank AccountWhat We're Looking For
SummaryNot bad, a few problems with your inheritance, you could use super in places to DRY your code a bit more. You also had a few bugs handling you withdrawal both in your tests and code. I've put in comments where. Overall you did a fine job on a hard project. Nice work. |
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 few comments in the code, just so you can see where you had small problems.
def self.all | ||
account = [] | ||
CSV.open("/Users/habsr/ada/projects/BankAccounts/support/accounts.csv", "r").each do |file| | ||
id = Integer(file[0]) |
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.
To make it so it'll work no matter where you clone the repo this should be:
CSV.open("support/accounts.csv", "r").each do |file|
puts "Warning, this will make your balance below your mininum , the current balance is " + (@balance.to_s) | ||
@balance | ||
else | ||
super + (-2) |
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.
This should probably be:
super(withdrawal_amount + 2)
because you're taking the return value of the Account
class' withdraw method and subtracting two from it. You're not changing @balance in the end.
Let me know if this is confusing.
# TODO: Your test code here! | ||
savings_account = Bank::SavingsAccount.new(11, 200) | ||
new_balance = savings_account.withdraw(10) | ||
new_balance.must_equal 188 |
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.
If you run the test
savings_account.balance.must_equal 188
here, it will fail. It's because the balance isn't getting updated. when you call super in the savings account, you should be passing it the amount + 2
to ensure it adds in the fee. You're only getting the return value from the withdraw method not the balance attribute.
class CheckingAccount < Account | ||
attr_reader :id, :balance | ||
def initialize(id, balance) | ||
@id = id |
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.
super would be swell here!
if check_balance < 0 | ||
puts "Warning, this will be below 0 , " + (@balance.to_s) | ||
else | ||
super + (-1) |
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.
Same problem with CheckingAccount
earlier.
@balance = balance | ||
@check_num = 3 | ||
|
||
def withdraw(withdrawal_amount) |
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 don't see any testing for this method...
attr_reader :id, :balance, :interest | ||
|
||
def initialize(id, balance) | ||
|
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 can probably use super to set the instance variables.
Bank Account
Congratulations! You're submitting your assignment.
Comprehension Questions
raise ArgumentError
? What do you think it's doing?.all
&.find
methods class methods? Why not instance methods?