This week's book giveaway is in the JDBC and Relational Databases forum.
We're giving away four copies of Murach's MySQL and have Joel Murach on-line!
See this thread for details.
Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sub class error

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:


 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

but I am using it in the method above that just fine.  



Because in the method above "amount" is a parameter to the method.
 
Alex Houser
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just realized I didn't post this in java beginners.  
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

it is giving me an error


Please copy the full text of the error message and paste it here.
 
Marshal
Posts: 79023
375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 shou‍ld be replaced by /** comments */
Why does the comment on line 2 say two variables?
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Marshal
Posts: 79023
375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic