+ Implemented the solution for the question asked in lecture + Changed students.txt format to csv
48 lines
858 B
Java
48 lines
858 B
Java
package dev.service;
|
|
|
|
import dev.model.Student;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
public class StudentManager {
|
|
|
|
private final ArrayList<Student> students = new ArrayList<>();
|
|
|
|
public void addStudents(ArrayList<Student> newStudents) {
|
|
students.addAll(newStudents);
|
|
}
|
|
|
|
public Student searchStudent(int id) {
|
|
for (Student student : students){
|
|
if (student.getId() == id){
|
|
return student;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public boolean removeStudent(int id) {
|
|
|
|
Student student = searchStudent(id);
|
|
|
|
if (student != null){
|
|
students.remove(student);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public void printStudents() {
|
|
|
|
for (Student student : students) {
|
|
|
|
System.out.println(student);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} |