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
64 changes: 64 additions & 0 deletions src/main/java/io/zipcoder/Classroom.java
Original file line number Diff line number Diff line change
@@ -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<Student> 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<Student> studentList = new ArrayList<Student>(Arrays.asList(students));

Comparator<Student> examScore = Comparator.comparing(Student::getAverageExamScore);
Comparator<Student> studentName = Comparator.comparing(Student::getFullName);
return null;
}



// public getGradeBook() {
//
// }
}


70 changes: 70 additions & 0 deletions src/main/java/io/zipcoder/Student.java
Original file line number Diff line number Diff line change
@@ -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<Double> 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;
}
}
37 changes: 37 additions & 0 deletions src/test/java/io/zipcoder/ClassroomTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
88 changes: 88 additions & 0 deletions src/test/java/io/zipcoder/StudentTest.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
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.