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
44 changes: 44 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
23 changes: 23 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>java-lab01</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
2 changes: 2 additions & 0 deletions .settings/org.eclipse.jdt.apt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=false
9 changes: 9 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
4 changes: 4 additions & 0 deletions .settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
57 changes: 52 additions & 5 deletions src/main/java/com/kpi/fict/DefaultStudentService.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.kpi.fict;

import com.kpi.fict.entities.Exam;
import com.kpi.fict.entities.Student;
import com.kpi.fict.repositories.StudentRepository;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

public class DefaultStudentService implements StudentService {
private StudentRepository studentRepository;
Expand All @@ -14,28 +17,72 @@ public DefaultStudentService(StudentRepository studentRepository) {

@Override
public List<Student> findAllWithRatingLessThan300() {
throw new UnsupportedOperationException("Need to make implementation");
return studentRepository
.findAll()
.stream()
.filter(s -> s
.getExams()
.stream()
.map(Exam::getScore)
.reduce(0.0, Double::sum) < 300)
.collect(Collectors.toList());
}

@Override
public List<Student> findStudentsWhoTakeMathAndOneMoreExam() {
throw new UnsupportedOperationException("Need to make implementation");
return studentRepository.findAll().stream().filter(student ->
student
.getExams()
.stream()
.anyMatch(exam -> exam.getType() == Exam.Type.MATH)
&&
student
.getExams()
.size() == 2
).collect(Collectors.toList());
}

@Override
public List<Student> findStudentsWithRatingMoreThanAvgAndTakeMathExam() {
throw new UnsupportedOperationException("Need to make implementation");
double avgRating = studentRepository
.findAll()
.stream()
.mapToDouble(Student::getRating)
.average()
.orElse(0.0);

return studentRepository
.findAll()
.stream()
.filter(s -> s.getRating() > avgRating && s
.getExams()
.stream()
.anyMatch(e -> e.getType() == Exam.Type.MATH))
.collect(Collectors.toList());
}

@Override
public List<Student> findStudentsWithoutExams() {
throw new UnsupportedOperationException("Need to make implementation");
return studentRepository
.findAll()
.stream()
.filter(s -> s.getExams().size() == 0)
.collect(Collectors.toList());
}

//Delimiter: ','
@Override
public List<String> calculateAvgRatingForEachStudent() {
throw new UnsupportedOperationException("Need to make implementation");
return studentRepository
.findAll()
.stream()
.map(s -> s.getName() + "," + s
.getExams()
.stream()
.mapToDouble(Exam::getScore)
.average()
.orElse(0.0))
.collect(Collectors.toList());
}

public StudentRepository getStudentRepository() {
Expand Down
Binary file not shown.
Binary file added target/classes/com/kpi/fict/StudentService.class
Binary file not shown.
Binary file not shown.
Binary file added target/classes/com/kpi/fict/entities/Exam.class
Binary file not shown.
Binary file not shown.
Binary file not shown.