• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

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: 5114
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: 80634
471
  • 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: 17734
302
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: 80634
471
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic