In: Computer Science
This is a Java program assignment.
In the GradeCalculator class, compute the final average and letter grade for a particular student.
The final average is calculated according to the following rules:
1) There are ten exams scored out of 100 points
2) The lowest exam score is not included in the calculation of the final average
3) The highest exam score is not included in the calculation of the final average
4) An average of 91-100 is an A
5) An average of 81-90 is a B
6) An average of 71-80 is a C
7) An average of 61-70 is a D
8) An average of 0-60 is an E
The GradeCalculator class must include the following methods:
1) A method to compute and return the highest score
2) A method to compute and return the lowest score
3) A method to compute the sum of all the scores
4) A method to compute the final average
5) A method to determine the letter grade
Thanks for the question. Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks! =========================================================================== public class GradeCalculator { // one instance variables to store all the 10 scores in an array private int[] scores; public GradeCalculator(int[] scores) { this.scores = scores; } //1) A method to compute and return the highest score public int getHighestScore() { int highest = scores[0]; for (int i = 1; i < scores.length; i++) { if (scores[i] > highest) highest = scores[i]; } return highest; } //2) A method to compute and return the lowest score public int getLowestScore() { int lowest = scores[0]; for (int i = 1; i < scores.length; i++) { if (scores[i] < lowest) lowest = scores[i]; } return lowest; } //3) A method to compute the sum of all the scores public int getTotalScore() { int total = 0; for (int i = 0; i < scores.length; i++) total += scores[i]; return total; } //4) A method to compute the final average public double getFinalAverage() { double totalScore = getTotalScore(); totalScore = totalScore - getHighestScore() - getLowestScore(); return totalScore / (scores.length - 2); } //5) A method to determine the letter grade public char getLetterGrade() { double getFinalAverage = getFinalAverage(); if (getFinalAverage >= 91) return 'A'; else if (getFinalAverage >= 81) return 'B'; else if (getFinalAverage >= 71) return 'C'; else if (getFinalAverage >= 61) return 'D'; return 'E'; } public static void main(String[] args) { int scores [] = {40,70,89,67,89,90,78,65,78,88}; GradeCalculator calculator = new GradeCalculator(scores); System.out.println("calculator.getHighestScore() = " + calculator.getHighestScore()); System.out.println("calculator.getLowestScore() = " + calculator.getLowestScore()); System.out.println("calculator.getTotalScore() = " + calculator.getTotalScore()); System.out.println("calculator.getFinalAverage() = " + calculator.getFinalAverage()); System.out.println("calculator.getLetterGrade() = " + calculator.getLetterGrade()); } }
====================================================================