wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Trouble with if statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Trouble with if statement" Watch "Trouble with if statement" New topic
Author

Trouble with if statement

Dan Grindstaff
Ranch Hand

Joined: Sep 24, 2006
Posts: 138
I am having trouble figuring out why the first if statement doesn't kick in. It is suppossed to catch a user already over the credit limit before doing any processing and end program. Here is the code:


EDIT by mw: Added Code Tags.
[ March 03, 2007: Message edited by: marc weber ]
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

It works for me. What test data are you entering?


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Dan Grindstaff
Ranch Hand

Joined: Sep 24, 2006
Posts: 138
HHmmm. I put in any account number, then 5 for balance and 4 for credit limit and it just goes on to the next pane and asks for credit and debit information.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Dan Grindstaff:
HHmmm. I put in any account number, then 5 for balance and 4 for credit limit and it just goes on to the next pane and asks for credit and debit information.

Oh, I see what you were expecting. You were thinking it would continuously check for that "if" condition.

But this is a single thread, so these lines of code execute in sequence. In particular, the "if" statement does not execute until it gets to that line of code. It sounds like you want to move that "if" statement to the point at which the validation should happen.

(Note: I've seen this assumption made with "while" loops. People sometimes expect that the loop body should stop the moment the "while" condition becomes false. But the condition is only checked at the beginning of each iteration. If true, then the entire loop body executes before another check is made.)
[ March 03, 2007: Message edited by: marc weber ]
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Here's what I'm confused about: The "balance" appears to be a credit balance (a debt amount), so it makes sense that a user is overdrawn if this balance is greater than their credit limit. But if that's the case, then to determine newBalance, shouldn't you be subtracting credits (i.e., payments that lower the debt) and adding debits (i.e., increasing the debt)? If so, then your second "if" statement should say "overpaid" instead of "overdrawn."
Dan Grindstaff
Ranch Hand

Joined: Sep 24, 2006
Posts: 138
OK thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trouble with if statement