File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Newbie problem - HELP! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Newbie problem - HELP!" Watch "Newbie problem - HELP!" New topic

Newbie problem - HELP!

Robert Adams

Joined: May 06, 2004
Posts: 2
I am having problems with this while loop when exiting. First I can enter valid info, when I want to exit I have to place a #1 in the share price JOptionPane and then a -1 to quit in the number of shares JOptionPane if I want to get any kind of a summary report. When I do this the number of shares are correct, number of transactions are correct, but the calculation of final pay due which is $100 base pay plus commission over $40 and commission over $40 is incorrect.
I feel like I am in a loop, Please help.

[ edited to preserve formatting using the [code] and [/code] UBB tags, and to remove the evil tab characters -ds ]
[ May 06, 2004: Message edited by: Dirk Schreckmann ]
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Using a local variable in the condition statement in the while loop is awkward since the "-1" alters it and thus your data that uses its value.
Another possibility is to make up a boolean such as enterMoreData and ask the user to validate it, ie, have them enter something special to exit, during each loop. If you get the signal to stop at the bottom all you need to do is set the boolean value to false. The next round evaluates to false and you're out of the loop. If you do the asking and checking/validating at the top of the loop you can use "break" to exit the loop and process your data.
I agree. Here's the link:
subject: Newbie problem - HELP!
It's not a secret anymore!