I have an assignment where I must modify my code to:
A: If the weight of an object is greater than 99999 your code should print a GUI driven error message, and force the user to reenter the weight of the object.
B: If a user enters a negative weight, your code should display a GUI warning message.
My original code is:
Not sure if its needed, but the Weight class is:
I thought in order to add the error message pop ups it would require an IF statement. I came up with:
The entire code with the addition looks like:
When I run the program it runs just the original program. It does not recognize if I enter a number higher than 99,999 or less than 0 and performs the calculations as normal. I am completely unsure as to what I am missing. Any help pointing me in the right direction would be greatly appreciated.
Did you not understand my suggestion in the other forum? If not, please describe your confusion and ask additional questions in the original post.
My suggestion from the other forum:
You need some kind of loop to repeat the request for the object's weight if the user's entry is incorrect, something like:
Learning Java using Eclipse on OpenSUSE 11.2
Linux user#: 501795
Joined: Jan 27, 2012
Haha, no, just thanks to the Wifey I lost browser history and could for the life of me not recall the site.
Anyways, you suggested the do-while loop.
I was working on that and could not figure out the proper way to construct it.
I understand I need to have for lets say the "A" portion:
However the bit about setting parts to false and true completely lost me. Also I am unsure where the do-while loop is suppose to fit in the original code.
Again my bad on switching to a different site, awesome that you are here as well though! (would love the name of that other site too)
Joined: Oct 24, 2010
You have the construct of the do/while loop correct, and you could do it the way you've coded. I suggested using an error flag, a boolean called 'error', so that multiple conditions could be tested in a single loop with the minimum or simplest (in my mind) code. Since you want to test for both greater than and less than a certain amount, your while statement should look like: