In: Computer Science
Question 2: Write a java program that calculates the weighted average of three grades
using the method with header public static double CalculateWeightedAverage (double
grade1, double grade2, double grade3), such that: [4 Marks]
Weighted average = grade1 * 0.5 + grade2 * 0.25 + grade3 * 0.25
The program in the main method will:
o ask the user to enter the three grades
o and then call the method that will calculate the weighted average
o and finally display the weighted average
Answer for the above question:
code:
import java.util.*;
class Main{
public static double CalculateWeightedAverage(double grade1,double grade2,double grade3 ){
double weighted_average = grade1*0.5+grade2*0.25+grade3*0.25;
return weighted_average;
}
public static void main(String args[]){
Scanner scnr = new Scanner(System.in);
System.out.print("Enter grade1 :");
double grade1 = scnr.nextDouble();
System.out.print("Enter grade2 :");
double grade2 = scnr.nextDouble();
System.out.print("Enter grade3 :");
double grade3 = scnr.nextDouble();
double weighted_average = CalculateWeightedAverage(grade1,grade2,grade3);
System.out.println("Weighted average of three grade :"+weighted_average);
}
}
OUTPUT:
PS: If you have any doubt please mention in comment section. I will solve it.