forked from kavitavadd/codealphatask
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentGradeTracker.java
More file actions
93 lines (71 loc) · 2.74 KB
/
Copy pathStudentGradeTracker.java
File metadata and controls
93 lines (71 loc) · 2.74 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.ArrayList;
import java.util.Scanner;
class Student {
String name;
double grade;
Student(String name, double grade) {
this.name = name;
this.grade = grade;
}
}
public class StudentGradeTracker {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<Student> students = new ArrayList<>();
int choice;
do {
System.out.println("\n..... Student Grade Tracker .......");
System.out.println("1. Add Student");
System.out.println("2. View Summary Report");
System.out.println("3. Exit");
System.out.print("Enter your choice: ");
choice = sc.nextInt();
sc.nextLine();
switch (choice) {
case 1:
System.out.print("Enter student name: ");
String name = sc.nextLine();
System.out.print("Enter student grade: ");
double grade = sc.nextDouble();
students.add(new Student(name, grade));
System.out.println("Student added successfully!");
break;
case 2:
displayReport(students);
break;
case 3:
System.out.println("Exiting program...");
break;
default:
System.out.println("Invalid choice! Try again.");
}
} while (choice != 3);
sc.close();
}
public static void displayReport(ArrayList<Student> students) {
if (students.isEmpty()) {
System.out.println("No student records available.");
return;
}
double total = 0;
double highest = students.get(0).grade;
double lowest = students.get(0).grade;
System.out.println("\n===== Student Summary Report =====");
System.out.printf("%-20s %-10s%n", "Student Name", "Grade");
for (Student student : students)
{
System.out.printf("%-20s %-10.2f%n",
student.name, student.grade);
total += student.grade;
if (student.grade > highest)
highest = student.grade;
if (student.grade < lowest)
lowest = student.grade;
}
double average = total / students.size();
System.out.println("--------------------------------");
System.out.printf("Average Score : %.2f%n", average);
System.out.printf("Highest Score : %.2f%n", highest);
System.out.printf("Lowest Score : %.2f%n", lowest);
}
}