-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentList.java
More file actions
59 lines (48 loc) · 1.21 KB
/
Copy pathStudentList.java
File metadata and controls
59 lines (48 loc) · 1.21 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
import java.util.ArrayList;
public class StudentList {
public static ArrayList < Student > stuList;
//constructor of StudentList
public StudentList() {
stuList = new ArrayList < Student > ();
}
//returns size of stuList
public int size() {
return stuList.size();
}
//returns the Student in index "index" of stuList
public Student get(int index) {
return stuList.get(index);
}
//returns the last student in the list
public Student getLast(){
return stuList.get(stuList.size() -1);
}
//returns stuList
public ArrayList < Student > getList() {
return stuList;
}
//returns the position where the match was found in the list
//returns -1 otherwise
public int searchID(String idNum) {
int pos = 0;
for (Student stu : stuList) {
String id = stu.getID();
if(id.compareTo(idNum)==0)
return pos;
pos++;
}
return -1;
}
//sets the student as "object" at position "index"
public void set(int index, Student object) {
stuList.set(index, object);
}
//sets stuList to stu
public void setList(ArrayList < Student > stu) {
stuList = stu;
}
//adds a new student to stuList
public void add(Student name) {
stuList.add(name);
}
}