I have been trying to find why I am getting this error and cannot seem to get on the right path. I am writing code to take in user inputed test scores through a JOptionPane and store the inputs into two arrays: one for test scores and one for student names. I then need to sort through the arrays to arrange them in order. I have created my arrays, as well as the method to sort the array, but am experiencing a "[array name] cannot be resolved" error. Can someone help me get on the right page? Why is this error occurring? What can I do to fix it?
Thank you for your help!!
Lorelai
Code:import javax.swing.JOptionPane;
public class P9 {
public static void main(String[] args) {
int negativeScore = 1;
while (negativeScore > 0) {
int i = 0;
int [] testScoreArray= new int[50];
String [] studentNameArray = new String [50];
String testScoreInputString = JOptionPane.showInputDialog(null, "What was the test score? Enter a negative (-) to end the program. ");
int testScoreInt = Integer.parseInt(testScoreInputString);
if (testScoreInt <0) {
negativeScore = 0;
break;
}
testScoreArray[i] = testScoreInt;
studentNameArray[i] = JOptionPane.showInputDialog(null, "What is the name of the student?");
i++;
}
// Sort the list
selectionSort(testScoreArray]);
} //end main method
/*method for printing numbers
static void printList(int[] list) {
for (int i = 0; i < list.length; i++)
System.out.print(list[i] + " ");
System.out.println();
} end printList method*/
//method for sorting the numbers
static void selectionSort(int[] list) {
for (int i = list.length - 1; i >= 1; i--) {
// Find the maximum in the list[0..i]
int currentMax = list[0];
int currentMaxIndex = 0;
for (int j = 1; j <= i; j++) {
if (currentMax < list[j]) {
currentMax = list[j];
currentMaxIndex = j;
} //end if
}// end for with j as index
// Swap list[i] with list[currentMaxIndex] if necessary;
if (currentMaxIndex != i) {
list[currentMaxIndex] = list[i];
list[i] = currentMax;
}// end if
}// end for with i as index
} //end selectionSort method
} //end SelectionSort class
