diff --git a/src/main/java/io/zipcoder/Classroom.java b/src/main/java/io/zipcoder/Classroom.java index 64566f0..a056799 100644 --- a/src/main/java/io/zipcoder/Classroom.java +++ b/src/main/java/io/zipcoder/Classroom.java @@ -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 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 studentList = new ArrayList(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 studentList = new ArrayList(Arrays.asList(students)); + + Comparator byExamScores = Comparator.comparing(Student::getAverageExamScore); + Comparator 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 getGradeBook(){ + Student[] studentlist = this.getStudents(); + Map 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); + }*/ +} + + + + + + diff --git a/src/main/java/io/zipcoder/Student.java b/src/main/java/io/zipcoder/Student.java index b543e36..ad9b84d 100644 --- a/src/main/java/io/zipcoder/Student.java +++ b/src/main/java/io/zipcoder/Student.java @@ -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 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 getExamScores() { + + return examScores; + } + + // public void setExamScores(ArrayList 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();*/ + + + } } + + + diff --git a/src/test/java/io/zipcoder/ClassroomTest.java b/src/test/java/io/zipcoder/ClassroomTest.java index 7bac1ff..0d28098 100644 --- a/src/test/java/io/zipcoder/ClassroomTest.java +++ b/src/test/java/io/zipcoder/ClassroomTest.java @@ -1,4 +1,204 @@ package io.zipcoder; +import org.junit.Assert; +import org.junit.Test; + +import java.sql.SQLOutput; +import java.util.Arrays; + public class ClassroomTest { + + + @Test + public void ConstructorTestMaxStudents1() { + int givenMaxStudentLength = 50; + Classroom testClassroom = new Classroom(givenMaxStudentLength); + + + Student[] returnedStudentArray = testClassroom.getStudents(); + int returnedArrayLength = returnedStudentArray.length; + + Assert.assertEquals(givenMaxStudentLength, returnedArrayLength); + } + + + @Test + public void ConstructorTestMaxStudents2() { + int givenMaxStudentLength = 50; + Classroom testClassroom = new Classroom(givenMaxStudentLength); + + + Student[] returnedStudentArray = testClassroom.getStudents(); + int returnedArrayLength = returnedStudentArray.length; + + Assert.assertNotEquals(null, returnedArrayLength); + + } + + /////////////////////////////////// + + + @Test + public void getAverageExamScoreTest() { + Double[] studentArr1 = {70.0, 61.0, 87.0, 98.0}; + Double[] studentArr2 = {85.0, 100.0, 88.0, 89.0}; + + Student student1 = new Student("Jimin", "Park", studentArr1); + Student student2 = new Student("Yoongi", "Min", studentArr2); + + + Student[] arrayOfStudents = {student1, student2,}; + Classroom classroom1 = new Classroom(arrayOfStudents); + + Double expectedClassroomExamAvg = (student1.getAverageExamScore() + student2.getAverageExamScore()) / 2; + Double actualClassroomExamAvg = classroom1.getAverageExamScore(arrayOfStudents); + + Assert.assertEquals(expectedClassroomExamAvg, actualClassroomExamAvg); + + + } + + + @Test + public void getStudentsTest() { + Double[] studentArr1 = {85.0, 84.0, 87.0, 98.0}; + Double[] studentArr2 = {85.0, 90.0, 87.0, 88.0}; + Double[] studentArr3 = {99.0, 90.0, 75.0, 52.0}; + Student student1 = new Student("Harry", "Potter", studentArr1); + Student student2 = new Student("SpongeBob", "SquarePants", studentArr2); + Student student3 = new Student("Namjoon", "Kim", studentArr3); + + Student[] arrayOfStudents = {student1, student2, student3}; + Classroom classroom1 = new Classroom(arrayOfStudents); + + Student[] actualStudentsArr = classroom1.getStudents(); + + Assert.assertEquals(arrayOfStudents, actualStudentsArr); + Assert.assertNotEquals(3, actualStudentsArr); + + //System.out.println(actualStudentsArr); + + } + + + @Test + public void getAverageExamScore2Test() { + Double[] studentArr1 = {85.0, 84.0, 87.0, 98.0}; + Double[] studentArr2 = {85.0, 90.0, 87.0, 88.0}; + Double[] studentArr3 = {99.0, 90.0, 75.0, 52.0}; + Student student1 = new Student("Harry", "Potter", studentArr1); + Student student2 = new Student("SpongeBob", "SquarePants", studentArr2); + Student student3 = new Student("Namjoon", "Kim", studentArr3); + + Student[] arrayOfStudents = {student1, student2, student3}; + Classroom classroom1 = new Classroom(arrayOfStudents); + + Double expectedClassroomExamAvg = (student1.getAverageExamScore() + student2.getAverageExamScore() + student3.getAverageExamScore()) / 3; + + Double actualClassroomExamAvg = classroom1.getAverageExamScore(arrayOfStudents); + + Assert.assertEquals(expectedClassroomExamAvg, actualClassroomExamAvg); + System.out.println(expectedClassroomExamAvg); + + } + + + + @Test + public void addStudentTest() { + Double[] scores1 = {85.0, 84.0, 87.0, 98.0}; + Double[] scoresr2 = {85.0, 90.0, 87.0, 88.0}; + Double[] scoresr3 = {99.0, 90.0, 75.0, 52.0}; + Student student1 = new Student("Harry", "Potter", scores1); + Student student2 = new Student("SpongeBob", "SquarePants", scoresr2); + Student student3 = new Student("Namjoon", "Kim", scoresr3); + Student[] expected = {student1, student2, student3, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,}; + + //Classroom classroom101 = new Classroom(30); + Classroom classroom101 = new Classroom(); + classroom101.addStudent(student1); + classroom101.addStudent(student2); + classroom101.addStudent(student3); + + Student[] actual = classroom101.getStudents(); + + Assert.assertEquals(expected, actual); + for (int i = 0; i < actual.length; i++) { + System.out.println(actual[i]); + } + + //Student[] expectedStudentArray = {student1, student2, student3}; + // Student[] returnedStudentArray = classroom101.getStudents(); + //System.out.print(Arrays.toString(expectedStudentArray)); + //System.out.print(Arrays.toString(returnedStudentArray)); + + //Assert.assertNotEquals(null, returnedStudentArray); + } + + + @Test + public void removeStudentTest() { + Double[] scores1 = {80.0, 80.0, 100.0, 70.0}; + Double[] scores2 = {79.0, 80.0, 95.0, 85.0}; + Double[] scores3 = {100.0, 80.0, 92.0, 90.0}; + Student student1 = new Student("Harry", "Potter", scores1); + Student student2 = new Student("SpongeBob", "SquarePants", scores2); + Student student3 = new Student("Namjoon", "Kim", scores3); + Student[] expected = {student2, student3, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null}; + + Classroom classroom101 = new Classroom(); + classroom101.addStudent(student1); + classroom101.addStudent(student2); + classroom101.addStudent(student3); + classroom101.removeStudent("Harry", "Potter"); + Student[] actual = classroom101.getStudents(); + + Assert.assertEquals(expected, actual); + for (int i = 0; i < actual.length; i++) { + System.out.println(actual[i]); + } + } + //System.out.println(expected); + // System.out.println(actual); + + + @Test + public void getStudentByScore(){ + Double[] scores1 = {80.0, 80.0, 90.0}; + Double[] scores2 = {100.0, 100.0, 95.0}; + Double[] scores3 = {80.0, 80.0, 98.0}; + Student student1 = new Student("Harry", "Potter", scores1); + Student student2 = new Student("SpongeBob", "SquarePants", scores2); + Student student3 = new Student("Namjoon", "Kim", scores3); + Student[] expected = {student2, student3, student1}; + + //WHEN + Classroom clasroom101 = new Classroom(student1, student2, student3); + Student[] actual = clasroom101.getStudentByScore(); + + //THEN + Assert.assertEquals(expected, actual); + + for (int i = 0; i < actual.length; i++) { + System.out.println(actual[i]); + + } + } + + + + + } + + + + + + + + + + + + diff --git a/src/test/java/io/zipcoder/StudentTest.java b/src/test/java/io/zipcoder/StudentTest.java index a9fedec..f5ff037 100644 --- a/src/test/java/io/zipcoder/StudentTest.java +++ b/src/test/java/io/zipcoder/StudentTest.java @@ -1,5 +1,89 @@ package io.zipcoder; +import org.junit.Assert; +import org.junit.Test; + public class StudentTest { + @Test + public void studentConstructor(){ + //Given + String firstName = "Leon"; + String lastName = "Hunter"; + Double[] examScores = { 100.0, 95.0, 123.0, 96.0 }; + Student student = new Student(firstName, lastName, examScores); + + //WHEN + String expectedName = student.getFirstName(); + + //THEN + Assert.assertEquals(expectedName, firstName); + } + + @Test + public void getStudentNameTest (){ + //GIVEN + String firstName = "Leon"; + String lastName = "Hunter"; + Double[] examScores = { 100.0, 95.0, 123.0, 96.0 }; + Student student = new Student(firstName, lastName, examScores); + + //WHEN + String nom = student.getFirstName(); + String expected = "Leon"; + + //THEN + Assert.assertEquals(expected, nom); + //System.out.println(nom); + } + + @Test + public void StudenLatNameTest (){ + //GIVEN + String firstName = "Leon"; + String lastName = "Hunter"; + Double[] examScores = { 100.0, 95.0, 123.0, 96.0 }; + Student student = new Student(firstName, lastName, examScores); + + //WHEN + String actualLasName = student.getLastName(); + + //WHEN + Assert.assertEquals(actualLasName, lastName); + } + + @Test + public void getAverageExamScoreTest (){ + //GIVEN + String firstName = "Leon"; + String lastName = "Hunter"; + Double[] examScores = { 98.0, 78.0, 80.0, 80.0 }; + Student student = new Student(firstName, lastName, examScores); + + //WHEN + double expected = 84; + double actua = student.getAverageExamScore(); + + //THEN + Assert.assertEquals(expected, actua, 0.001); + } + + + @Test + public void getnumberOfExamsTakenTest (){ + //GIVEN + String firstName = "Leon"; + String lastName = "Hunter"; + Double[] examScores = { 100.0, 95.0, 123.0, 96.0 }; + Student student = new Student(firstName, lastName, examScores); + + //WHEN + int expected = 4; + int actual = student.getNumberOfExamsTaken(); + + //THEN + Assert.assertEquals(expected, actual); +} + + } \ No newline at end of file diff --git a/target/classes/io/zipcoder/Classroom.class b/target/classes/io/zipcoder/Classroom.class new file mode 100644 index 0000000..b5aa1da Binary files /dev/null and b/target/classes/io/zipcoder/Classroom.class differ diff --git a/target/classes/io/zipcoder/Student.class b/target/classes/io/zipcoder/Student.class new file mode 100644 index 0000000..65b83a5 Binary files /dev/null and b/target/classes/io/zipcoder/Student.class differ diff --git a/target/test-classes/io/zipcoder/ClassroomTest.class b/target/test-classes/io/zipcoder/ClassroomTest.class new file mode 100644 index 0000000..e87b3ff Binary files /dev/null and b/target/test-classes/io/zipcoder/ClassroomTest.class differ diff --git a/target/test-classes/io/zipcoder/StudentTest.class b/target/test-classes/io/zipcoder/StudentTest.class new file mode 100644 index 0000000..2591e8f Binary files /dev/null and b/target/test-classes/io/zipcoder/StudentTest.class differ