Question
Using Java, implement the DropFilter class by following below instructions. Also, please make sure that it works with Gradient class and Grade class provided below.
Using Java, implement the DropFilter class by following below instructions. Also, please make sure that it works with Gradient class and Grade class provided below.
package app;
import grading.*;
import java.util.*;
/**
* An application for calculating the numeric grade for
* a course from the grades on individual assignments.
*
* This version assumes that the course is structured as follows:
*
* 6 programming assignments (PAs) accounting for 40% of the course grade
* after the lowest grade is dropped.
*
* 5 homework assignments (HWs) accounting for 10% of the course grade.
*
* 1 mid-term exam (Midterm) accounting for 20% of the course grade.
*
* 1 final exam (Final) accounting for 30% of the course grade.
*
* @version 1.0
* @author Sagacious Media
*
*/
public class Gradient
{
/**
* The entry point for the application.
*
* @param args The 13 grades (ordered as above). Missing grades can be entered as "NA".
*/
public static void main(String[] args)
{
Filter paFilter;
Grade courseGrade, hwGrade, paGrade;
GradingStrategy courseStrategy, hwStrategy, paStrategy;
List
Map
// Early exit
if ((args == null) || (args.length != 13))
{
System.err.println("You must enter all 13 grades. (Use NA for missing.)");
System.exit(1);
}
// Create the filter and strategy for PAs
paFilter = new DropFilter(true, false);
paStrategy = new TotalStrategy();
// Create the strategy for HWs
hwStrategy = new TotalStrategy();
// Create the weights and strategy for the course grade
courseWeights = new HashMap
courseWeights.put("PAs", 0.4);
courseWeights.put("HWs", 0.1);
courseWeights.put("Midterm", 0.2);
courseWeights.put("Final", 0.3);
courseStrategy = new WeightedTotalStrategy(courseWeights);
try
{
// Put the PA grades in a List
pas = new ArrayList
for (int i=0; i
{
pas.add(parseGrade("PA"+(i+1), args[i]));
}
// Calculate the PA grade (after filtering)
paGrade = paStrategy.calculate("PAs", paFilter.apply(pas));
// Put the HW grades in a List
hws = new ArrayList
for (int i=0; i
{
hws.add(parseGrade("HW"+(i+1), args[i+6]));
}
// Calculate the HW grade
hwGrade = hwStrategy.calculate("HWs", hws);
// Put all of the grades in a List
grades = new ArrayList
grades.add(paGrade);
grades.add(hwGrade);
grades.add(parseGrade("Midterm", args[11]));
grades.add(parseGrade("Final", args[12]));
// Calculate the final grade
courseGrade = courseStrategy.calculate("Course Grade", grades);
// Display the final grade
System.out.println(courseGrade.toString());
}
catch (SizeException se)
{
System.out.println("You entered too few valid grades.");
}
catch (IllegalArgumentException iae)
{
// Should never get here since all keys should be valid
}
}
/**
* Construct a Grade object from a key and a String representation of
* its value. If the String representation of the value is null or not a valid
* double then the resulting Grade will have a missing value.
*
* @param key The key for the Grade
* @param value The String representation of the value
* @return The corresponding Grade object
* @throws IllegalArgumentException if the key is invalid
*/
private static Grade parseGrade(String key, String value) throws IllegalArgumentException
{
Grade result;
try
{
Double v;
if (value == null) v = null;
else v = new Double(Double.parseDouble(value));
result = new Grade(key, v);
}
catch (NumberFormatException nfe)
{
result = new Grade(key, null);
}
return result;
}
}
Grade.java
package grading;
public class Grade implements Comparable
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started