Question
Assume that two-dimensional arrays are used to store information about students' grades. The first is called studentScores and contains the students' numerical scores as integers.
Assume that two-dimensional arrays are used to store information about students' grades. The first is called studentScores and contains the students' numerical scores as integers. The other is studentLetters and contains the corresponding letter grades as a String (i.e. "A", "B", "C", "D", or "F"). Each row represents an individual student and each column a different assessment.
For example, if studentScores[0][0] contains 92, then the contents of studentLetters[0][0] will contain the corresponding letter grade. In this case, the letter grade is A because the professor has used a standard grading scale. Note that the professor might choose a different grading scale. Do not assume scores of 90 or above are the letter grade A.
public class Gradebook
{
private int[][] studentScores;
private String[][] studentLetters;
// constructors not shown
// postcondition: returns −1.0 if letterGrade does not appear in studentLetters
// otherwise, returns the average of all studentScores with corresponding
// studentLetters values that are equal to the parameter letterGrade
public double letterAverage(String letterGrade)
{
}
// other methods not shown
}
Write the method letterAverage. This method returns a double representing the average (arithmetic mean) of the student scores that correspond to a given letter grade. The method letterAverage returns −1.0 if none of the student scores corresponds to the given letter grade.
For example, given the following two-dimensional arrays:
studentScores: 96 72 84 65 89 60
78 86 75 61 85 73
studentLetters: A C B D A D
B B C D B C
The method call letterAverage("B") would return the number 83.25, which is the average of the four scores that correspond to the letter grade B.
The method call letterAverage("F") would return −1.0 because none of the studentLetters elements are equal to F.
Complete the method letterAverage below. Be sure to include the method header.
Step by Step Solution
3.47 Rating (160 Votes )
There are 3 Steps involved in it
Step: 1
Gradebookjava Public class book Private int studentScores Private string s...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started