-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentManagementSystem.java
More file actions
65 lines (53 loc) · 1.8 KB
/
StudentManagementSystem.java
File metadata and controls
65 lines (53 loc) · 1.8 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
class Student {
// Static variable shared across all students
private static String universityName = "Engineering College of India";
private static int totalStudents = 0;
// Final variable for roll number
private final int rollNumber;
private String name;
private String grade;
// Constructor
public Student(String name, int rollNumber, String grade) {
this.name = name;
this.rollNumber = rollNumber;
this.grade = grade;
totalStudents++;
}
// Static method to display total students
public static void displayTotalStudents() {
System.out.println("Total Students Enrolled: " + totalStudents);
}
// Method to display student details
public void displayDetails() {
if (this instanceof Student) {
System.out.println("Name: " + name + ", Roll Number: " + rollNumber + ", Grade: " + grade);
}
}
// Method to update grade
public void updateGrade(String grade) {
if (this instanceof Student) {
this.grade = grade;
}
}
}
public class StudentManagementSystem {
public static void main(String[] args) {
// Create student instances
Student student1 = new Student("Manan", 101, "A");
Student student2 = new Student("Naman", 102, "B");
// Display student details
student1.displayDetails();
student2.displayDetails();
// Update student grade
student2.updateGrade("A+");
// Display updated details
student2.displayDetails();
// Display total number of students
Student.displayTotalStudents();
}
}
//SampleOutput
//Name: Manan, Roll Number: 101, Grade: A
//Name: Naman, Roll Number: 102, Grade: B
//Name: Naman, Roll Number: 102, Grade: A+
//Total Students Enrolled: 2