Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 145 additions & 0 deletions src/main/java/io/zipcoder/Classroom.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,149 @@
package io.zipcoder;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

public class Classroom {
int maxStudents;

Student[] students;
//ArrayList<Student> students = new ArrayList<>();



public Classroom(int maxNumOfStudents){

this.students = new Student[maxNumOfStudents];
}

public Classroom (Student... students){

this.students = students;
}

public Classroom(){

this.students = new Student[30];
}


/*public Student[] getStudents(){
return this.students;

}*/


public void removeStudent(String firstName, String lastName) {
ArrayList<Student> studentList = new ArrayList<Student>(Arrays.asList(students));

for (int i = 0; i < studentList.size(); i++) {
Student student = studentList.get(i);
if (student == null) {
continue;

} else if(student.getFirstName().equals(firstName) && student.getLastName().equals(lastName)) {
studentList.remove(student);
studentList.add(null);
}
}
this.students = studentList.toArray(new Student[0]);
}


public Student[] getStudents() {
//Arrays.sort(students);
return students;

}


//


public double getAverageExamScore(Student[] student) {
double sum = 0;
for(Student estu : student) {
sum += estu.getAverageExamScore();
}
//Double studentAverage = sum / student.length;
//return studentAverage;
return sum / students.length;
}

public void addStudent (Student student){

for (int i = 0; i < students.length; i++){
if (students[i] == null){
students[i] = student;
break;
}
}
}



public Student[] getStudentByScore() {

ArrayList<Student> studentList = new ArrayList<Student>(Arrays.asList(students));

Comparator<Student> byExamScores = Comparator.comparing(Student::getAverageExamScore);
Comparator<Student> byFullName = Comparator.comparing(Student::getFirstName);

Collections.sort(studentList, byExamScores.reversed().thenComparing(byFullName));

Student[] studentSortByScore = studentList.toArray(new Student[0]);

return studentSortByScore;


}

/*public char getDeviationScore (Student student){
Double averageClassExamScore = this.getAverageExamScore();
Double averageStudentExamScore = student.getAverageExamScore();
Double predevition = Math.pow((averageStudentExamScore - averageClassExamScore, 2);
Double standardDeviation = Math.sqrt(preDeviation/(actualStudentCount() -1));

if(averageStudentExamScore >= (averageClassExamScore + (standardDeviation * 2))){
return 'A';
}else if (averageStudentExamScore >= (averageClassExamScore + standardDeviation)){
return 'B';
}else if (averageStudentExamScore < (averageClassExamScore + standardDeviation) &&
averageStudentExamScore > averageClassExamScore){
return 'C';
}else if (averageStudentExamScore <= (averageClassExamScore + standardDeviation)) {
return 'D';
}else {
return 'F';
}
}

public Map<Student, Character> getGradeBook(){
Student[] studentlist = this.getStudents();
Map<Student, Character> gradeMap = new HasMap<>();
int length = actualStudentCount();
for (int i = 0; i < length; i++) {
gradeMap.put(Studentlist[i], getDeviationScore(studentlist[i]));
}
return gradeMap;
}


}*/
//////////////////////////////////////////////////////////


/*public void addStudent(Student student) {
students.add(student);
}*/
}






102 changes: 102 additions & 0 deletions src/main/java/io/zipcoder/Student.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,106 @@
package io.zipcoder;

import java.util.ArrayList;
import java.util.Arrays;

public class Student {

protected String firstName;
protected String lastName;
private ArrayList<Double> examScores;
Double[] testScores;


public Student(String firstName, String lasName, Double[] testScores) {
this.firstName = firstName;
this.lastName = lasName;
this.examScores = new ArrayList<>(Arrays.asList(testScores));
this.testScores = testScores;
}

public String getFirstName() {

return firstName;
}

public void setFirstName(String firstName) {

this.firstName = firstName;
}

public String getLastName() {

return lastName;
}

public void setLastName(String lastName) {

this.lastName = lastName;
}

public ArrayList<Double> getExamScores() {

return examScores;
}

// public void setExamScores(ArrayList<Double> examScores) {

// this.examScores = examScores;
// }


public Integer getNumberOfExamsTaken() {

return this.testScores.length;

}

public String GetExamScores() {
StringBuilder stringOfScores = new StringBuilder();
for (int i = 0; i < testScores.length; i++) {
stringOfScores.append(testScores[i] + " | ");
stringOfScores = stringOfScores.append(i);
}
return Arrays.toString(testScores);
}

//}
// return Arrays.toString(examScores);
// }

public void addExamScores(double testScore) {

this.examScores.add(testScore);
}

public void setExamScores(int examNumber, double newScore) {

this.examScores.set(examNumber, newScore);
}

public double getAverageExamScore() {
double sum = 0.0;
for (int i = 0; i < testScores.length; i++) {
sum += testScores[i];
}
return sum / testScores.length;
}

@Override
public String toString() {
return "NAME: " + firstName + " " + lastName + '\n' +
"Average Score: " + getAverageExamScore() + '\n' +
"Exam Scores: " + getExamScores();



/*" NAME: " + firstName + lastName + "/n",
" Avrg Exam Score : " + getAverageExamScore() + "/n",
"Exam Score : " + getExamScores();*/


}
}



Loading