-
Notifications
You must be signed in to change notification settings - Fork 0
/
StudentGradeCalculator.java
64 lines (52 loc) · 1.55 KB
/
StudentGradeCalculator.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
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.util.Scanner;
public class StudentGradeCalculator
{
public static void main(String[] args)
{
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the Number of Subjects: ");
int numSubjects = scanner.nextInt();
int[] marks = new int[numSubjects];
int totalMarks = 0;
for (int i = 0; i < numSubjects; i++)
{
System.out.print("Enter marks obtained in each Subject " + (i + 1) + ": ");
marks[i] = scanner.nextInt();
totalMarks += marks[i];
}
double averagePercentage = (double) totalMarks / (numSubjects * 100) * 100;
System.out.println("Your Result is Here:");
System.out.println("Your Total Marks: " + totalMarks);
System.out.println("Average Percentage: " + averagePercentage + "%");
String grade = calculateGrade(averagePercentage);
System.out.println("Grade: " + grade);
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";
}
}
}