Bom Dia ! Estou tendo dificuldade para implementar esse algoritmo alguém já trabalhou com isso ? Algoritmo da Média Ponderada (WAA). Cada elemento da fórmula pode ser o resultado de outro cálculo do WWA.
Given the current class:
public class WeightedGrade {
public Float grade = null;
public Float weight = 0F;
List<WeightedGrade> childGrades = null;
public WeightedGrade() {
this.weight = 1F;
}
public WeightedGrade((Float grade, Float weight) {
this.grade = grade;
this.weight = weight;
}
public WeightedGrade(Float grade, Float weight, List<WeightedGrade) childGrades) {
this.grade = grade;
this.weight = weight;
this.childGrades = childGrades;
}
Implement the WeightedGradeAverage calculator:
class WeightedGradeAverage {
public static Float average(WeightedGrade weightedGrade) {
//TODO:
}
}
Which should pass the following test (at least)
WeightedGrade a1 = new WeightedGrade(100, 1)
WeightedGrade a2 = new WeightedGrade(null, 3)
WeightedGrade a3 = new WeightedGrade(30, 1)
WeightedGrade b1 = new WeightedGrade(20, 4)
WeightedGrade b2 = new WeightedGrade(100, 2)
WeightedGrade a = new WeightedGrade(null, 20)
a.childGrades = Arrays.asList(a1, a2, a3)
WeightedGrade b = new WeightedGrade(null, 4)
b.childGrades = Arrays.asList(a1, a2, a3)
WeightedGrade c = new WeightedGrade(100, 2)
WeightedGrade evaluation = new WeightedGrade()
evaluation.add(a)
evaluation.add(b)
evaluation.add©
assertEquals(WeightedGradeAverage.average(a), 65)
assertEquals(WeightedGradeAverage.average(b), 20)
assertEquals(WeightedGradeAverage.average©, 100)
assertEquals(WeightedGradeAverage.average(evaluation), 60.7692307692)