-
Notifications
You must be signed in to change notification settings - Fork 0
/
CalculateGrade.java
42 lines (35 loc) · 1.43 KB
/
CalculateGrade.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.util.Scanner;
public class Grades {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Get marks in each subject
System.out.println("Enter marks obtained in Physics (out of 100): ");
int physicsMarks = scanner.nextInt();
System.out.println("Enter marks obtained in Chemistry (out of 100): ");
int chemistryMarks = scanner.nextInt();
System.out.println("Enter marks obtained in Mathematics (out of 100): ");
int mathsMarks = scanner.nextInt();
// Calculate total marks and average percentage
int totalMarks = physicsMarks + chemistryMarks + mathsMarks;
double averagePercentage = (totalMarks * 1.0) / 3;
// Grade calculation
String grade = "A+";
if (averagePercentage >= 90) {
grade = "A+";
} else if (averagePercentage >= 80) {
grade = "A";
} else if (averagePercentage >= 70) {
grade = "B";
} else if (averagePercentage >= 60) {
grade = "C";
} else if (averagePercentage >= 50) {
grade = "D";
} else {
grade = "F";
}
// Display results
System.out.println("Total Marks: " + totalMarks);
System.out.println("Average Percentage: " + averagePercentage);
System.out.println("Grade: " + grade);
}
}