-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentGradeTracker.java
More file actions
93 lines (67 loc) · 2.33 KB
/
Copy pathStudentGradeTracker.java
File metadata and controls
93 lines (67 loc) · 2.33 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
import java.util.Scanner;
class Student {
String name;
int marks;
Student(String name, int marks) {
this.name = name;
this.marks = marks;
}
String getGrade() {
if (marks >= 90) return "A";
if (marks >= 80) return "B";
if (marks >= 70) return "C";
if (marks >= 60) return "D";
if (marks >= 50) return "E";
return "F";
}
}
public class StudentGradeTracker {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of students: ");
int n = sc.nextInt();
sc.nextLine();
if (n <= 0) {
System.out.println("Number of students must be greater than 0.");
sc.close();
return;
}
Student[] students = new Student[n];
int total = 0;
int highest = -1;
int lowest = 101;
for (int i = 0; i < n; i++) {
System.out.print("\nEnter name of Student " + (i + 1) + ": ");
String name = sc.nextLine();
int marks;
while (true) {
System.out.print("Enter marks (0-100): ");
marks = sc.nextInt();
if (marks >= 0 && marks <= 100) {
break;
}
System.out.println("Invalid marks. Please enter a value between 0 and 100.");
}
sc.nextLine();
students[i] = new Student(name, marks);
total += marks;
if (marks > highest)
highest = marks;
if (marks < lowest)
lowest = marks;
}
System.out.println("\n========== STUDENT REPORT ==========");
for (Student student : students) {
System.out.println(
student.name + " | Marks: " + student.marks +
" | Grade: " + student.getGrade()
);
}
double average = (double) total / n;
System.out.println("\nAverage Marks : " + average);
System.out.println("Highest Marks : " + highest);
System.out.println("Lowest Marks : " + lowest);
System.out.println("====================================");
sc.close();
}
}