60 316
Assignments Done
98%
Successfully Done
In April 2018

Answer to Question #51197 in Java | JSP | JSF for Michael

Question #51197
how to ask user to reenter ID number if the number entered is invalid?
inputString = JOptionPane.showInputDialog(null, "Enter the student ID number");
IDNumber = Integer.parseInt(inputString);

for(x = 0; x < studentsIDNumberList.length && !validIDNumber; ++x)
{
if(IDNumber == studentsIDNumberList[x])
{
validIDNumber = true;
firstName = studentsFirstNameList[x];
GPA = studentsGPAArray[x];
}
}

if(validIDNumber)
{
JOptionPane.showMessageDialog(null, "The ID number you entered is " + IDNumber + ". This number belong to "
+ firstName + " and this student GPA is " + GPA);
}

else
{
JOptionPane.showMessageDialog(null, "Invalid ID number!");
}
Expert's answer
Solution.
1.    You need to add an infinite loop (while (true))
2.    Out of the loop (break;)
 
while(true)
            {
 
                inputString =JOptionPane.showInputDialog(null, "Enter the student ID number");
                IDNumber =Integer.parseInt(inputString);
 
                for(x = 0; x < studentsIDNumberList.length && !validIDNumber; ++x)
                {
                    if(IDNumber == studentsIDNumberList[x])
                    {
                        validIDNumber = true;
                        firstName =studentsFirstNameList[x];
                        GPA =studentsGPAArray[x];
                    }
                }
 
                if(validIDNumber)
                {
                   JOptionPane.showMessageDialog(null, "The ID number you entered is " +IDNumber + ". This number belongto "
                    + firstName + " and this student GPA is " + GPA);
 
                    break;
                }
                else
                {
                   JOptionPane.showMessageDialog(null, "Invalid ID number!");
                }
 
            }
 


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions