Hello everyone, I was hoping for some help on a subclass I'm creating. I have a bank account superclass that is pulled into my checking account subclass. If you look at lines 30-39 of my checking account class, you can see that I'm trying to charge a 30 dollar fee if a withdrawal is more than the balance. If you look at lines 34 and 36 you can see I'm trying to use withdraw from my bank account superclass but it is giving me an error saying it can't find the symbol variable amount, but I am using it in the method above that just fine. Any advice you can give me would be greatly appreciated. What am I doing wrong here? Thanks!
This is my bank account superclass:
This is my checking account subclass:
Post by:Rob Camick
but I am using it in the method above that just fine.
Because in the method above "amount" is a parameter to the method.
Post by:Alex Houser
Just realized I didn't post this in java beginners.
Post by:Norm Radder
it is giving me an error
Please copy the full text of the error message and paste it here.
Post by:Campbell Ritchie
Alex Houser wrote:Just realized I didn't post this in java beginners.
In which case I shall move you.
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?
Post by:Junilu Lacar
Assuming that the amount you refer to is the one declared on line 23, that's a parameter to the withdraw method and its scope is limited to that method only. You can't refer to it from another method, like what you did in processWithdrawal().
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.
Post by:Campbell Ritchie
Junilu Lacar wrote:. . . real world bank accounts do go into negative balances. . . . I have a kid in college
Do real world student accounts ever go out of negative balances
. . . you have to invoke that method when it is appropriate to perform the logic in it.
I would give that method private access and call it from inside the withdraw method. It will need some changes, however.
This thread has been viewed 396 times.
All times above are in ranch (not your local) time.
The current ranch time is Dec 16, 2018 22:33:59.