StudentManager and StudentLoader completed.

This commit is contained in:
2026-06-10 22:32:39 +03:30
parent fa3f20a54b
commit 6f5da83c47
3 changed files with 27 additions and 41 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ public class Student {
@Override
public boolean equals(Object obj) {
if (obj == null) return false;
if (this == obj) return true;
if (this.getClass() != obj.getClass()) return false;
+13 -19
View File
@@ -10,34 +10,28 @@ public class StudentManager {
private final ArrayList<Student> students = new ArrayList<>();
public void addStudents(ArrayList<Student> newStudents) {
// TODO:
// Merge students
// Hint:
// addAll()
if (newStudents != null && !newStudents.isEmpty()) {
students.addAll(newStudents);
}
}
public Student searchStudent(int id) {
// TODO:
// Loop through students
// Compare IDs
for (Student student: students) {
if (student.getId() == id) {
return student;
}
}
return null;
}
public boolean removeStudent(int id) {
Student s = searchStudent(id);
// TODO:
// Find student
// Remove student
if (s != null) {
students.remove(s);
return true;
}
return false;
}
+13 -21
View File
@@ -24,35 +24,27 @@ public class StudentLoader extends Thread {
@Override
public void run() {
// TODO:
/*
Example line:
1001,Aryan,Computer Science,3.7
*/
for (String line : lines) {
try {
String[] parts = line.split(",");
// TODO:
// split line
if(parts.length == 4) {
int id = Integer.parseInt(parts[0].trim());
String name = parts[1].trim();
String major = parts[2].trim();
double gpa = Double.parseDouble(parts[3].trim());
// TODO:
// read values
// TODO:
// create Student
// TODO:
// add to students list
Student student = new Student(id,name,major,gpa);
students.add(student);
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
public ArrayList<Student> getStudents() {
return students;
}