-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathClassroom.java
More file actions
141 lines (113 loc) · 4.57 KB
/
Classroom.java
File metadata and controls
141 lines (113 loc) · 4.57 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
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
import io.zipcoder.Student;
//import com.google.common.collect;
import java.util.*;
public class Classroom {
//instance variables
private ArrayList<Student> students;
private Integer maxNumberOfStudents;
private static Map<Double, String> limits;
//Nullary Constructor
public Classroom() {
students = new ArrayList<Student>(30);
this.students = students;
}
//Constructor with int maxNumberOfStudents
public Classroom(Integer maxNumberOfStudents) {
this.maxNumberOfStudents = maxNumberOfStudents;
students = new ArrayList<>(maxNumberOfStudents);
}
//Constructor with the students <list> representative of the collection of student objects this classroom will store.
public Classroom(ArrayList<Student> students) {
this.students = students;
}
//Getters
public ArrayList<Student> getStudents() {
return students;
}
public Integer getMaxNumOfStudents() {
return maxNumberOfStudents;
}
public Double getAverageExamScore() {
Double totalExamScores = 0.0;
int numOfStudents = students.size();
for (int i = 0; i < students.size(); i++) {
totalExamScores += students.get(i).getAverageExamScore();
}
return totalExamScores / numOfStudents;
}
public void addStudent (Student studentToAdd){
//StringBuilder sb = new StringBuilder();
students.add(studentToAdd);
// sb.append("\n========================================\n");
// sb.append(studentToAdd.printToString());
// sb.append("========================================");
//return sb.toString();
}
public void removeStudent (String firstName, String lastName){
for (int i = 0; i < students.size(); i++) {
if(students.get(i).getFirstName().equals(firstName) && students.get(i).getLastName().equals(lastName)){
students.remove(i);
}
}
}
public ArrayList <Student> getStudentsByScore () {
Collections.sort(students);
return students;
}
//Tried creating some maps and things to sort the student data. Ended up using a custom comparator to sor the student list
// for (int i = 0; i < students.size(); i++) {
// students.get(i).getAverageExamScore();
// students.sort(Comparator.naturalOrder());
// HashMap<Student, Double> studentDoubleHashMap = new HashMap<>();
// for (int i = 0; i < students.size(); i++) {
// studentDoubleHashMap.put(students.get(i), students.get(i).getAverageExamScore());
// }
public Map getGradeBook (){
//Integer numOfStudentsInClass = students.size();
String letterGrade = "I";
//orders students by score
getStudentsByScore();
//Limits for the tree map
// static {
// limits = new TreeMap<>();
// limits.put(0.0 , "F");
// limits.put(students.size()*0.11 , "D");
// limits.put(students.size()*0.31, "C");
// limits.put(students.size()*0.51, "B");
// limits.put(students.size()*0.71, "B");
// limits.put(students.size()* 0.9, "A");
TreeMap<Student, String> gradeMap = new TreeMap<>();
// gradeMap.put(90.0, "A");
// gradeMap.put(71.0, "B");
// gradeMap.put(51.0, "C");
// gradeMap.put(11.0, "D");
// gradeMap.put( 0.0, "F");
for (int i = 0; i < students.size(); i++ ){
if ( students.get(i).getAverageExamScore() >= 90){
letterGrade = " A";}
else if (students.get(i).getAverageExamScore() <= 90 && students.get(i).getAverageExamScore() >= 71){
letterGrade = " B";}
else if (students.get(i).getAverageExamScore() <= 70 && students.get(i).getAverageExamScore() >= 50){
letterGrade= " C";}
else if (students.get(i).getAverageExamScore() <= 90 && students.get(i).getAverageExamScore() >= 71){
letterGrade = " D";}
else {
letterGrade = " F";}
gradeMap.put(students.get(i), letterGrade);
}
return gradeMap;
}
}
//
//+ " " + letterGrade
// students.get(i).getFirstName() + " " + students.get(i).getLastName());
// RangeMap<Integer, String> gradeLetter = ImmutableRangeMap.builder()
// .put(Range.closed(90, 100), "A")
// .put(Range.closed(60, 89), "B")
// // ...
// .build();
//
// public String getGrade(String studentName) {
// int averageScore = getAverageExamGrade(studentName);
// return gradeLetter.get(averageScore);
// }