-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeAlphaStudentGradeTracker.java
More file actions
68 lines (49 loc) · 1.65 KB
/
Copy pathCodeAlphaStudentGradeTracker.java
File metadata and controls
68 lines (49 loc) · 1.65 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
import java.util.ArrayList;
import java.util.Scanner;
class Student {
String name;
double grade;
Student(String name, double grade) {
this.name = name;
this.grade = grade;
}
}
public class CodeAlphaStudentGradeTracker {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<Student> students = new ArrayList<>();
System.out.print("Enter number of students: ");
int n = sc.nextInt();
sc.nextLine();
for (int i = 0; i < n; i++) {
System.out.println("\nStudent " + (i + 1));
System.out.print("Enter Name: ");
String name = sc.nextLine();
System.out.print("Enter Grade: ");
double grade = sc.nextDouble();
sc.nextLine();
students.add(new Student(name, grade));
}
double total = 0;
double highest = students.get(0).grade;
double lowest = students.get(0).grade;
for (Student s : students) {
total += s.grade;
if (s.grade > highest) {
highest = s.grade;
}
if (s.grade < lowest) {
lowest = s.grade;
}
}
double average = total / students.size();
System.out.println("\n===== STUDENT REPORT =====");
for (Student s : students) {
System.out.println("Name: " + s.name + " | Grade: " + s.grade);
}
System.out.println("\nAverage Grade: " + average);
System.out.println("Highest Grade: " + highest);
System.out.println("Lowest Grade: " + lowest);
sc.close();
}
}