Skip to content
Open

done #35

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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.zipcoder</groupId>
<artifactId>classroom</artifactId>
<groupId>com.zipcodewilmington</groupId>
<artifactId>loop_labs</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
Expand Down
97 changes: 96 additions & 1 deletion src/main/java/io/zipcoder/Classroom.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,99 @@
package io.zipcoder;

import com.sun.org.apache.xml.internal.security.encryption.AgreementMethod;

import java.util.*;

public class Classroom {
}
// Declaring variables
public int maxNumOfStudents;
Student[] students = new Student[30];
ArrayList<Student> studentsList = new ArrayList();

public Classroom(int maxNumOfStudents){
this.maxNumOfStudents = maxNumOfStudents;
}

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

public Classroom(){
}

public ArrayList<Student> getStudents(){
return studentsList;
}

public Double getAverageExamScore() {
Double totalExams = 0.0;
for (int i = 0; i < students.length; i++) {
totalExams += students[i].getAverageExamScore();
}
return totalExams / students.length;
}

public void addStudent(Student student1) {
studentsList.add(student1);
}

public void removeStudent(Student firstName, Student lastName) {
for (int i = 0; i < studentsList.size(); i++) {
if(studentsList.get(i).firstName.equals(firstName) && studentsList.get(i).lastName.equals(lastName)){
studentsList.remove(i);
}
students[students.length-1] = null;
break;
}
}

public Student[] getStudentsByScore() {
Arrays.sort(students, Collections.reverseOrder());
return students;
}

public Map getGradeBook() {
Map<String, String> gradeBook = new TreeMap<>();
for (int i = 0; i < students.length; i++) {
if(students[i].getAverageExamScore() >= 90){
gradeBook.put(students[i].firstName, "A");
}
else if(students[i].getAverageExamScore() >= 80) {
gradeBook.put(students[i].firstName, "B");
}
else if(students[i].getAverageExamScore() >= 70) {
gradeBook.put(students[i].firstName, "C");
}
else if(students[i].getAverageExamScore() >= 60) {
gradeBook.put(students[i].firstName, "D");
}
else {gradeBook.put(students[i].firstName, "F");
}

}
for (Map.Entry j: gradeBook.entrySet()){
System.out.println(j);
}
return gradeBook;
}




















}
86 changes: 85 additions & 1 deletion src/main/java/io/zipcoder/Student.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,88 @@
package io.zipcoder;

