Using a custom library but everything is still relevant to the standard java language.
I'm trying to ask the user for a string to store their gender for a variable called formGender using a dialog box to get them to enter either "Male", "Female" or "Other".
I declare a new char variable for "charGender" as a blank character regardless if the user enters or leaves the gender field blank when prompted.
If the "formGender" variable is NOT blank, then define "charGender" as the first character of "formGender". Else just continue on down.
String formGender = gt.getInputString("Please specify your gender. ([Male] or [Female] or [Other])");
char charGender = ' ';
if (!formGender.isBlank()) {
//Select character at position 0 (1).
charGender = formGender.charAt(0);
}
And later down the line, I perform checks to see if the gender field was left blank or not valid which is done by checking if the "charGender" is not equals to either upper or lower case of 'm', 'f' or 'o' for 'male', 'female' or 'other' respectively.
If so, then it asks again to re-enter a valid answer this time.
if (charGender != 'M' || charGender != 'm' || charGender != 'F' || charGender != 'f' || charGender != 'O' || charGender != 'o') {
gt.showErrorDialog("Please specify a valid gender. ([Male] or [Female] or [Other])");
formGender = gt.getInputString("Please specify your gender. ([Male] or [Female] or [Other])");
Then I perform ANOTHER check again to see if the gender field was left blank or not valid which is done by checking if the "charGender" is not equals to either upper or lower case of 'm', 'f' or 'o' for 'male', 'female' or 'other' respectively.
If so, then it tells the user to "Please enter valid information next time." and terminates further execution.
charGender = formGender.charAt(0);
if (charGender != 'M' || charGender != 'm' || charGender != 'F' || charGender != 'f' || charGender != 'O' || charGender != 'o') {
gt.clear();
gt.showErrorDialog("Please enter valid infomation next time. Bye!");
System.exit(0);
}
}
My problem here is that when I perform the first check, I try to redefine the "charGender" variable to the new one which will be entered by the user.
And the second check is supposed to take into account the new definition of the 'charGender' variable but it isn't doing so. So the second check just skips to the "Please enter valid information next time. Bye!" part and terminates the program.
What do I do?! I've been banging my head at this problem for too many hours now! Plz HELP!
Aucun commentaire:
Enregistrer un commentaire