A java question Question 2 Creating a Grading Program 50 poi
A java question
Question 2: Creating a Grading Program (50 points)
 The goal of this question is to write several methods to create a program for outputting student grades.
 All the code for this question must be placed in a le named GradingProgram.java. Note that this
 means the class must also be named GradingProgram.
 2a)Void Method for Con rming Entry
 Write a method printInput that takes as input three double arguments and prints these numbers.
 You must include all three numbers as part of a message, separated by commas. For example, your
 message could be \\You entered 34.0, -12.2, and 4.0\".
 Note that for full marks, this message must be written on one line. Research the + operator for Strings,
 or the System.out.print() and System.out.println() statements.
 Hint: To test your method, create a main method. The main method will not be graded in
 GradingProgram.java, but without it, you won\'t know whether or not your method works!
 Your main method should call this printInput method and verify the results. You should
 think of other cases to test!
 2b)Methods for Calculations
 To make the GradingProgram more interesting, we will write a division method and a maximum method.
 Write a method divide inside of GradingProgram.java that takes as input two double values. This
 method should return the result of dividing the rst method parameter by the second. The return value
 must be a double value.
 Note that division doesn\'t work if the second parameter is zero. Therefore, if the second parameter is
 zero, the method should print an appropriate error message, and then return zero. Your method must
 not print anything if the second parameter is not zero.
 To test your divide method, you will need to call it from your main method. Think about how you can
 call the method and then display the answer.
 As well, write another method getMax that takes two doubles values as input. getMax must returns the
 larger of the two input values, and the return type must be double. In the case of a tie, return either
 value. Don\'t use the built-in max method.
 2c)Method Calling
 Now we will use the divide and getMax methods to calculate student grades.
 Write a method finalGrade that takes as input three double values and returns the nal percentage
 out of 100 for a COMP 202 student. The return value must also be a double.
 The rst value corresponds to the total assignment grade out of 35.
 The second is the midterm mark out of 20.
 And the third is the nal exam mark out of 45.
 Recall that if the student does better on the nal than on the midterm, the mark for the nal replaces
 the mark for the midterm. Therefore, you will have to calculate which is greater:
 1. The assignment grade plus the midterm grade plus the nal grade divided by 100 OR
 2. The assignment grade plus the nal grade divided by 80
 Page 4
 Note that you must use the divide method that you created earlier to divide the sums. Then you must
 use your getMax method to determine which percentage would be higher. Finally, the percentage will
 then be less than 1, so multiply the answer by 100 before returning it.
 For example, a student might have 28 out of 35 for assignments, 18 on 20 for the midterm, and 30 on 45
 for the nal. The finalGrade method takes these numbers 28.0, 18.0, 30.0 as input, in order, and
 would output a nal grade of 76 (to represent 76%).
 A student who instead had marks of 28.0, 16.0, 38.0 would have a nal grade of 82.5 (to represent
 82.5%). In this case, the midterm grade is dropped, because the student\'s performance in the course is
 higher using the alternate grading scheme.
Solution
CODE:
package temp;
public class GradingProgram {
   // printInput method to display the 3 values.
    public void printInput(double a, double b, double c){
        System.out.println(\"You entered \" + a + \", \" + b + \", \" + c);
    }
   
    // divide method
    public double divideMtd(double a, double b){
       
        // Check if 2nd parameter is ZERO.
        if ( b == 0){
            System.out.println(\"Second parameter to the divide function is zero !!\");
            return 0;
        }
        else{
            return a/b;
        }
    }
   
    // getMax method without using built in method.
    public double getMax (double a, double b){
        if (a == b)
            return a;
        else if (a > b)
            return a;
        else
            return b;
    }
   
    // Method to calculate final percentage
    public double finalGrade(double rst, double midterm, double nal){
       
        // Option 1: totalMarks/100 calculation
        double totalMarks = rst + midterm + nal;
        double percent1 = divideMtd(totalMarks, 100);
       
        // Option 2: rst and nal marks divided by 80.
        totalMarks = rst + nal;
        double percent2 = divideMtd(totalMarks, 80);
       
        // Get the maximum of the two percentages obtained above.
        double finalPercent = getMax(percent1, percent2);
       
        // Multiply finalPercent by 100.
        finalPercent = finalPercent * 100;
       
        return finalPercent;
    }
    public static void main(String[] args) {
       
        // Create an instance of the class here.
        GradingProgram gp = new GradingProgram();
       
        // Enter the marks obtained in various exams here.
        double rst = 28;
        double midterm = 18;
        double nal = 30;
       
        // printInput method to print the marks
        gp.printInput(rst, midterm, nal);
       
        // To check if the divide method is working fine.
        double res = gp.divideMtd(10, 10);      
        System.out.println(\"Result of divide method is \" + res);
       
        // To check if the getMax method is working fine.
        res = gp.getMax(1, 10);
        System.out.println(\"Result of getMax method is \" + res);
       
        // Call the finalGrade method to obtain the percentage.
        double percent = gp.finalGrade(rst, midterm, nal);
        System.out.println(\"Total percentage is \" + percent);
    }
}
OUTPUT:
You entered 28.0, 18.0, 30.0
 Result of divide method is 1.0
 Result of getMax method is 10.0
 Total percentage is 76.0



