-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentGradeCalculator.java
More file actions
98 lines (76 loc) · 3.03 KB
/
Copy pathStudentGradeCalculator.java
File metadata and controls
98 lines (76 loc) · 3.03 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import java.util.Scanner;
public class StudentGradeCalculator {
// Method to calculate grade
public static String calculateGrade(double percentage) {
if (percentage >= 90) {
return "A";
} else if (percentage >= 80) {
return "B";
} else if (percentage >= 70) {
return "C";
} else if (percentage >= 60) {
return "D";
} else {
return "F";
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("====================================");
System.out.println(" STUDENT GRADE CALCULATOR");
System.out.println("====================================");
// Student Name
System.out.print("Enter Student Name: ");
String studentName = sc.nextLine();
// Number of Subjects
System.out.print("Enter Number of Subjects: ");
int numberOfSubjects = sc.nextInt();
while (numberOfSubjects <= 0) {
System.out.print("Invalid input! Enter valid number of subjects: ");
numberOfSubjects = sc.nextInt();
}
int totalMarks = 0;
int highestMarks = 0;
int lowestMarks = 100;
// Input marks
for (int i = 1; i <= numberOfSubjects; i++) {
System.out.print("Enter marks for Subject " + i + " (0-100): ");
int marks = sc.nextInt();
while (marks < 0 || marks > 100) {
System.out.print("Invalid marks! Enter between 0 and 100: ");
marks = sc.nextInt();
}
totalMarks += marks;
if (marks > highestMarks) {
highestMarks = marks;
}
if (marks < lowestMarks) {
lowestMarks = marks;
}
}
// Calculations
double average = (double) totalMarks / numberOfSubjects;
double percentage = average;
// Grade
String grade = calculateGrade(percentage);
// Output
System.out.println("\n====================================");
System.out.println(" STUDENT RESULT");
System.out.println("====================================");
System.out.println("Student Name : " + studentName);
System.out.println("Subjects : " + numberOfSubjects);
System.out.println("Total Marks : " + totalMarks);
System.out.printf("Average Marks : %.2f%n", average);
System.out.printf("Percentage : %.2f%%%n", percentage);
System.out.println("Highest Marks : " + highestMarks);
System.out.println("Lowest Marks : " + lowestMarks);
System.out.println("Grade : " + grade);
if (percentage >= 40) {
System.out.println("Result : PASS");
} else {
System.out.println("Result : FAIL");
}
System.out.println("====================================");
sc.close();
}
}