Repository navigation
Expand file tree
/
Copy pathStudentManagementSystem.java
More file actions
145 lines (112 loc) · 3.97 KB
/
Copy pathStudentManagementSystem.java
File metadata and controls
145 lines (112 loc) · 3.97 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import java.util.*;
class Student {
int id;
String name;
int age;
String course;
Student(int id, String name, int age, String course) {
this.id = id;
this.name = name;
this.age = age;
this.course = course;
}
void display() {
System.out.println("ID: " + id + ", Name: " + name +
", Age: " + age + ", Course: " + course);
}
}
public class StudentManagementSystem {
static ArrayList<Student> students = new ArrayList<>();
static Scanner sc = new Scanner(System.in);
public static void addStudent() {
System.out.print("Enter ID: ");
int id = sc.nextInt();
sc.nextLine();
System.out.print("Enter Name: ");
String name = sc.nextLine();
System.out.print("Enter Age: ");
int age = sc.nextInt();
sc.nextLine();
System.out.print("Enter Course: ");
String course = sc.nextLine();
students.add(new Student(id, name, age, course));
System.out.println("✅ Student Added Successfully!");
}
public static void viewStudents() {
if (students.isEmpty()) {
System.out.println("⚠️No students found!");
return;
}
for (Student s : students) {
s.display();
}
}
public static void searchStudent() {
System.out.print("Enter ID to search: ");
int id = sc.nextInt();
for (Student s : students) {
if (s.id == id) {
System.out.println(" Student Found:");
s.display();
return;
}
}
System.out.println("❌ Student not found!");
}
public static void updateStudent() {
System.out.print("Enter ID to update: ");
int id = sc.nextInt();
sc.nextLine();
for (Student s : students) {
if (s.id == id) {
System.out.print("Enter new name: ");
s.name = sc.nextLine();
System.out.print("Enter new age: ");
s.age = sc.nextInt();
sc.nextLine();
System.out.print("Enter new course: ");
s.course = sc.nextLine();
System.out.println("✅ Student Updated!");
return;
}
}
System.out.println("❌ Student not found!");
}
public static void deleteStudent() {
System.out.print("Enter ID to delete: ");
int id = sc.nextInt();
Iterator<Student> it = students.iterator();
while (it.hasNext()) {
Student s = it.next();
if (s.id == id) {
it.remove();
System.out.println("🗑️ Student Deleted!");
return;
}
}
System.out.println("❌ Student not found!");
}
public static void main(String[] args) {
int choice;
do {
System.out.println("\n Student Management System ");
System.out.println("1. Add Student");
System.out.println("2. View Students");
System.out.println("3. Search Student");
System.out.println("4. Update Student");
System.out.println("5. Delete Student");
System.out.println("6. Exit");
System.out.print("Enter your choice: ");
choice = sc.nextInt();
switch (choice) {
case 1: addStudent(); break;
case 2: viewStudents(); break;
case 3: searchStudent(); break;
case 4: updateStudent(); break;
case 5: deleteStudent(); break;
case 6: System.out.println(" Exiting..."); break;
default: System.out.println(" Invalid choice!");
}
} while (choice != 6);
}
}