Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write an application containing three parallel arrays that hold 10 elements each. The first array hold four-digit student ID numbers, the second array holds first

Write an application containing three parallel arrays that hold 10 elements each. The first array hold four-digit student ID numbers, the second array holds first names, and the third array holds the students grade point averages. Use dialog boxes to accept a student ID number and display the students first name and grade point average. If a match is not found, display an error message that includes the invalid ID number and allow the user to search for a new ID number.

I cannot figure out how to get the name and GPA to come up when you input a valid student ID. When I enter a student ID, it does not recognize that it is in the list and shows the error message. This is what I have so far:

import javax.swing.JOptionPane; public class Assignment1 { /** * @param args the command line arguments */ public static void main(String[] args) { // Initialize Arrays int[]studentid = new int[]{5892,1950,2957,1048,5838,8158,8251,5739,2957,6983}; String[]studentname = new String[]{"Caroline","Jake","Anna","Ashley","Ryan","Bethany","David","Lisa","Lauren","Alan"}; double[]studentavg = new double[]{4.0,3.8,4.4,3.7,3.1,3.5,3.3,4.0,3.4,3.5}; String studentID = null; studentID = JOptionPane.showInputDialog(null, "Enter StudentID: "); boolean flag = true; do{ // Match entered student ID against all IDs for(int i = 0; i < studentid.length; i++){ if (studentID.equals(studentid[i])){ JOptionPane.showMessageDialog(null, "StudentID: %d" +studentid[1]+"Name: %s"+studentname[i]+"GPA: %f"+studentavg[i]); flag = true; break; } if (!"studentID".equals(studentid[i])){ // loop until correct ID is entered while (!"studentID".equals(studentid[i])){ JOptionPane.showMessageDialog(null, "Error: Invalid StudentID: " +studentID); JOptionPane.showInputDialog(null, "Enter StudentID: "); } if (studentID.equals(studentid[i])){ JOptionPane.showMessageDialog(null, "StudentID: " +studentid[i]+"Name: "+studentname[i]+"GPA: "+studentavg); } } } } while (true); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions