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
27 changes: 27 additions & 0 deletions src/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
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>org.example</groupId>
<artifactId>src</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>

</dependencies>

</project>
55 changes: 55 additions & 0 deletions src/src/main/java/Student.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import java.util.ArrayList;
import java.util.Scanner;

public class Student {
public long id;
public String name;
public ArrayList<Integer> grades;

public Student(String name, long id, ArrayList<Integer> grades) {
this.id = id;
this.name = name;
this.grades = grades;
}

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

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public ArrayList<Integer> getGrades() {
return grades;
}

public void setGrades(ArrayList<Integer> grades) {
this.grades = grades;
}
public void addGrade(int grade){
Integer gradeEntered = grade;
this.grades.add(gradeEntered);
}
public double getGradeAverage(){
int total = 0;
for(int grade : grades){
total+=grade;
}
return (double) total / grades.size();
}

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

public class StudentTest {

@Test
public void testStudentConstructor() {
Student student = new Student("John Doe", 123456, new ArrayList<Integer>(List.of()));
assertEquals("John Doe", student.getName());
assertEquals(123456, student.getId());
assertEquals(new ArrayList<Integer>(), student.getGrades());
}

@Test
public void testAddGrade() {
Student student = new Student("John Doe", 123456, new ArrayList<Integer>(List.of()));
student.addGrade(90);
student.addGrade(85);
assertEquals(2, student.getGrades().size());
assertEquals(90, (int) student.getGrades().get(0));
assertEquals(85, (int) student.getGrades().get(1));
}

@Test
public void testGradeAverage() {
Student student = new Student("John Doe", 123456, new ArrayList<Integer>(List.of()));
student.addGrade(90);
student.addGrade(85);
assertEquals(87.5, student.getGradeAverage(), 0.0);
}
}