First commit
This commit is contained in:
40
Homework 8/src/grading/TotalStrategy.java
Executable file
40
Homework 8/src/grading/TotalStrategy.java
Executable file
@@ -0,0 +1,40 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user