-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentGradeTracker.java
More file actions
95 lines (67 loc) · 2.83 KB
/
Copy pathStudentGradeTracker.java
File metadata and controls
95 lines (67 loc) · 2.83 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
import java.util.Scanner;
public class StudentGradeTracker {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("========================================");
System.out.println(" STUDENT GRADE TRACKER");
System.out.println("========================================");
// Get number of students
System.out.print("\nEnter number of students: ");
int n = sc.nextInt();
sc.nextLine(); // Clear input buffer
// Arrays to store student information
String[] names = new String[n];
double[] grades = new double[n];
// Input student details
for (int i = 0; i < n; i++) {
System.out.print("\nEnter student " + (i + 1) + " name: ");
names[i] = sc.nextLine();
System.out.print("Enter " + names[i] + "'s grade: ");
grades[i] = sc.nextDouble();
sc.nextLine(); // Clear input buffer
}
// Variables for calculations
double total = 0;
double highest = grades[0];
double lowest = grades[0];
int highestIndex = 0;
int lowestIndex = 0;
// Calculate total, highest and lowest
for (int i = 0; i < n; i++) {
total = total + grades[i];
if (grades[i] > highest) {
highest = grades[i];
highestIndex = i;
}
if (grades[i] < lowest) {
lowest = grades[i];
lowestIndex = i;
}
}
// Calculate average
double average = total / n;
// Display summary report
System.out.println("\n========================================");
System.out.println(" SUMMARY REPORT");
System.out.println("========================================");
System.out.printf("%-20s %s%n", "Student", "Grade");
System.out.println("----------------------------------------");
for (int i = 0; i < n; i++) {
System.out.printf(
"%-20s %.2f%n",
names[i],
grades[i]
);
}
System.out.println("----------------------------------------");
System.out.printf("Average Grade : %.2f%n", average);
System.out.printf("Highest Grade : %.2f%n", highest);
System.out.printf("Lowest Grade : %.2f%n", lowest);
System.out.println("----------------------------------------");
System.out.println("Highest Scorer : " + names[highestIndex]);
System.out.println("Lowest Scorer : " + names[lowestIndex]);
System.out.println("========================================");
System.out.println("\nThank you for using Student Grade Tracker!");
sc.close();
}
}