import javax.swing.*;
public class StudentIDArray
{
public static void main(String[] args)
{
String enteredID;
int idNumber;
int x = 0;
String studentName = "";
double studentGPA = 0.0;
boolean validID = false;
int[] id = {1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010};
String[] names = {"Bob", "Joe", "Fred", "Suzie", "Jane", "Megan", "Frank", "Jill", "Tom", "Judy"};
double[] gpa = {3.5, 3.32, 3.7, 4.0, 3.72, 3.93, 2.6, 1.95, 2.18, 2.83};
enteredID = JOptionPane.showInputDialog(null, "Enter a four-digit student ID number");
idNumber = Integer.parseInt(enteredID);
for(x = 0; x < id.length; ++x)
{
if(idNumber == id[x])
{
validID = true;
studentName = names[x];
studentGPA = gpa[x];
}
}
if(validID == false)
JOptionPane.showMessageDialog(null, "You entered an invalid ID number");
else
JOptionPane.showMessageDialog(null, "You entered " + idNumber + ".\nThe student's name is "
+ studentName + " and the GPA is " + studentGPA);
}
}