173k views
5 votes
Write a program in Java that asks the user to enter four weighted assessment grades, calculate the average, then display the average with the message: "Student Pass" if the average is greater than or equal 60 or the message "Student Fail" otherwise. The details of the assessments and weights are as follow: Homeworks: 20% Labs: 15% Midterm: 25% Final: 40%

1 Answer

3 votes

Answer:

Step-by-step explanation:

In order to calculate the weighted average, the grade itself is multiplied by the percentage of the category and then these values are summed. This sum is then divided by the total percentage of the portfolio.

import java.util.Scanner;

class Main {

public static void main(String[] args) {

double sumOfWeights = 100;

Scanner in = new Scanner(System.in);

System.out.println("Please Enter Homework Grade: ");

double homework = in.nextDouble() * 20;

System.out.println("Please Enter Labs Grade: ");

double labs = in.nextDouble() * 15;

System.out.println("Please Enter Midterm Grade: ");

double midterm = in.nextDouble() * 25;

System.out.println("Please Enter Final Grade: ");

double finals = in.nextDouble() * 40;

double average = (homework + labs + midterm + finals) / sumOfWeights;

System.out.println("The Average of these Weighted Grades is " + average);

}

}

User Kaushik Shankar
by
4.9k points