-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandle.java
More file actions
69 lines (61 loc) · 1.77 KB
/
Copy pathHandle.java
File metadata and controls
69 lines (61 loc) · 1.77 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
import javax.swing.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Handle {
private ArrayList<Student> list;
public Handle(){
list = new ArrayList<Student>();
}
public void add(Student student){
this.list.add(student);
}
public void addStudent(){
Student student = new Student();
student.addStudent();
if((findStudent(student.getId()) != null)){
System.out.println("Student id already exist! Try again");
addStudent();
}
this.add(student);
}
public void updateStudent(){
System.out.println("Your student ID for update?");
int id = Integer.parseInt((new Scanner(System.in)).nextLine());
for (Student student : list) {
if (student.getId() == id) {
student.updateStudent();
}
}
System.out.println("Updated!");
}
public Student findStudent(int id){
for (Student student : list) {
if (student.getId() == id) {
return student;
}
}
return null;
}
public void outStudent(){
System.out.println("Print all student:");
for(Student student: list){
student.outStudent();
System.out.println("____");
}
}
//Delete student
public void destroyById() {
System.out.println("ID?");
int id = Integer.parseInt((new Scanner(System.in)).nextLine());
for (Student student : list) {
if (student.getId() == id) {
list.remove(student);
}
}
System.out.println("Destroyed");
}
public void sortName() {
Collections.sort(list, new sortName());
}
}