Question: Comment out the provided array in Lines 9-21 (Be aware that the line numbers could have changed if you modified the file. You should comment
Comment out the provided array in Lines 9-21 (Be aware that the line numbers could have changed if you modified the file. You should comment out or remove the part under the comment line // Array initializer)
a. Declare a 2-d array to hold scores of 5 quizzes (in columns) for 10 students (in rows) under the comment in Line 4
b. Under the comment in Line 6, use for loops to assign an integer random number in the range of 0-10 to each student for each quiz.
c. In our in-class exercise, you should have the grade table printed out with row totals. So move to the last comment line, and calculate and display another line in the output to show the quiz average (column average). Make sure you align the numbers well with the rest of the grade table.
//This program calculates student quiz totals and class quiz averages.
public class StudentQuiz {
public static void main(String[] args){
// (HW10) Create a 2-dimensional array for 10 student grades on 5 quizzes
//int [] [] studGrade = new int [10][5];
// (HW10) Generate random integer grades (0-10) for all students in all quizzes
//for (int row = 0; row < matrix.length; row++) {
//for (int column = 0; column < matrix[row].length; column++) matrix[row][column] = (int)(Math.random() * 100);
//}
// Array initializer
int [][] studGrade = {
{7, 8, 6, 8, 9},
{8, 9, 8, 7, 9},
{9, 9, 7, 6, 7},
{8, 9, 6, 7, 8},
{7, 8, 9, 9, 9},
{6, 9, 6, 8, 7},
{9, 8, 7, 8, 7},
{8, 8, 9, 8, 7},
{8, 5, 8, 9, 6},
{7, 6, 9, 7, 9}
};
// Print the student quiz table
//Quiz heads
System.out.println("Stud # | Q1 | Q2 | Q3 | Q4 | Q5 | Total |");
//Separator
System.out.println("-------------------------------------------");
// For loop for rows
for (int row = 0; row < studGrade.length; row++){
// stud #:
System.out.printf("Stud%2d |", (row + 1));
// for loop for elements in the row.
int total = 0;
for (int column = 0; column < studGrade[row].length; column++){
System.out.printf(" %2d |", studGrade[row][column]);
total += studGrade[row][column];
}
System.out.printf(" %5d | ", total);
// row total
}
/* Calculate the quiz averages
for (int column = 0; column < studGrade[0].length; column++){
for (int row = 0; row < studGrade.length; row++){
}
}*/
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
