Hello, I am having a problem putting this Array's output in a single GUI window. When I receive the output it just shows the grades in individual GUI windows (IE Erik 98 [OK], Fred 76 [OK], etc). If I put the output outside the loop then it doesn't recognize grade. I'm at a loss right now. I would like to have the output of all grades in one GUI window. If anybody could help it would be much appreciated. Thank you. I'm here to learn.
import java.util.Scanner;
import java.lang.String;
import javax.swing.*;
public class SortingStudentsGUI {
public static void main(String[] args) {
//Prompt user to enter number of students;
String NumberStudentsString = JOptionPane.showInputDialog(
"Enter the number of students: ");
int num = Integer.parseInt(NumberStudentsString);
//Create arrays
String[] names = new String[num];
double[] grades = new double[num];
// Fill arrays with prompted user data
for(int i = 0; i < num; i++)
{
String StudentNameString = JOptionPane.showInputDialog(
"Enter the name of the student: ");
names[i] = (StudentNameString);
String StudentScoreString = JOptionPane.showInputDialog(
"Enter the score of the student: ");
grades[i] = Double.parseDouble(StudentScoreString);
}
for (int bound = num-1; bound > 0; bound--)
{
for (int i = 0; i < bound; i++)
{
// Grades is the sorting criteria
if (grades[i] < grades[i+1])
{
// Swap both grades and names
double temp1 = grades[i+1];
grades[i+1] = grades[i];
grades[i] = temp1;
String temp2 = names[i+1];
names[i+1] = names[i];
names[i] = temp2;
}
}
}
//*****************************************
// Display sorted names and grades
//*****************************************
for (int i = 0; i < num; i++)
JOptionPane.showMessageDialog(null, names[i]+ " " + grades[i]);
}
}