This is my bank account superclass:
This is my checking account subclass:
In which case I shall move you.
Alex Houser wrote:Just realized I didn't post this in java beginners.
Have you come across the @Override annotation? Whenever you are extending a class, tag each method you are overriding with @Override, like this:-Now, I think there is only one method you are trying to override, so I used that annotation once in line 23; if you make the tiniest spelling error, or mark a method which you aren't overriding, you will find out soon enough; try it and see.
Why are you calling the method in line 32 processWithdrawal? Why have you given it public access? Surely nobody is going to call the charge fee method from elsewhere. Why have you hard‑coded the fee in line 33? Why do both that and the ordinary withdraw method call the superclass' withdraw method? And while we are on about the method to charge a fee, look how badly it is formatted when the rest of the code is formatted well. Bad indentation and excess blank lines make the code harder to read, but it is you who will have the most difficulty reading it and identifying errors.
What does the minBalanace field mean?
I think most of your // comments should be replaced by /** comments */
Why does the comment on line 2 say two variables?
By the way, real world bank accounts do go into negative balances. I know this because I have a kid in college who often over draws from his account and I have to stay on top of that so we don't get charged a fee. Luckily, the bank we use alerts us when the balance goes negative and gives us a 24 hour grace period to get the account back in the black. Your code, unfortunately, will lose that information because it just sets the balance to 0 in an overdraft situation. Also, you have code to charge and overdraft fee but it is never called from anywhere else in your program. Just because you provided a method to do something, that doesn't mean it will get executed magically; you have to invoke that method when it is appropriate to perform the logic in it.
Do real world student accounts ever go out of negative balances
Junilu Lacar wrote:. . . real world bank accounts do go into negative balances. . . . I have a kid in college
I would give that method private access and call it from inside the withdraw method. It will need some changes, however.
. . . you have to invoke that method when it is appropriate to perform the logic in it.