-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudGradeManager.java
More file actions
101 lines (75 loc) · 2.69 KB
/
StudGradeManager.java
File metadata and controls
101 lines (75 loc) · 2.69 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
96
97
98
99
100
import java.util.ArrayList;
import java.util.Scanner;
public class StudGradeManager {
public static void main(String[] args){
ArrayList<Student> students = new ArrayList<>();
Scanner sc = new Scanner(System.in);
//MENU FOR USER TO SELECT WHICH OPERATION TO PERFORM
while(true){
System.out.println("\nStudent Grade Manager");
System.out.println("1. Add Student");
System.out.println("2. View Students");
System.out.println("3. Calculate Average");
System.out.println("4. Exit");
System.out.print("Enter your choice:");
int choice = sc.nextInt();
switch(choice){
case 1:
sc.nextLine();
System.out.println("Enter Student name: ");
String name = sc.nextLine();
System.out.println("Enter roll number: ");
int rollNo = sc.nextInt();
System.out.println("Enter grade: ");
double grade = sc.nextDouble();
Student s = new Student(name,rollNo,grade);
students.add(s);
System.out.println("Student added successfully!");
break;
case 2:
if(students.size() == 0){
System.out.println("No students added yet.");
} else {
System.out.println("\nStudent List:");
for(int i = 0; i < students.size(); i++){
Student student = students.get(i);
System.out.println(
"Name: " + student.name +
", Roll No: " + student.rollNo +
", Grade: " + student.grade
);
}
}
break;
case 3:
if(students.size() == 0){
System.out.println("No students available to calculate average.");
}else{
double sum = 0;
for(int i = 0;i<students.size();i++){
sum+=students.get(i).grade;
}
double average = sum / students.size();
System.out.println("Average grade: " + average);
}
break;
case 4:
System.out.println("Exiting program...");
sc.close();
return;
default:
System.out.println("Invalid choice");
}
}
}
}
class Student {
String name;
int rollNo;
double grade;
Student(String name,int rollNo,double grade){
this.name = name;
this.rollNo = rollNo;
this.grade = grade;
}
}