-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode
More file actions
63 lines (53 loc) · 1.83 KB
/
Copy pathCode
File metadata and controls
63 lines (53 loc) · 1.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
import java.util.Scanner;
public class GradeTracker {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the number of students: ");
int numStudents = scanner.nextInt();
// Arrays to store student grades
int[] grades = new int[numStudents];
// Input grades
for (int i = 0; i < numStudents; i++) {
System.out.print("Enter the grade for student " + (i + 1) + ": ");
grades[i] = scanner.nextInt();
}
// Calculate average, highest, and lowest grades
double average = calculateAverage(grades);
int highest = findHighest(grades);
int lowest = findLowest(grades);
// Display results
System.out.println("\nResults:");
System.out.println("The Average Grade of class is: " + average);
System.out.println("The Highest Grade of class is: " + highest);
System.out.println("The Lowest Grade of class is: " + lowest);
scanner.close();
}
// Method to calculate the average grade
private static double calculateAverage(int[] grades) {
int sum = 0;
for (int grade : grades) {
sum += grade;
}
return (double) sum / grades.length;
}
// Method to find the highest grade
private static int findHighest(int[] grades) {
int highest = grades[0];
for (int grade : grades) {
if (grade > highest) {
highest = grade;
}
}
return highest;
}
// Method to find the lowest grade
private static int findLowest(int[] grades) {
int lowest = grades[0];
for (int grade : grades) {
if (grade < lowest) {
lowest = grade;
}
}
return lowest;
}
}