-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentGradingSystem.java
More file actions
65 lines (55 loc) · 1.73 KB
/
StudentGradingSystem.java
File metadata and controls
65 lines (55 loc) · 1.73 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
import java.util.Scanner;
class Student {
String name;
int rollNo;
int[] marks = new int[5];
int total = 0;
double average;
char grade;
void inputDetails(Scanner sc) {
System.out.print("Enter student name: ");
name = sc.nextLine();
System.out.print("Enter roll number: ");
rollNo = sc.nextInt();
System.out.println("Enter marks for 5 subjects (out of 100):");
for (int i = 0; i < 5; i++) {
System.out.print("Subject " + (i + 1) + ": ");
marks[i] = sc.nextInt();
total += marks[i];
}
average = total / 5.0;
assignGrade();
}
void assignGrade() {
if (average >= 90) {
grade = 'A';
} else if (average >= 80) {
grade = 'B';
} else if (average >= 70) {
grade = 'C';
} else if (average >= 60) {
grade = 'D';
} else if (average >= 40) {
grade = 'E';
} else {
grade = 'F'; // Fail
}
}
void printReport() {
System.out.println("\n----- Student Grade Report -----");
System.out.println("Name : " + name);
System.out.println("Roll No. : " + rollNo);
System.out.println("Total Marks: " + total + "/500");
System.out.printf("Average : %.2f%%\n", average);
System.out.println("Grade : " + grade);
}
}
public class StudentGradingSystem {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Student student = new Student();
student.inputDetails(sc);
student.printReport();
sc.close();
}
}