• 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

Frustrating- logic error, but where?

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I eliminated the constructor problem (still don't know why it occurred), but now a new problem.
This is supposed to be a checking account with a savings account as overdraft protection. That part seems ok, except the overdraft method (trfFunds()) doesn't seem to work, and I can't see why. The program subtracts any amount from checking, putting it into negative values, when it should instead withdraw from savings, deposit in checking, then withdraw from savings. It should throw an NSF exception if there's not enough in savings.
Instead, it leaves savings alone and deducts any amount from checking (both are initialized to $500).
I've been over and over this and can't find the error. It compiles and runs ok, just doesn't work correctly. Relevant code below. Thanks for any help!
Test driver code:

Checking code:

DemandAccount code (base class to Checking) that hold trfFunds()):

Thanks!
[ April 23, 2002: Message edited by: Greg Adams ]
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One problem (or so I think):
It looks like that if the withdraw(double) method discovers that the account funds are inadequate, it invokes trfFunds(double, DemandAccount), which invokes withdraw(double), which invokes trfFunds(double, DemandAccount), which invokes withdraw(double), which invokes trfFunds(double, DemandAccount), which invokes withdraw(double), etc.
Or did I miss something?
[ April 23, 2002: Message edited by: Dirk Schreckmann ]
 
Sal Velinus
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Checking and savings are both subclasses of abstract class DemandAccount, which is a subclass of Abstract class Account.
Checking has it's own withdraw() method, which calls trfFunds() in DemandAccount. Savings uses the withdraw method in DemandAccount. requestor is the Checking account instance, while trfAcct is the Savings instance designated as the overdraft.
So, I don't think it's an endless loop. Checking's withdraw() calls trfFunds(), which then calls Savings withdraw(). At least it's supposed to. If Savings balance is too low, an exception is thrown. At least it's supposed to.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK. I have a feeling that my powers of guessing will only get bounced around a bit here with things like: "Nope. I didn't tell you about this." or "Nope. I didn't tell you about that."
So, in the sake of maximizing my powers, could you please post everything relevant in its simplest form with very clear identifiers (please not too many acronyms - I can hand a couple).
Good Luck.
[ April 24, 2002: Message edited by: Dirk Schreckmann ]
 
Sal Velinus
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, ok, but it's several files worth. I didn't want to clutter the board.
DemandAccount

Checking

Savings

TestBanking (the driver class to test the classes)

and finally Customer

Hope that's better, I appreciate the help.
[ April 24, 2002: Message edited by: Dirk Schreckmann ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic