/**
 * 3D array code: add third term dimension to student/quiz 2D array
 * @author CPSC 111 Jan 2010 class, in array order of row/column seating in the lecture hall!
 * @date Wed Mar 17 2010
 */
public class ArrayTestCleanedup
{
	public static void main(String[] args)
	{
		// let's try a 3D array of scores!
		// add a second term
		// we have: 2 terms, 3 students, with 5 quizzes each
		// added a 6th quiz
		// then added a 4th student
		double[][][] scores = {
				{
					{34, 46, 24, 33, 55, 99},
					{88,67,89,43,88,99},
					{45,67,89,90,33,99},
					{20,20,20,20,40,60}
				},
				{
					{95, 82, 13, 96,99,94},
					{51, 68, 63, 57,33,99}, 
					{73, 71, 84, 78,76,99},
					{70,80,90,95,98,99}
				}
		};

		double averagePerTerm;
		//	terms is the outermost part of array, then students second level, then quizzes innermost

		double averageAcrossTerm = 0;
		// here's where we control looping row by row (student by student)
		for (int term = 0; term < scores.length; term++)
		{
			//averageQuizzesPerStudent = 0; // wait, we're not resetting between students!
			// move this reset into the second-level loop
			// and here's where we control looping through the columns
			// (i.e., quiz scores) within each row
			double averageForStudentsInTerm = 0;
			for (int student = 0; student < scores[term].length; student++)
			{
				double averageQuizzesPerStudent = 0; // reset this average once per student
				for (int quiz = 0; quiz < scores[term][student].length; quiz++)
				{
					averageQuizzesPerStudent += scores[term][student][quiz];
				}
				averageQuizzesPerStudent = averageQuizzesPerStudent / scores[term][student].length;
				System.out.println("averageQuizzesPerStudent " + term + " is " + averageQuizzesPerStudent);
				averageForStudentsInTerm += averageQuizzesPerStudent;
			}
			averageForStudentsInTerm /= scores[term].length;
			System.out.println("     averageForStudentsInTerm " + term + " is " + averageForStudentsInTerm);
			averageAcrossTerm += averageForStudentsInTerm;
		}
		averageAcrossTerm /= scores.length;
		System.out.println("************averageAcrossTerm is " + averageAcrossTerm);

	}
}
