From 54a938be1f318b285750d464e5d1f6e3a4467849 Mon Sep 17 00:00:00 2001 From: Rex Date: Tue, 3 Aug 2021 04:26:42 -0400 Subject: [PATCH] go back to gradebook/tests --- src/main/java/io/zipcoder/Classroom.java | 64 +++++++++++++ src/main/java/io/zipcoder/Student.java | 70 ++++++++++++++ src/test/java/io/zipcoder/ClassroomTest.java | 37 ++++++++ src/test/java/io/zipcoder/StudentTest.java | 88 ++++++++++++++++++ target/classes/io/zipcoder/Classroom.class | Bin 0 -> 3171 bytes target/classes/io/zipcoder/Student.class | Bin 0 -> 2932 bytes .../io/zipcoder/ClassroomTest.class | Bin 0 -> 1880 bytes .../io/zipcoder/StudentTest.class | Bin 0 -> 2731 bytes 8 files changed, 259 insertions(+) create mode 100644 target/classes/io/zipcoder/Classroom.class create mode 100644 target/classes/io/zipcoder/Student.class create mode 100644 target/test-classes/io/zipcoder/ClassroomTest.class create mode 100644 target/test-classes/io/zipcoder/StudentTest.class diff --git a/src/main/java/io/zipcoder/Classroom.java b/src/main/java/io/zipcoder/Classroom.java index 64566f0..2ca90bd 100644 --- a/src/main/java/io/zipcoder/Classroom.java +++ b/src/main/java/io/zipcoder/Classroom.java @@ -1,4 +1,68 @@ package io.zipcoder; +import java.util.*; + public class Classroom { + + Student[] students; + int studentLimit; + + public Classroom(int studentLimit){ + students = new Student[studentLimit]; + } + + public Classroom(Student[] student){ + this.students = student; + } + + public Classroom() { + this.students = new Student[30]; + } + + public Student[] getStudents(){ + return students; + } + + public double getAverageExamScore() { + double sum = 0.0; + for (Student student : students) { + sum += student.getAverageExamScore(); + } + return sum / students.length; + } + + public void addStudent(Student student) { + for (int i = 0; i < students.length; i++) { + if (students[i] == null) { + students[i] = student; + } + } + } + + public Student[] removeStudent(String firstName, String lastName) { + List studentList = new ArrayList<>(Arrays.asList(students)); + for (Student student : students) { //each student in students array + if (student.getFirstName().equals(firstName) && student.getLastName().equals(lastName)) { + studentList.remove(student); //if names match then remove student + } + return studentList.toArray(new Student[studentList.size()]); + } + return new Student[studentLimit]; + } + + public Student[] getStudentsByScore() { + List studentList = new ArrayList(Arrays.asList(students)); + + Comparator examScore = Comparator.comparing(Student::getAverageExamScore); + Comparator studentName = Comparator.comparing(Student::getFullName); + return null; + } + + + +// public getGradeBook() { +// +// } } + + diff --git a/src/main/java/io/zipcoder/Student.java b/src/main/java/io/zipcoder/Student.java index b543e36..2bc255c 100644 --- a/src/main/java/io/zipcoder/Student.java +++ b/src/main/java/io/zipcoder/Student.java @@ -1,4 +1,74 @@ package io.zipcoder; +import java.util.ArrayList; +import java.util.Arrays; + public class Student { + String firstName; + String lastName; + Double[] testScores; + ArrayList examScores; + + public Student(String firstName,String lastName, Double[] testScores){ + this.firstName = firstName; + this.lastName = lastName; + this.testScores = testScores; + this.examScores = new ArrayList<>(Arrays.asList(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 int getNumberOfExamsTaken() { + return examScores.size(); + } + + public String getFullName() {return firstName + " " + lastName;} + + public String getExamScores() { + String score = "Exam Scores: \n"; + + for(int i =0; i < examScores.size(); i++) { + score += "\tExam " + (i + 1) + " -> "; + score += examScores.get(i) + "\n"; + } + return score; + } + + public void addExamScore(double examScore) { + this.examScores.add(examScore); + } + + public void setExamScore(int examNumber, double newScore){ + examScores.set(examNumber, newScore); + } + + public double getAverageExamScore() { + double average = 0.0; + for (int i = 0; i < examScores.size(); i++) { + average += examScores.get(i); + + } return average / examScores.size(); + } + + @Override + public String toString(){ + String nameScore = "Student Name: " + firstName + " " + lastName + "\n"; + nameScore = nameScore + "> Average Score: " + this.getAverageExamScore() + "\n"; + nameScore = nameScore + "> " + this.getExamScores(); + return nameScore; + } } diff --git a/src/test/java/io/zipcoder/ClassroomTest.java b/src/test/java/io/zipcoder/ClassroomTest.java index 7bac1ff..dbaa946 100644 --- a/src/test/java/io/zipcoder/ClassroomTest.java +++ b/src/test/java/io/zipcoder/ClassroomTest.java @@ -1,4 +1,41 @@ package io.zipcoder; +import org.junit.Assert; +import org.junit.Test; + public class ClassroomTest { + Double[] testScores = {70.0, 80.0, 90.0}; + @Test + public void TestGetStudents() { + Student student = new Student("Rex","Casio", testScores); + Classroom classroom = new Classroom(); + classroom.addStudent(student); + + Student actual = classroom.getStudents()[0]; + + Assert.assertEquals(student,actual); + } + + @Test + public void TestRemoveStudents() { + Student student1 = new Student("Rex","Casio", testScores); + Student student2 = new Student("Rox","Casio", testScores); + Student student3 = new Student("Rosie","Casio", testScores); + Student student4 = new Student("Russell","Casio", testScores); + Classroom classroom = new Classroom(); + + classroom.addStudent(student1); + classroom.addStudent(student2); + classroom.addStudent(student3); + classroom.addStudent(student4); + classroom.removeStudent("Rox", "Casio"); + Student [] expected = {student2, student3, student4, 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}; + + Student [] actual = classroom.getStudents(); + + + Assert.assertArrayEquals(expected, actual); + } } diff --git a/src/test/java/io/zipcoder/StudentTest.java b/src/test/java/io/zipcoder/StudentTest.java index a9fedec..1087d9a 100644 --- a/src/test/java/io/zipcoder/StudentTest.java +++ b/src/test/java/io/zipcoder/StudentTest.java @@ -1,5 +1,93 @@ package io.zipcoder; +import org.junit.Assert; +import org.junit.Test; + public class StudentTest { + @Test + public void testGetFirstName() { + String firstName = "Rex"; + String lastName = "Casio"; + Double[] testScores = {70.0, 80.0, 90.0}; + + Student student = new Student(firstName,lastName,testScores); + //student.setFirstName(); + String actual = student.getFirstName(); + + Assert.assertEquals(firstName, actual); + } + + @Test + public void testGetLastName() { + String firstName = "Rex"; + String lastName = "Casio"; + Double[] examScores = {70.0, 80.0, 90.0}; + + Student student = new Student(firstName,lastName,examScores); + String actual = student.getLastName(); + + Assert.assertEquals(firstName, actual); + } + + @Test + public void testGetFullName() { + String firstName = "Rex"; + String lastName = "Casio"; + Double[] examScores = {70.0, 80.0, 90.0}; + + Student student = new Student(firstName,lastName,examScores); + String expected = "Rex Casio"; + String actual = student.getFirstName() + " " +student.getLastName(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void TestGetExamsScores() { + String firstName = "Rex"; + String lastName = "Casio"; + Double[] examScores = {70.0, 80.0, 90.0}; + + Student student = new Student(firstName,lastName,examScores); + String expected = "Exam Scores: \n" + + "\tExam 1 -> 70.0\n" + + "\tExam 2 -> 80.0\n" + + "\tExam 3 -> 90.0\n"; + String actual = student.getExamScores(); + + Assert.assertEquals(expected, actual); + } + + @Test + public void TestGetAverageExamScore() { + String firstName = "Rex"; + String lastName = "Casio"; + Double[] examScores = {70.0, 80.0, 90.0}; + + Student student = new Student(firstName, lastName, examScores); + Double expected = 80.0; + Double actual = student.getAverageExamScore(); + + Assert.assertEquals(expected, actual); + + } + + @Test + public void TestStringOverride() { + String firstName = "Rex"; + String lastName = "Casio"; + Double[] examScores = {70.0, 80.0, 90.0}; + + Student student = new Student(firstName, lastName, examScores); + String expected = "Student Name: Rex Casio\n" + + "> Average Score: 80.0\n" + + "> Exam Scores: \n" + + "\tExam 1 -> 70.0\n" + + "\tExam 2 -> 80.0\n" + + "\tExam 3 -> 90.0\n"; + String actual = student.toString(); + + 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 0000000000000000000000000000000000000000..a20344029ba496cf840871a0bb9131fb55150097 GIT binary patch literal 3171 zcma)8Yf~Fl7=BJ}3t60;L2fjnbC3KaA+k z-{3fY=@&m*XS6p*#&6Cz{tQ3(6C9@_K4*7H7D=5BaQ2+D@B6&Z`#$eE%WwZYSp{$q zUqsQ4Qwk;SMDFjKdUQpU{cR%+gTF(#mTHff_^*aBikATn+g z4SPZ$l$_~5&&MQv1X|KYQJJwvgveTiVQM`SY4($hEf_vacHq*s&qrWL_(m zEz>M8Vj@|eiwvcBYy^Tyxo*now#Sv2oyq?Ct^!+Wcyd{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Y=aGWb{XfJcKeQr=y`nXmunU9ErptvG6@iBto&s@Tihd9-v|H z0UEzTr<_OkIdgR=p*%)Y02hXa9zzviH$29c0DeL9ed4unEmaLUwch4bagYtS4}&bu zBoj!J)>T$k*83od4sw+Bmb&JuY31-TZDgb5aDcM_F)q^b5K|f9u52)O=P-AqDhCi; zBd9`E6dZAWk9z7n#eM~&YhaK1-_l87tlF915GcgGo{d#XKjB%yBfK#CgaC3fCuD}M zXtM1=MlCo(X^t|JQ75wj7s|`0g@Q`%{3nv~j^h~f+0DNR&fI)t=ebsgt5(OWR>%1^ mh!czyz)9TUGfJzE@EJblL7nGXUJmDI^A^tIf;YQ@xBmq$)zzW^ literal 0 HcmV?d00001 diff --git a/target/classes/io/zipcoder/Student.class b/target/classes/io/zipcoder/Student.class new file mode 100644 index 0000000000000000000000000000000000000000..dfe09f9e5fb734e996fad67f38ecd470ec67e81c GIT binary patch literal 2932 zcmZ`)Yg1EK6kRtrAt7FZ22oM8p;ZY1M6I?8N__xAji3$1s(pA#E_gL0G!K0AVIQ{k zTmM66I{ng_wlfkPo$2&*|3&{sXKcInxhF43CzEr}*=O&y*M8mm=RePX2XGAEh4Ct` zw4)F2$dZy}K8Sb2SisdV0(eg(*JO7+h#O&qaYdH*L-;_RABONz2sdSGhp;GmX*py< zaKh-pl1P?ixfO&flG`EN2_YLM?22gSLdeTuHHeRcC>Us8atp=Mti9qGh$e5_YxYRi z&Ml9mN(DE!JZ2!2wX65xl2a_D()of@G|+XUL3<)!Ud%ew4mf7E4rWPr1uEyHqaF=Rhl+Q=6g3Y1ekj&AFv<1EcW<1)erfFMXa>^MeC!tu&PHC#1 z!R>J!Pje2fVv|;P3;M!r3&E1LY;U1a{nX7nkL}#jBy(Jxx9>PP17>_+#W{Z%=*)^wNFFOrZWK5`_?Oo8Il=n(Ve>wJ{HV&uqLAo}S{^=@;o1yQ!JhPz^M&q5pn7Vcxzz|M`0ey;3hSy>AY z@Cjp$S-6B_1|q^c=H+oT7G?{!D~afR$~47>$Eo@mJ{Q458ip-=fiEq5g|96S{^=p%D#ffZI(o8ovYv$iDly$V=nw>2>b4!9a(df4J zPBS?ha@)YTihG>{$eA$EAD?M)y;;Oj&8TY-x{n_Wz|TM1ohzi{ z)ss!Ho@{CuNO14NAS~{OFwFH3B@bz-Y!gpmBnH>vOAM{UOboBXpLl`5wc%%Idy3#X zLcb}15w5$@#?_)>2ig(guM=I^N+R2Em^TSc=LnASB*cW8p>{&fr*=Zmr1W)u_B=8p ze2P{e@dUnKx$!~VwJG6t1ug8U01w*0alAo^L^4io0d7-K)X9dGbQf)U6v7TqOCt!n zN6x^TEs2;LiS)K4a-ua6b0d)$iS+#s5y_2Y;3P(MP)F4n2r(m}3fg~WfQ?Dn-@qkQ zOUhU+kZEd5!uGvD_}Wu!k;GPDMLW1~Z}L$=WMhQ=4XFESsC>0(R?k^Clc)>P&ZK#| zS9ALT7qpi_aj}(4um5HR+oDm=O|s!yY!5AusEBiU{PMxWe4E3G)O8=VUDe zaDb|#62UZsk&;C)Lv$%0U-26KdyRf1GHs6Ut>t}pzijt1oqwRGg5BxqMO-nj1sX{$NDF^B${3f&6M_T*{ zYH~l)Mh4K)WsdG)T}f=x9 aT|k2C$M~4t+P_ufx=6LJF<^KS_KS{y> literal 0 HcmV?d00001 diff --git a/target/test-classes/io/zipcoder/ClassroomTest.class b/target/test-classes/io/zipcoder/ClassroomTest.class new file mode 100644 index 0000000000000000000000000000000000000000..b8b6f8bea37191a1f03ca946c4a493bc0500747e GIT binary patch literal 1880 zcmZ`(-BR0T5Ivu5{U8Ju#()JOr7aD%fw&>0KZd5bkffys5}P{XNpFO$QZcrb$}*Go zDp!4<&a}WZlRiLh^9p^0UU#}H|2O7BN4u-<+daEyM{oZ9^Dh9Kc&cF@_Y{00?>u=) z5kNx-pUOMOfdhG`^fIu>#J&D;2vc_Bix_ zLk|@^Qt-8a=G#rbSaChODKPyke`cLqnVQu&&Fs0YlbXFHAa6Sj$GK2u3JB* z;#48Z??<*@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