-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathClassroom.java
More file actions
85 lines (79 loc) · 2.88 KB
/
Classroom.java
File metadata and controls
85 lines (79 loc) · 2.88 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
80
81
82
83
84
85
package io.zipcoder;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.TreeMap;
public class Classroom {
Student[] students;
int maxNumberOfStudents;
public Classroom(int maxNumberOfStudent){
maxNumberOfStudents = maxNumberOfStudent;
}
public Classroom(Student[] allStudents){
this.students = allStudents;
}
public Classroom(){
this.students = new Student[30];
}
public Student[] getStudents() {
return students;
}
public Double getAverageExamScore(){
Double examSum = 0.0;
for(int i = 0; i < students.length; i++){
examSum += students[i].getAverageExamScore();
}
return examSum/students.length;
}
public void addStudent(Student student){
students = new Student[maxNumberOfStudents];
for (int i = 0; i < this.students.length; i++){
if(this.students[i] == null){
students[i] = student;
break;
}
}
}
public void removeStudent(String firstName, String lastName) {
for (int i = 0; i < students.length; i++) {
if ((students[i].firstName + students[i].lastName).equals(firstName + lastName)) {
System.arraycopy(students, i + 1, students, i, students.length - 1 - i);
}
students[students.length - 1] = null;
break;
}
}
public Student[] getStudentsByScore () {
Student[] scoreArr = new Student[students.length];
for (int i=0 ; i <students.length-1; i ++) {
for (int j = i + 1; j < students.length; j++) {
if (students[i].getAverageExamScore().compareTo(students[j].getAverageExamScore()) < 0) {
Student temp = students[i];
students[i] = students[j];
students[j] = temp;
}
}
}
return scoreArr;
}
public Map getGradeBook() {
Map<String, String> gradeBook = new TreeMap<String, String>();
for (int i = 0; i < students.length; i++) {
if (students[i].getAverageExamScore() >= 90) {
gradeBook.put(students[i].getFirstName(), "A");
} else if (students[i].getAverageExamScore() >= 80) {
gradeBook.put(students[i].getFirstName(), "B");
} else if (students[i].getAverageExamScore() >= 70) {
gradeBook.put(students[i].getFirstName(), "C");
} else if (students[i].getAverageExamScore() >= 60) {
gradeBook.put(students[i].getFirstName(), "D");
} else {
gradeBook.put(students[i].getFirstName(), "F");
}
}
for (Map.Entry g : gradeBook.entrySet()) {
System.out.println(g);
}
return gradeBook;
}
}