To achieve your goal, you need to search for the entered student ID in the `StudentID` array and then display the corresponding first name and GPA if a match is found. Otherwise, you should show an error message. Here's the modified version of your code to accomplish this:
```java
import javax.swing.JOptionPane;
public class Assignment1 {
public static void main(String[] args) {
int[] StudentID = {1234, 5678, 9101, 1213, 1415, 1617, 1819, 2021, 2223, 2425};
String[] FirstName = {"Bob", "Joe", "Jane", "John", "Roman", "Billy", "Casy", "Kylie", "Raimy", "Abby"};
double[] GPA = {3.4, 3.6, 2.1, 1.2, 4.0, 3.7, 1.0, 3.7, 3.9, 3.4};
// Prompt user to enter student ID
String input = JOptionPane.showInputDialog(null, "Enter student ID");
// Convert the input to an integer
int searchID = Integer.parseInt(input);
// Initialize variables to hold found data
String foundFirstName = null;
double foundGPA = 0.0;
boolean found = false;
// Search for the entered student ID in the array
for (int i = 0; i < StudentID.length; i++) {
if (searchID == StudentID[i]) {
foundFirstName = FirstName[i];
foundGPA = GPA[i];
found = true;
break;
}
}
// If a match is found, display the student's details
if (found) {
JOptionPane.showMessageDialog(null, "First name: " + foundFirstName + "\nGPA: " + foundGPA);
} else {
// If no match is found, display an error message
JOptionPane.showMessageDialog(null, "Error: Student ID " + searchID + " not found.");
}
}
}
```
This code prompts the user to enter a student ID, searches for that ID in the `StudentID` array, and then displays the corresponding first name and GPA if found. If the ID is not found, it shows an error message.
If no match is found, display an error message. Remember, seeking assistance with Java assignments can provide valuable insights and guidance to overcome hurdles. Additionally, exploring various online resources and seeking help from experienced programmers can further enhance your understanding and proficiency in Java programming. Understanding these concepts deeply can assist you in tackling similar challenges in the future. There are various online platforms, such as
programminghomeworkhelp.com, where you can find
help with Java assignment.