Question

In: Computer Science

This is a Java program assignment. In the GradeCalculator class, compute the final average and letter...

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

Solutions

Expert Solution

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());

    }
}

====================================================================


Related Solutions

Create a Project and a Class called “FinalGrade” Write a Java program to compute your final...
Create a Project and a Class called “FinalGrade” Write a Java program to compute your final grade for the course. Assume the following (you can hard-code these values in your program). Assignments are worth 30% Labs are worth 40% Mid-term is worth 15% Final is worth 15% Ask for the grades in each category. Store them in a double variable. Print out the final percentage grade.           For example, Final Grade Calculation Enter percentage grades in the following order. Assignments,...
Java program. Need to create a class names gradesgraph which will represent the GradesGraphtest program. Assignment...
Java program. Need to create a class names gradesgraph which will represent the GradesGraphtest program. Assignment Create a class GradesGraph that represents a grade distribution for a given course. Write methods to perform the following tasks: • Set the number of each of the letter grades A, B, C, D, and F. • Read the number of each of the letter grades A, B, C, D, and F. • Return the total number of grades. • Return the percentage of...
I am struggling with this assignment for my java class. Objectives: Your program will be graded...
I am struggling with this assignment for my java class. Objectives: Your program will be graded according to the rubric below. Please review each objective before submitting your work so you don’t lose points. 1.Create a new project and class in Eclipse and add the main method. (5 points) 2. Construct a Scanner to read input from the keyboard. (5 points) 3. Prompt the user with three questions from the Psychology Today quiz, and use the Scanner to read their...
Modify the program 5-13 from page 279 such that will also compute the class average. This...
Modify the program 5-13 from page 279 such that will also compute the class average. This class average is in addition to each individual student score average. To accomplish this additional requirement, you should do the following: 1. Add two more variables of type double: one for accumulating student averages, and one to hold the class average. Don't forget, accumulator variable should be initialized to 0.0. 2. Immediately after computing individual student average, add a statement that will accumulate the...
Create the pseudocode solution to a program that calculates the final score and letter grade for...
Create the pseudocode solution to a program that calculates the final score and letter grade for one student. Please use the following grading system: 9 Homework Assignments – 100 points each 10 points 11 Quizzes – 100 points each 5 points 5 Projects – 100 points each 10 points 6 Discussion posts – 100 points each 10 points 4 Exams – 100 points each 65 points A = 90 – 100% B = 80 – 89% C = 70 –...
In Java Write a program that allows Professor Poindexter to get class averages including the average...
In Java Write a program that allows Professor Poindexter to get class averages including the average for allher/his classes. Professor Poindexter has M classes. M will be input from the terminal. For each class he/she will input each student’s grade for that class until 0 is input. Once the goof prof inputs 0, The class average for that class is output in the form:   Average for Class X 1 is XXX.XX Finally, once all the M class data is input,...
write a Java program Write a program to assign a letter grade according to the following...
write a Java program Write a program to assign a letter grade according to the following scheme: A: total score >= 90 B: 80 <= total score < 90 C: 70 <= total score < 80 D: 60 <= total score < 70 F: total score < 60 Output - the student's total score (float, 2 decimals) and letter grade Testing - test your program with the following input data: test1 = 95; test2 = 80; final = 90; assignments...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class,...
JAVA PROGRAMMING. In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) id: String   (5 pts) hours: int   (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an exception...
Create an Java application that uses a class to convert number grades to letter grades and...
Create an Java application that uses a class to convert number grades to letter grades and another class for data validation. Specifications The Grade class should have only one Instance Variable of type int. Use a class named Grade to store the data for each grade. This class should include these three methods:   public void setNumber(int number)   public int getNumber()   public String getLetter() The Grade class should have two constructors. The first one should accept no parameters and set the...
The java.awt.Rectangle class of the standard Java library does not supply a method to compute the...
The java.awt.Rectangle class of the standard Java library does not supply a method to compute the area or perimeter of a rectangle. Provide a subclass BetterRectangle of the Rectangle class that has getPerimeter and getArea methods. Do not add any instance variables. In the constructor, call the setLocation and setSize methods of the Rectangle class. In Main class, provide 3 test cases that tests the methods that you supplied printing expected and actual results. The test cases are: 1) One...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT