I would not be posting right now if it weren't for the fact that I've exausted my resources and have no where else to turn for a solution.
First of all, let me give you guys a .class file, that when compiled, does exactly what my program is -supposed- to do.
Now that you know what my program is supposed to do, here is the program I have:
import static java.lang.System.out;
import java.util.Scanner;
public class StuTest
{
private static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args)
{
int[][] testScores; // [students][tests]
String[] stuNames;
testScores = createArray();
if(testScores != null)
{
stuNames = new String[testScores.length];
populateNames(stuNames);
populateTestScores(stuNames,testScores);
printStudentReport(stuNames,testScores);
printTestReport(stuNames,testScores);
out.println("\n\nGoodbye!\n\n");
}
else
{
out.println("Array not successfully created - exiting");
}
}
// Code your 5 methods below..
// Ask user to enter the number of students, and then asks user to enter the number of tests.
private static int numberOfStudents;
private static int numberOfTests;
public static int[][] createArray()
{
System.out.print("Enter the number of students: ");
numberOfStudents = keyboard.nextInt();
System.out.print("Enter the number of tests: ");
numberOfTests = keyboard.nextInt();
System.out.println();
System.out.println();
int[][] stuArray = new int[numberOfStudents][numberOfTests];
return stuArray;
}
// Ask for the name of each student for each number of students
public static String[] populateNames(String[] stuNames)
{
for(int x = 0; x < stuNames.length; x++)
{
System.out.print("Enter the name for student " + (x + 1) + ": ");
keyboard = new Scanner(System.in);
stuNames[x] = keyboard.nextLine();
}
return stuNames;
}
// Display "Entering Scores for (Student Name)" then input the score for each test.
public static int[][] populateTestScores(String[] stuNames, int[][] testScores)
{
for(int y = 0; y < stuNames.length; y++)
{
for(int u = 0; u < stuNames.length; u++)
{
System.out.println("Entering scores for " + stuNames[y]);
System.out.print(" Enter score for Test " + testScores + ": ");
testScores[y][u] = keyboard.nextInt();
}
}
return testScores;
}
// Print Student Report
public static void printStudentReport(String[] stuNames, int[][] testScores)
{
// Print the name of each student and the scores for each of the student's tests
System.out.println("STUDENT REPORT");
for(int z = 1; z <= stuNames.length; z++)
{
System.out.println("Report for " + stuNames[z]);
for(int a = 1; a <= numberOfTests; a++)
{
System.out.println(" Test " + a + ": " + testScores[a][z]);
}
// Print the average of the student's tests
int p = 0;
for(int o = 1; o <= testScores.length; o++)
{
p += testScores[o][z];
}
p /= testScores.length;
System.out.println(" " + stuNames[z] + "'s average is " + p);
}
// Print Test Report
}
public static void printTestReport(String[] stuNames, int[][] testScores)
{
System.out.println("TEST REPORT");
// Print the results for each individual test, and the average for each test
for(int b = 1; b <= testScores.length; b++)
{
System.out.println("Report for Test" + b);
for(int c = 1; c <= numberOfStudents; c++)
{
System.out.println(" Test " + c + ": " + testScores[c][b]);
}
int p = 0;
for(int o = 1; o <= testScores.length; o++)
{
p += testScores[o][b];
}
p /= testScores.length;
System.out.println(" Test" + b + " average is " + p);
}
}
}
If you throw that into your compiler, it will compile, but gives several runtime errors resulting in a crash.. What happens is that when I get to the "Entering scores for test", the test numbers do not show up correctly. It prints out the student report inproperly and does not print out the test report at all, it just crashes.