-
Notifications
You must be signed in to change notification settings - Fork 0
/
StudentManager.java
46 lines (38 loc) · 1.16 KB
/
StudentManager.java
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
package studentOop;
import java.util.List;
import java.util.ArrayList;
public class StudentManager extends Student{
ArrayList<Student> students = new ArrayList<Student>();
public StudentManager() {
super();
}
public void add(Student addedStudent) {
if(students.contains(addedStudent)) {
System.out.println("This student already exists !");
return;
}
this.students.add(addedStudent);
System.out.println("Student " + addedStudent.getId() + " has been successfully added !");
}
public void delete(int id) {
Student studentDeleted = new Student();
for (Student student : students) {
if(student.getId() == id) {
studentDeleted = student;
}
}
students.remove(studentDeleted);
System.out.println("Student " + studentDeleted.getId() + " has been successfully deleted !");
}
public void update(Student studentUpdated, int id) {
for (Student student : students) {
if (id == studentUpdated.getId()) {
studentUpdated = student;
}
}
System.out.println("Student " + id + " has been successfully updated !");
}
public ArrayList<Student> getAll(){
return this.students;
}
}