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. |
CheezItMan
left a comment
There was a problem hiding this comment.
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.
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.
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.
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 |
| if check_balance < 0 | ||
| puts "Warning, this will be below 0 , " + (@balance.to_s) | ||
| else | ||
| super + (-1) |
There was a problem hiding this comment.
Same problem with CheckingAccount earlier.
| @balance = balance | ||
| @check_num = 3 | ||
|
|
||
| def withdraw(withdrawal_amount) |
There was a problem hiding this comment.
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.
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&.findmethods class methods? Why not instance methods?