aspose file tools*
The moose likes Beginning Java and the fly likes Frustrating- logic error, but where? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Frustrating- logic error, but where?" Watch "Frustrating- logic error, but where?" New topic
Author

Frustrating- logic error, but where?

Sal Velinus
Greenhorn

Joined: Mar 05, 2002
Posts: 25
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 ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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 ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Sal Velinus
Greenhorn

Joined: Mar 05, 2002
Posts: 25
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

Joined: Dec 10, 2001
Posts: 7023
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

Joined: Mar 05, 2002
Posts: 25
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Frustrating- logic error, but where?