-
Notifications
You must be signed in to change notification settings - Fork 0
/
StudentGroup.java
230 lines (199 loc) · 5.56 KB
/
StudentGroup.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
/**
* A fix-sized array of students
* array length should always be equal to the number of stored elements
* after the element was removed the size of the array should be equal to the number of stored elements
* after the element was added the size of the array should be equal to the number of stored elements
* null elements are not allowed to be stored in the array
*
* You may add new methods, fields to this class, but DO NOT RENAME any given class, interface or method
* DO NOT PUT any classes into packages
*
*/
public class StudentGroup implements StudentArrayOperation {
private Student[] students;
/**
* DO NOT remove or change this constructor, it will be used during task check
* @param length
*/
public StudentGroup(int length) {
this.students = new Student[length];
}
@Override
public Student[] getStudents() {
// Add your implementation here
//Correct
return students;
}
@Override
public void setStudents(Student[] students) {
// Add your implementation here
if (students == null) {
throw new IllegalArgumentException();
}
else this.students = students;
}
@Override
public Student getStudent(int index) {
// Add your implementation here
if(index < 0 || index >= students.length) throw new IllegalArgumentException();
else return students[index];
}
@Override
public void setStudent(Student student, int index) {
// Add your implementation here
if(index < 0 || index >= students.length) throw new IllegalArgumentException();
else {
students[index] = student;
}
}
@Override
public void addFirst(Student student) {
// Add your implementation here
//Still to be Reviewed
if (student == null ) throw new IllegalArgumentException();
else {
ArrayList <Student>at = new ArrayList<Student>();
at = (ArrayList<Student>) Arrays.asList(students);
at.add(0, student);
students = null;
students = (Student[]) at.toArray();
/*
Student []st = new Student[students.length+1];
st[0] = student;
for(int i=1;i<st.length;i++) {
st[i] = students[i-1];
}
students = null;
Student []students = new Student[st.length];
for(int i=0;i<st.length;i++) {
students[i] = st[i];
}*/
}
}
@Override
public void addLast(Student student) {
// Add your implementation here
//Still to be Reviewed
if (student == null ) throw new IllegalArgumentException();
else {
ArrayList <Student>at = new ArrayList<Student>();
at = (ArrayList<Student>) Arrays.asList(students);
at.add(students.length, student);
students = null;
students = (Student[]) at.toArray();
}
}
@Override
public void add(Student student, int index) {
// Add your implementation here
}
@Override
public void remove(int index) {
// Add your implementation here
}
@Override
public void remove(Student student) {
// Add your implementation here
}
@Override
public void removeFromIndex(int index) {
// Add your implementation here
}
@Override
public void removeFromElement(Student student) {
// Add your implementation here
}
@Override
public void removeToIndex(int index) {
// Add your implementation here
}
@Override
public void removeToElement(Student student) {
// Add your implementation here
}
@Override
public void bubbleSort() {
// Add your implementation here
Arrays.sort(students);
}
@Override
public Student[] getByBirthDate(Date date) {
// Add your implementation here
if (date == null) throw new IllegalArgumentException();
else {
Student []st = new Student[students.length];
int count =0;
for(int i=0;i<students.length;i++)
if(students[i].getBirthDate().compareTo(date) == 0) {
st[count] = students[i];
count++;
}
Student []ts = new Student[count];
for(int i=0;i<count;i++) {
ts[i] = st[i];
}
return ts;
}
}
@Override
public Student[] getBetweenBirthDates(Date firstDate, Date lastDate) {
// Add your implementation here
return null;
}
@Override
public Student[] getNearBirthDate(Date date, int days) {
// Add your implementation here
return null;
}
@Override
public int getCurrentAgeByDate(int indexOfStudent) {
// Add your implementation here
return 0;
}
@Override
public Student[] getStudentsByAge(int age) {
// Add your implementation here
/*Student st[] = new Student[students.length];
int count=0;
for(int i=0;i<students.length;i++) if(students[i].getBirthDate()getClass().getAge() == age) {
st[count] = students[i];
count++;
}*/
return null;
}
@Override
public Student[] getStudentsWithMaxAvgMark() {
// Add your implementation here
double d = 0;
for(int i=0;i<students.length;i++) {
if(students[i].getAvgMark() > d) {
d = students[i].getAvgMark();
}
}
Student []st = new Student[students.length];
int count=0;
for(int i=0;i<students.length;i++) {
if(d == students[i].getAvgMark()) {st[count] = students[i]; count++;}
}
Student []ts = new Student[count];
for(int i=0;i<count;i++) {
ts[i] = st[i];
}
return ts;
}
@Override
public Student getNextStudent(Student student) {
//Correct
// Add your implementation here
if (student == null) throw new IllegalArgumentException();
else
for(int i=0;i<students.length;i++) {
if(student.getId() == students[i].getId()) return students[i+1];
}
return null;
}
}