-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathClassroom.java
More file actions
67 lines (59 loc) · 2.41 KB
/
Classroom.java
File metadata and controls
67 lines (59 loc) · 2.41 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
package io.zipcoder;
import java.lang.reflect.Array;
import java.util.*;
public class Classroom extends Student{
Student[] students;
public Classroom(int maxNumberOfStudents){this.students = new Student[maxNumberOfStudents];}
public Classroom(Student[] students){this.students = students;}
public Classroom(){ this.students = new Student[30]; }
public Student[] getStudents() {
return students;
}
public Double getAverageExamScore() {
double total = 0;
for (int i = 0; i < students.length; i++) {
total += students[i].getAverageExamScore();
}
return total / students.length;
}
public Student[] addStudent(Student student){
List<Student> studentList = Arrays.asList(students);
studentList.add(student);
return (Student[]) studentList.toArray();
}
public Student[] removeStudent(String firstName, String lastName){
List<Student> studentList = Arrays.asList(students);
for(int i =0; i < students.length; i++){
if(students[i].getFirstName().equals(firstName) && students[i].getLastName().equals(lastName)) {
studentList.remove(i);
}
}
return (Student[])studentList.toArray();
}
public Student[] getStudentByScore(){
StudentSorter itemSorter = new StudentSorter(students);
Comparator<Student> comparator = new ScoreComparator();
return itemSorter.sort(comparator);
}
//******Correct this to meet requirements ******
public Map getGradeBook(){
Map<Character, Student> gradeBook= new HashMap<>();
Student[] sortedStudents =getStudentByScore();
for(int i =0; i < sortedStudents.length; i++){
if(sortedStudents[i].getAverageExamScore() <=50){
gradeBook.put('F',sortedStudents[i]);
}else if(sortedStudents[i].getAverageExamScore() <=60) {
gradeBook.put('E', sortedStudents[i]);
}else if(sortedStudents[i].getAverageExamScore() <=65) {
gradeBook.put('D', sortedStudents[i]);
}else if(sortedStudents[i].getAverageExamScore() <=70) {
gradeBook.put('C', sortedStudents[i]);
}else if(sortedStudents[i].getAverageExamScore() <=90) {
gradeBook.put('B', sortedStudents[i]);
} else {
gradeBook.put('A', sortedStudents[i]);
}
}
return gradeBook;
}
}