Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CIS 260 Closed Lab 8 Arrays Create a gradebook using multi-dimensional array, wi

ID: 3607020 • Letter: C

Question

CIS 260 Closed Lab 8 Arrays Create a gradebook using multi-dimensional array, with 4 students in class and their grades of 3 quizzes. Write three different methods: 1. Displaying the grade of one student in a quiz. 2. Displaying the average grade of all the quizzes for a student. 3. Displaying the average of all the students in a quiz. The gradebook data you need to enter is: studentAverage 10.0 studentAverage [e |studentAverage[1] studenti- student 2- 2 tudent 38 student 4 8 10 10 10 | | 1 --| 1.0 6 | 4 |10 17.3 studen tAverage[3] quizAverage 7 7.0 5.07.5 You will be asking the user, what would they like to see. Ask the user to enter 1 for displaying the grade of a student in a quiz, 2 for displaying the average grade of all the quizzes for a student and 3 for

Explanation / Answer

import java.util.Scanner;

// Class GradeBook definition

public class GradeBook

{

// Declares and assign values for 4 x 3 matrix

// 4 rows for 4 students

// 3 columns for 3 quiz mark

static double studentGrades[][] = {{10, 10, 10}, {2, 0, 1}, {8, 6, 9}, {8, 4, 10}};

// Method to display specified student's specified quiz mark

static void oneStudentGrade(int s, int g)

{

// s is used for row number and g is used for column number

// -1 because index position begins from zero

System.out.println("The requested grade is : " + studentGrades[s-1][g-1]);

}// End of method

// Method to display specified student's average mark

static void oneStudentAllQuizAverage(int s)

{

double tot = 0;

double avg;

// Loops 3 times for all quiz mark

for(int c = 0; c < 3; c++)

// s is used for row number i.e., student number

// -1 because index position begins from zero

// Calculates total

tot += studentGrades[s-1][c];

// Calculates average. 3 for number of quiz

avg = tot / 3;

// Displays average

System.out.println("The student's average is : " + avg);

}// End of method

// Method to display all student's specified quiz average mark

static void allStudentAverageInQuiz(int q)

{

double tot = 0;

double avg;

// Loops 4 times for all students

for(int c = 0; c < 4; c++)

// s is used for row number i.e., student number

// -1 because index position begins from zero

// Calculates total

tot += studentGrades[c][q-1];

// Calculates average. 4 for number of students.

avg = tot / 4;

// Displays average

System.out.println("The quiz's average is : " + avg);

}// End of method

// main method definition

public static void main(String[] args)

{

// Scanner class object created

Scanner sc = new Scanner(System.in);

// To student student and quiz number entered by the user

int stu, quiz;

// Displays menu

System.out.println("Please enter what would you like to do in the grade book today.");

System.out.println("To view the grade of a student for a quiz, please press 1");

System.out.println("To view the average grade of all the quizzes for a student, please press 2");

System.out.println("To view the average grade of all the students for a quiz, please press 3");

// Accepts user choice

int choice = sc.nextInt();

// Checks user choice using switch and calls appropriate method

switch(choice)

{

case 1:

System.out.println("Which student's grade would you like to see? ");

stu = sc.nextInt();

System.out.println("Which quizz grade would you like to see? ");

quiz = sc.nextInt();

oneStudentGrade(stu, quiz);

break;

case 2:

System.out.println("Which student's average grade would you like to see? ");

stu = sc.nextInt();

oneStudentAllQuizAverage(stu);

break;

case 3:

System.out.println("Which quiz's average would you like to see? ");

quiz = sc.nextInt();

allStudentAverageInQuiz(quiz);

break;

default:

System.out.println("Wrong input!");

}// End of switch - case

}// End of main method

}// End of class

Sample Run 1:

Please enter what would you like to do in the grade book today.
To view the grade of a student for a quiz, please press 1
To view the average grade of all the quizzes for a student, please press 2
To view the average grade of all the students for a quiz, please press 3
1
Which student's grade would you like to see?
3
Which quizz grade would you like to see?
2
The requested grade is : 6.0

Sample Run 2:

Please enter what would you like to do in the grade book today.
To view the grade of a student for a quiz, please press 1
To view the average grade of all the quizzes for a student, please press 2
To view the average grade of all the students for a quiz, please press 3
2
Which student's average grade would you like to see?
2
The student's average is : 1.0

Sample Run 3:

Please enter what would you like to do in the grade book today.
To view the grade of a student for a quiz, please press 1
To view the average grade of all the quizzes for a student, please press 2
To view the average grade of all the students for a quiz, please press 3
3
Which quiz's average would you like to see?
3
The quiz's average is : 7.5