41 lines
899 B
Java
Executable File
41 lines
899 B
Java
Executable File
package grading;
|
|
|
|
import java.util.List;
|
|
|
|
/**
|
|
* An implementation GradingStrategy that simply totals the scores for all grades.
|
|
*/
|
|
public class TotalStrategy implements GradingStrategy
|
|
{
|
|
/**
|
|
* Creates a new instance of TotalStrategy.
|
|
*/
|
|
public TotalStrategy()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* @param key
|
|
* The key of the final totaled grade
|
|
* @param grades
|
|
* The list of grades to calculate the final total grade from
|
|
* @return A new grade representing the total of grades
|
|
*/
|
|
public Grade calculate(final String key, final List<Grade> grades) throws SizeException
|
|
{
|
|
if (grades == null || grades.isEmpty())
|
|
{
|
|
throw new SizeException();
|
|
}
|
|
|
|
Double total = 0.0;
|
|
|
|
for (Grade grade : grades)
|
|
{
|
|
total += Missing.doubleValue(grade.getValue());
|
|
}
|
|
|
|
return new LeafGrade(key, total);
|
|
}
|
|
}
|