-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task2.java
51 lines (41 loc) · 1.58 KB
/
Task2.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
43
44
45
46
47
48
49
50
51
import java.util.Scanner;
public class Task2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Student Grade Calculator");
System.out.print("Enter the number of subjects: ");
int numSubjects = scanner.nextInt();
int totalMarks = 0;
for (int i = 1; i <= numSubjects; i++) {
System.out.print("Enter marks obtained in subject " + i + ": ");
int marks = scanner.nextInt();
totalMarks += marks;
}
double averagePercentage = (double) totalMarks / (numSubjects * 100) * 100;
System.out.println("Total Marks: " + totalMarks);
System.out.println("Average Percentage: " + averagePercentage + "%");
String grade = calculateGrade(averagePercentage);
System.out.println("Grade: " + grade);
if(grade.equals("F")){
System.out.println("you are failed the exam");
}else{
System.out.println("you passed the exam");
}
scanner.close();
}
public static String calculateGrade(double percentage) {
if (percentage >= 90) {
return "A+";
} else if (percentage >= 80) {
return "A";
} else if (percentage >= 70) {
return "B";
} else if (percentage >= 60) {
return "C";
} else if (percentage >= 50) {
return "D";
} else {
return "F";
}
}
}