Here's a friend's code. I included the entire thing in case you'd like to dump it into an IDE or whatever. Anyway, Eclipse is complaining about the following line:
System.out.println(student[t] + "\t\t" +highGrade(grades) + "\t\t" +lowGrade(grades)
+ "\t\t" +(averageGrade(grades)));
It says that 'grades' cannot be resolved to a variable. The intent of the code at this point is to pass the inner array of grades[][] to some methods, returning doubles to print. What is the proper syntax for this? (Note: I haven't checked out the methods yet, so there may also be errors there. But for now I'm just wondering about this syntax.)
Thanks!
import java.util.*; public class Midterm { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Please enter the number of students: "); int numofStudents = input.nextInt(); String student[] = new String[numofStudents]; for (int i = 0; i < numofStudents; i++) { // collect student name System.out.println("Enter the " + numName(i+1) + " student's name: "); student[i] = input.next(); // collect grades double grades[][] = new double[student.length][]; grades[i] = collectGrades(); } //end for // print information System.out.println("Student Name\tHigh Score\tLow Score\tAverage\tGrade"); System.out.println("----------------------------------------------------------"); for(int t = 0; t < numofStudents; t++) { System.out.println(student[t] + "\t\t" +highGrade(grades) + "\t\t" +lowGrade(grades) + "\t\t" +(averageGrade(grades))); } //end for } //end main public static double[] collectGrades() { Scanner input = new Scanner(System.in); System.out.println("Please enter the number of grades you will be entering for this student:"); int numOfGrades = input.nextInt(); double gradeArrayOut[] = new double[numOfGrades]; for (int i = 0; i < gradeArrayOut.length; i++) { System.out.println("Please enter the " + numName(i + 1) + " grade:"); gradeArrayOut[i] = input.nextDouble(); } //end for return gradeArrayOut; } //end collectGrades public static double highGrade (double arrayIn[]) { Arrays.sort(arrayIn); return arrayIn[arrayIn.length -1]; } // end highGrade public static double lowGrade (double arrayIn[]) { Arrays.sort(arrayIn); return arrayIn[0]; } // end highGrade public static double averageGrade(double arrayIn[]) { double avgGrade = 0.0; for(int i = 0;i < arrayIn.length;i++) { avgGrade += arrayIn[i]; } // end for return avgGrade/arrayIn.length; } // end averageGrade public static String numName(int intIn) { String numName = ""; switch(intIn) { case 1: numName = "first"; break; case 2: numName = "second"; break; case 3: numName = "third"; break; case 4: numName = "fourth"; break; case 5: numName = "fifth"; break; case 6: numName = "sixth"; break; case 7: numName = "seventh"; break; case 8: numName = "eight"; break; case 9: numName = "ninth"; break; case 10: numName = "tenth"; break; default: numName = intIn + (intIn<20?"th" : (intIn%10==1?"st": (intIn%10==2?"nd": (intIn%10==3?"rd":"rh")))); } //end Switch return numName; } } //end class