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
96 changes: 95 additions & 1 deletion src/main/java/io/zipcoder/Classroom.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,98 @@
package io.zipcoder;

import javax.sound.midi.Soundbank;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

public class Classroom {
}
public Student[] students;
private Integer maxNumberOfStudents;

public Classroom(Integer maxNumberOfStudents) {
this.students = new Student[maxNumberOfStudents];
this.maxNumberOfStudents = maxNumberOfStudents;

}

public Classroom(Student[]students) {
this.students = students;

}

public Classroom() {
this.students = new Student[30];

}

public Student[] getStudents() {
List<Student> studentList = new ArrayList<>();
for (Student student: students) {
if (student != null)
studentList.add(student);
}
return studentList.toArray(new Student[studentList.size()]);

}

public double getAverageExamScores() {
double avgScore = 0;
double summ = 0;
for (int i = 0; i < students.length; i++) {
summ += students[i].getAverageExamScore();
avgScore = summ / students.length;

}
return avgScore;
}

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

public int getNumberOfStudents () {
int count = 0;
for (int i = 0; i < students.length; i++) {
if (students[i] != null && students[i].getFirstName().length() > 0) {
count++;

}
}
return count;
}

public void removeStudent(String firstName, String lastName) {


List<Student> studentList = new ArrayList<>();
for (int i = 0; i < students.length; i++) {
studentList.add(students[i]);
}
for (Student i : getStudents()) {
if (i.getFirstName().equals(firstName) && (i.getLastName().equals(lastName))) {
studentList.remove(i);
}
}
students = studentList.toArray(new Student[0]);
}





public String getGradeBook(){

return null;
}
}






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

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

public class Student {

private String firstName;
private String lastName;
ArrayList<Double>examScores;

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

}

public String getFirstName() {
return this.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> getTestScores() {
return examScores;
}

public int getNumberOfTestsTaken() {
return examScores.size();
}

public String getExamScores() {
String scoreReport = "";
for (int i = 0; i < examScores.size(); i++) {
scoreReport += "Exam " + i + 1 + " --> " + examScores.get(i) + "\n";
}
return scoreReport;
}

public void addExamScore(double examScore) {
examScores.add(examScore);
}

public Double getAverageExamScore() {
double sum = 0;
double avgReport = 0;
for (int i = 0; i < examScores.size(); i++) {
sum += examScores.get(i);
avgReport = sum/examScores.size();
}
return avgReport;
}

@Override
public String toString(){
return "'''\n" + "Student Name: " + firstName + " " + lastName + "\n" + getExamScores()+ "\n" + getAverageExamScore()+"\n'''";
}



/* @Override
public String toString() {
return "Student{" +
"firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", testScores=" + examScores +
'}';
}*/
}

55 changes: 55 additions & 0 deletions src/test/java/io/zipcoder/ClassroomTest.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,59 @@
package io.zipcoder;

import org.junit.Assert;
import org.junit.Test;

public class ClassroomTest {
@Test
public void getStudents() {
Double[] s1Scores = {100.0, 150.0};
Double[] s2Scores = {225.0, 25.0};

Student s1 = new Student("student", "one", s1Scores);
Student s2 = new Student("student", "two", s2Scores);

Student[] students = new Student[]{s1, s2};
Classroom classroom = new Classroom(students);
}

@Test
public void getAverageExamScores() {
Double[] s1Scores = {100.0, 150.0};
Double[] s2Scores = {225.0, 25.0};

Student s1 = new Student("student", "one", s1Scores);
Student s2 = new Student("student", "two", s2Scores);

Student[] students = new Student[]{s1, s2};
Classroom classroom = new Classroom(students);
}

@Test
public void addStudentTest() {
int maxNumberOfStudents = 1;
Classroom classroom = new Classroom(maxNumberOfStudents);
Double[] examScores = {100.0, 150.0, 250.0, 0.0};
Student student = new Student("Leon", "Hunter", examScores);
classroom.addStudent(student);
int postEnrollment = classroom.getNumberOfStudents();

Assert.assertEquals(1, postEnrollment);


}

@Test
public void removeStudentTest() {
int maxNumberOfStudents = 1;
Classroom classroom = new Classroom(maxNumberOfStudents);
Double[] examScores = {100.0, 150.0, 250.0, 0.0};
Student student = new Student("Leon", "Hunter", examScores);
classroom.addStudent(student);
int expected = classroom.getNumberOfStudents();
classroom.removeStudent("Leon","Hunter");
int actual = classroom.getNumberOfStudents();

Assert.assertEquals(expected-1,actual);
}
}

