-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathClassroom.java
More file actions
79 lines (54 loc) · 1.82 KB
/
Classroom.java
File metadata and controls
79 lines (54 loc) · 1.82 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
70
71
72
73
74
75
76
77
78
79
package io.zipcoder;
import java.util.*;
public class Classroom {
private Student[] students;
//Constructors
public Classroom(int maxNumberOfStudents) {
students = new Student[maxNumberOfStudents];
}
public Classroom(Student[] students) {
this.students = students;
}
public Classroom() {
this(30);
}
public Student[] getStudents() {
return students;
}
public Double getAverageExamScore() {
double classTotalScore = 0;
double numberOfStudents = students.length;
for (int i = 0; i < students.length; i++)
classTotalScore += students[i].getAverageExamScore();
return (classTotalScore / numberOfStudents);
}
public String addStudent(Student student) {
for (int index = 0; index < students.length; index++) {
if (students[index] == null) {
students[index] = student;
return student.toString();
}
}
return "Classroom is full";
}
public boolean removeStudent(String firstName, String lasName) {
for (int index = 0; index < students.length; index++) {
Student student = students[index];
if (student.getFirstName().contains(firstName) &&
student.getLastName().contains(lasName)) {
students[index] = null;
return true;
}
}
return false;
}
public List getStudentByScore(double score) {
List<Student> studentScore = new ArrayList<>();
for (Student student : getStudents()) {
if (student.getExamScores().contains(String.valueOf(score)))
studentScore.add(student);
}
Collections.sort(studentScore, new NameComparator());
return studentScore;
}
}