public class Student {
import java.util.ArrayList;
import java.util.Arrays;

// this is a blueprint in case we want multiple students
public class Student implements Comparable<Student>{
// declaring variables
String firstName;
String lastName;
ArrayList<Double> examScores;

public Student(String firstName, String lastName, ArrayList<Double> examScores){
// assigning parameter variables to the object "Student" in line 13
this.firstName = firstName;
this.lastName = lastName;
this.examScores = examScores;
}

public Student(String firstName, String lastName, Double[] testScores){
this.firstName = firstName;
this.lastName = lastName;
// this converts an array to an arrayList
this.examScores = new ArrayList<>(Arrays.asList(testScores));
}

public String getFirstName() {
return firstName;
}

public String getLastName() {
return lastName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

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

public String getExamScores(){
String output = " Exam Scores:\n";
for (int i = 0; i < examScores.size(); i++) {
output += " \t" + "Exam " + (i+1) + " -> " + Math.round(examScores.get(i));
// if i is not equal to the index of last element than make a new line,
// otherwise if its the last index dont go to the next line.
if (i != examScores.size()-1) {
output += "\n";
}
}
return output;
}


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

public void setExamScore(int examNum, double newScoreOnExam){
examScores.set(examNum, newScoreOnExam);
}

public Double getAverageExamScore() {
Double totalExams = 0.0;
for (int i = 0; i < getNumberOfExamsTaken(); i++) {
totalExams += examScores.get(i);
}
return totalExams / getNumberOfExamsTaken();
}

@Override
public String toString(){
return "Student Name: " + getFirstName() + " " + getLastName() + "\n" +
"> Average Score: " + getAverageExamScore() + "\n>" + getExamScores();
}


@Override
public int compareTo(Student o) {
return Double.compare(this.getAverageExamScore(), o.getAverageExamScore());
}
}
175 changes: 175 additions & 0 deletions src/test/java/io/zipcoder/ClassroomTest.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,179 @@
package io.zipcoder;

import com.sun.xml.internal.fastinfoset.tools.XML_SAX_StAX_FI;
import org.junit.Assert;
import org.junit.Test;

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

public class ClassroomTest {

@Test
public void getStudentsTest() {
int maxNumOfStudents = 4;
Classroom class1 = new Classroom(maxNumOfStudents);
ArrayList<Double> s1Scores = new ArrayList<>(Arrays.asList(100.0));
ArrayList<Double> s2Scores = new ArrayList<>(Arrays.asList(125.0));
ArrayList<Double> s3Scores = new ArrayList<>(Arrays.asList(150.0));
ArrayList<Double> s4Scores = new ArrayList<>(Arrays.asList(175.0));

Student s11 = new Student("student", "one", s1Scores);
Student s12 = new Student("student", "two", s2Scores);
Student s13 = new Student("student", "three", s3Scores);
Student s14 = new Student("student", "four", s4Scores);

ArrayList <Student> expectedStudents = new ArrayList<Student>(Arrays.asList(s11, s12, s13, s14));
class1.studentsList = expectedStudents;
ArrayList actual = class1.getStudents();
ArrayList expected = expectedStudents;

Assert.assertEquals(expected, actual);

}

@Test
public void getAverageExamScore() {
int maxNumOfStudents = 2;
// : Given
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 = {s1, s2};
Classroom classroom = new Classroom(students);

Double expected = 125.0;

// When
Double output = classroom.getAverageExamScore();

// Then
Assert.assertEquals(expected, output);
}

@Test
public void addStudentTest() {
// : Given
int maxNumberOfStudents = 1;
Classroom classroom = new Classroom(maxNumberOfStudents);
Double[] examScores = { 100.0, 150.0, 250.0, 0.0 };
Student s1 = new Student("Leon", "Hunter", examScores);

String expected = " ===========================\n" +
" []\n" +
" ===========================\n" +
" [Student Name: Leon Hunter\n" +
" > Average Score: 125\n" +
" > Exam Scores:\n" +
" Exam 1 -> 100\n" +
" Exam 2 -> 150\n" +
" Exam 3 -> 250\n" +
" Exam 4 -> 0";

// When
ArrayList<Student> preEnrollment = classroom.getStudents();
classroom.addStudent(s1);
ArrayList<Student> postEnrollment = classroom.getStudents();

// Then
String preEnrollmentAsString = preEnrollment.toString();
String postEnrollmentAsString = postEnrollment.toString();

System.out.println("===========================");
System.out.println(preEnrollmentAsString);
System.out.println("===========================");
System.out.println(postEnrollmentAsString);

}

@Test
public void removeStudentTest() {
// : Given
int maxNumberOfStudents = 1;
Classroom classroom = new Classroom(maxNumberOfStudents);
Double[] examScores = { 100.0, 150.0, 250.0, 0.0 };
Student s1 = new Student("Leon", "Hunter", examScores);
classroom.addStudent(s1);

int actual = classroom.getStudents().size();

// When
ArrayList<Student> preEnrollment = classroom.getStudents();
classroom.removeStudent(s1, s1);
ArrayList<Student> postEnrollment = classroom.getStudents();


Assert.assertEquals(maxNumberOfStudents, actual);
System.out.println(maxNumberOfStudents);

}

@Test
public void getStudentsByScoreTest() {

// : Given
ArrayList<Double> s1Scores = new ArrayList<>(Arrays.asList(100.0));
ArrayList<Double> s2Scores = new ArrayList<>(Arrays.asList(125.0));
ArrayList<Double> s3Scores = new ArrayList<>(Arrays.asList(150.0));
ArrayList<Double> s4Scores = new ArrayList<>(Arrays.asList(175.0));

Student s1 = new Student("student", "one", s1Scores);
Student s2 = new Student("student", "two", s2Scores);
Student s3 = new Student("student", "three", s3Scores);
Student s4 = new Student("student", "four", s4Scores);

Student[] expectedStudents = {s2, s3, s4, s1};
Classroom expectedClassroom = new Classroom(expectedStudents);

// When
Student[] actualStudents = {s3, s4, s1, s2};
Classroom actualClassroom = new Classroom(actualStudents);
actualClassroom.getStudentsByScore();

// When
Assert.assertEquals(actualClassroom.getStudents(), expectedClassroom.getStudents());

}
@Test
public void getGradeBookTest() {

// : Given
ArrayList<Double> s1Scores = new ArrayList<>(Arrays.asList(90.0));
ArrayList<Double> s2Scores = new ArrayList<>(Arrays.asList(85.0));
ArrayList<Double> s3Scores = new ArrayList<>(Arrays.asList(77.0));
ArrayList<Double> s4Scores = new ArrayList<>(Arrays.asList(65.0));

Student s1 = new Student("student", "one", s1Scores);
Student s2 = new Student("student", "two", s2Scores);
Student s3 = new Student("student", "three", s3Scores);
Student s4 = new Student("student", "four", s4Scores);

Student[] expectedStudents = {s2, s3, s4, s1};
Classroom expectedClassroom = new Classroom(expectedStudents);

// When
Student[] actualStudents = {s3, s4, s1, s2};
Classroom actualClassroom = new Classroom(actualStudents);
actualClassroom.getStudentsByScore();

// When
Assert.assertEquals(actualClassroom.getStudents(), expectedClassroom.getStudents());

}













}
Loading