83 318
Assignments Done
99,2%
Successfully Done
In February 2020

# 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, &quot;Enter the student ID number&quot;); IDNumber = Integer.parseInt(inputString); for(x = 0; x &lt; studentsIDNumberList.length &amp;&amp; !validIDNumber; ++x) { if(IDNumber == studentsIDNumberList[x]) { validIDNumber = true; firstName = studentsFirstNameList[x]; GPA = studentsGPAArray[x]; } } if(validIDNumber) { JOptionPane.showMessageDialog(null, &quot;The ID number you entered is &quot; + IDNumber + &quot;. This number belong to &quot; + firstName + &quot; and this student GPA is &quot; + GPA); } else { JOptionPane.showMessageDialog(null, &quot;Invalid ID number!&quot;); }
1
2015-03-10T04:19:44-0400
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!