diff --git a/1ano/2semestre/poo/src/aula11/ex2/Gradebook.java b/1ano/2semestre/poo/src/aula11/ex2/Gradebook.java index 00867ed..5c2b05a 100644 --- a/1ano/2semestre/poo/src/aula11/ex2/Gradebook.java +++ b/1ano/2semestre/poo/src/aula11/ex2/Gradebook.java @@ -1,15 +1,14 @@ package aula11.ex2; -import utils.MathTools; - import java.io.*; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.*; -public class Gradebook implements IGradeCalculator { +public class Gradebook { private final LinkedList students = new LinkedList<>(); + private final IGradeCalculator gradeCalculator = new SimpleGradeCalculator(); public void load(String filename) { LinkedList lines = new LinkedList<>(); @@ -42,16 +41,11 @@ public class Gradebook implements IGradeCalculator { } public double calculateAverageGrade(String name) { - return calculate(getStudent(name).getGrades()); - } - - @Override - public double calculate(LinkedList grades) { - return MathTools.media(grades); + return gradeCalculator.calculate(getStudent(name).getGrades()); } public void printAllStudents() { for (Student student : students) - System.out.printf("Nome: %s%nNota Final: %.2f%n%n", student.getName(), calculate(student.getGrades())); + System.out.printf("Nome: %s%nNota Final: %.2f%n%n", student.getName(), gradeCalculator.calculate(student.getGrades())); } } diff --git a/1ano/2semestre/poo/src/aula11/ex2/SimpleGradeCalculator.java b/1ano/2semestre/poo/src/aula11/ex2/SimpleGradeCalculator.java new file mode 100644 index 0000000..7192ed8 --- /dev/null +++ b/1ano/2semestre/poo/src/aula11/ex2/SimpleGradeCalculator.java @@ -0,0 +1,13 @@ +package aula11.ex2; + +import java.util.LinkedList; + +public class SimpleGradeCalculator implements IGradeCalculator { + @Override + public double calculate(LinkedList grades) { + double sum = 0; + for (double n : grades) + sum += n; + return sum / grades.size(); + } +}