import java.util.Arrays;
import javax.swing.JOptionPane;
public class Lab3
{
public static void main(String[] args)
{
intro();
int numberOfStudents = 0;
String response = null;
do
{
response =
JOptionPane.showInputDialog("Enter number of students.");
numberOfStudents = Integer.parseInt(response);
}
while(response == null || response.length() == 0);
String[] names = new String[numberOfStudents];
int[] scores = new int[numberOfStudents];
getInput(names, scores);
System.out.printf("names = %s%n", Arrays.toString(names));
// Now you can process the collected data.
}
public static void intro()
{
JOptionPane.showMessageDialog(null, "This program will take " +
"a given number of students and show you the user " +
"their scores from highest to lowest with the " +
"class average.");
}
public static void getInput(String[] names, int[] scores)
{
// Fill the arrays with user input.
int count = 0;
do
{
String s =
JOptionPane.showInputDialog("What is the students name?");
names[count] = s;
s = JOptionPane.showInputDialog("Please enter a number.");
scores[count] = Integer.parseInt(s);
}
while(count++ < names.length-1);
}
}