Skip to content
Open

Main #29

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
2 changes: 0 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>junit-tests</groupId>
<artifactId>tests</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/Cohort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import java.util.ArrayList;
import java.util.List;

public class Cohort {
public List<Student> students;

}
58 changes: 58 additions & 0 deletions src/main/java/Student.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import java.util.ArrayList;
import java.util.Collection;

public class Student {

long id;
String name ;
ArrayList<Integer> grades;

//Constructor
public Student(long id, String name) {
this.id = id;
this.name = name;
this.grades = grades;
}

// returns the student's id
public long getId(){
return this.id;
}

// returns the student's name
public String getName(){
return this.name;
}

// adds the given grade to the grades list
public void addGrade(int grade){
grades.add(grade);
}

// returns the list of grades
public ArrayList<Integer> getGrades(){
return this.grades;
}

// returns the average of the students grades
public double getGradeAverage(){
double bucket = 0;
for(int grade : this.grades) {
bucket += grade;
}
return bucket/grades.size();
// int averGrade = grades.getGrades()/ grades.size;
}

// updated the grades in the grade list
public void addGrade(){

}

// delete Grade from the grade list
public void deleteGrade(){

}


}
3 changes: 3 additions & 0 deletions src/test/java/CohortTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public class CohortTest {

}
52 changes: 52 additions & 0 deletions src/test/java/StudentTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import org.junit.Test;
import static org.junit.Assert.*;

public class StudentTest {

@Test
public void StudentTest() {
Student me = new Student(11, "Manii");
Student nullMe = null;
assertNotNull(me);
assertNull(nullMe);
}

@Test
public void SettersGettersTest(){
Student me = new Student(11, "Manii");
assertEquals(11, me.getId());
assertEquals("Manii", me.getName());

Student her = new Student(12, "Stephanie");
assertEquals(12, her.getId());
assertEquals("Stephanie", her.getName());
}

@Test
public void AddGradeTest(){
Student me = new Student(11, "Manii");
assertEquals(0, me.addGrade().size());
me.addGrade(60);
assertEquals(1, me.addGrade().size());
me.addGrade(75);
}

@Test
public void AddGetTest(){
Student me = new Student(11, "Manii");
me.addGrade(75);
me.addGrade(60);
assertSame(75, me.getGrades().get(0));
assertSame(60, me.getGrades().get(1));
}

@Test
public void getAverageTest(){
Student me = new Student(11, "Manii");
me.addGrade(90);
me.addGrade(80);
assertEquals(80, me.getGradeAverage(), 0);
me.addGrade(50);
assertEquals(60, me.getGradeAverage(), 0);
}
}