I have been going at this for several hours for the last 4-5 days and cant seem to figure out where i am going wrong.
I have a dialog box to ask the user if they want to enter a loan. IF yes is pushed it goes one with the prgram, if no is pushed it still goes on without exiting, and
once the end of the program is reached it wont loop back to the dialog box asking to enter a loan.. Can any one spot my error? this is driving me crazy!
Before we go to the fixes, I advise you to learn the constructs or syntax of Java first.
1. while loop will execute statements that are placed inside its opening & closing braces. There are no statements inside your while to tell which statements you need to execute till the condition matches. Hence the code should be like
2. The program checks for the "No" condition only at the last after executing all the logical statements to Principle, Interest, etc. So to terminate the program once after user entering "No" option have your code like below
3. Ok now you see this code you wrote ->
There is a ; after your if condition meaning that the if statement ends by then and the System.exit(0) will always be executed even if the option is yes / no (to be precise - when the execution reaches that point it will be executed for sure). So if your original logic was that program should be terminated if user gave No option then provide the System.exit(0) inside the braces of the condition.
4. Ok... at last please have your code nicely indented without unnecessary white spaces for your easy understanding.
And of course welcome to the Ranch
Joined: Jul 05, 2011
AHHH! Thank you so much, i was at the point of nervous break down trying to figure out how the syntax on loops work. I can do
i<10 loops all day long, but when you use input form GUI boxes it made things a lot more complicated!! Now to clean up my code for readability!!
This has got to be the best java forum on the net! no doubt!