105 changes: 105 additions & 0 deletions src/test/java/io/zipcoder/StudentTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,110 @@
package io.zipcoder;

import org.junit.Assert;
import org.junit.Test;

import java.util.ArrayList;

public class StudentTest {

@Test
public void getFirstName() {
Double[] examScores = { 100.0, 150.0, 250.0, 0.0 };
Student student = new Student("Jim", "Bo", examScores);

String actual = student.getFirstName();
String expected = "Jim";
Assert.assertEquals(expected, actual);
}

@Test
public void setFirstName() {
Double[] examScores = { 100.0, 150.0, 250.0, 0.0 };
Student student = new Student("Jim", "Bo", examScores);
student.setFirstName("Gum");
String actual = student.getFirstName();
String expected = "Gum";
Assert.assertEquals(expected, actual);
}

@Test
public void getLastName() {
Double[] examScores = { 100.0, 150.0, 250.0, 0.0 };
Student student = new Student("Jim", "Bo", examScores);

String actual = student.getLastName();
String expected = "Bo";
Assert.assertEquals(expected, actual);
}

@Test
public void setLastName() {
Double[] examScores = { 100.0, 150.0, 250.0, 0.0 };
Student student = new Student("Jim", "Bo", examScores);
student.setLastName("Bobo");
String actual = student.getLastName();
String expected = "Bobo";
Assert.assertEquals(expected, actual);
}

@Test
public void getTestScores() {
Double[] examScores = { 100.0, 150.0, 250.0, 0.0 };
Student student = new Student("Jim", "Bo", examScores);
ArrayList actual = student.getTestScores();
Double expected = 150.0;
Assert.assertEquals(actual.get(1),expected);
}

@Test
public void getNumberOfTestsTaken() {
Double[] examScores = { 100.0, 150.0, 250.0, 0.0 };
Student student = new Student("Jim", "Bo", examScores);
int actual = student.getNumberOfTestsTaken();
int expected = 4;
Assert.assertEquals(expected, actual);
}

@Test
public void getExamScores() {
Double[] examScores = { 100.0, 150.0, 250.0, 0.0 };
Student student = new Student("Jim", "Bo", examScores);
String actual = student.getExamScores();
}

@Test
public void addExamScore() {
Double[] examScores = { 100.0, 150.0, 250.0, 0.0 };
Student student = new Student("Jim", "Bo", examScores);
int actual = student.getNumberOfTestsTaken()+1;
student.addExamScore(100.0);
int expected = student.getNumberOfTestsTaken();
Assert.assertEquals(expected, actual);
}

@Test
public void getAverageExamScore() {
Double[] examScores = { 100.0, 150.0, 250.0, 0.0 };
Student student = new Student("Jim", "Bo", examScores);
Double actual = student.getAverageExamScore();
Double expected = 125.0;
Assert.assertEquals(expected,actual);
}

@Test
public void toStingTest() {
Double[] examScores = {100.0, 150.0, 250.0, 0.0};
Student student = new Student("Jim", "Bo", examScores);
String actual = student.toString();
String expected = "'''\n" +
"Student Name: Jim Bo\n" +
"Exam 01 --> 100.0\n" +
"Exam 11 --> 150.0\n" +
"Exam 21 --> 250.0\n" +
"Exam 31 --> 0.0\n" +
"\n" +
"125.0\n" +
"'''";
Assert.assertEquals(expected, actual);
}
}
Binary file added target/classes/io/zipcoder/Classroom.class
Binary file not shown.
Binary file added target/classes/io/zipcoder/Student.class
Binary file not shown.
Binary file not shown.
Binary file added target/test-classes/io/zipcoder/StudentTest.class
Binary file not shown.