Question: package app; import grading.*; import java.util.*; /** * An application for calculating the numeric grade for * a course from the grades on individual assignments.






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 grades, hws, pas; Map courseWeights;
// 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 // 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 // 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; } }
2 Overvieww SagaciousMedia is a (fictitious) company that develops educational hardware, software, and content for both the formal and informal education markets. SagaciousMedia's products are designed to excite and educate students, and to inspire and assist teachers/instructors. They are in the process of developing a suite of products for working with grading assignments of various kinds (e.g. exams, homework assignments, labs, programming assignments). They have hired you to construct several interfaces/classes that will, ultimately, become part of these products. These classes/interfaces might be used by the first application they are creating (called Gradient) to calculate the numerical grade for a course that has 6 programming assignments (with the lowest dropped) that account for 40% of the course grade, 5 homework assignments that account for 10% of the course grade, one midterm exam that accounts for 20% of the course grade, and a final exam that accounts for 30% of the course grade. For example, assuming the the programming assignments and homework assignments are each graded on a 20-point scale and the exams are each graded on a 100-point scale, the following grades 20.0 18.05.0 15.0 20.0 200 200 50 0.0 10.0 15.0 80.0 75.6 should result in a PA grade of 20.0+18.0+15.0+20.0+20.0-93.0, a homework grade of 20.0+5.0+0.0+10.0+15.0-50.0 and a course grade of 0.4-93.0+0.1.50.0+0.2.80.0+0.3-75.0-37.2+5.0+16.0+22.5-80.7. 2 Overvieww SagaciousMedia is a (fictitious) company that develops educational hardware, software, and content for both the formal and informal education markets. SagaciousMedia's products are designed to excite and educate students, and to inspire and assist teachers/instructors. They are in the process of developing a suite of products for working with grading assignments of various kinds (e.g. exams, homework assignments, labs, programming assignments). They have hired you to construct several interfaces/classes that will, ultimately, become part of these products. These classes/interfaces might be used by the first application they are creating (called Gradient) to calculate the numerical grade for a course that has 6 programming assignments (with the lowest dropped) that account for 40% of the course grade, 5 homework assignments that account for 10% of the course grade, one midterm exam that accounts for 20% of the course grade, and a final exam that accounts for 30% of the course grade. For example, assuming the the programming assignments and homework assignments are each graded on a 20-point scale and the exams are each graded on a 100-point scale, the following grades 20.0 18.05.0 15.0 20.0 200 200 50 0.0 10.0 15.0 80.0 75.6 should result in a PA grade of 20.0+18.0+15.0+20.0+20.0-93.0, a homework grade of 20.0+5.0+0.0+10.0+15.0-50.0 and a course grade of 0.4-93.0+0.1.50.0+0.2.80.0+0.3-75.0-37.2+5.0+16.0+22.5-80.7