-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentService.java
More file actions
50 lines (42 loc) · 1.36 KB
/
Copy pathStudentService.java
File metadata and controls
50 lines (42 loc) · 1.36 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
package studentManagementSystem;
import java.util.*;
public class StudentService {
private List<Student> studentList = new ArrayList<>();
public void addStudent(Student student) {
studentList.add(student);
System.out.println("Student added successfully.");
}
public void viewStudents() {
if (studentList.isEmpty()) {
System.out.println("No students found.");
return;
}
for (Student s : studentList) {
System.out.println(s);
}
}
public void deleteStudent(int id) {
studentList.removeIf(s -> s.getId() == id);
System.out.println("Student removed if existed.");
}
public void searchStudent(int id) {
for (Student s : studentList) {
if (s.getId() == id) {
System.out.println("Found: " + s);
return;
}
}
System.out.println("Student not found.");
}
public void updateStudent(int id, String name, String dept) {
for (Student s : studentList) {
if (s.getId() == id) {
s.setName(name);
s.setDepartment(dept);
System.out.println("Student updated.");
return;
}
}
System.out.println("Student not found.");
}
}