Question: Write a JUnit test file to reasonably test the java code in GradeSheet. java Submit the JUnit test file 2) Check the code coverage of

Write a JUnit test file to reasonably test the java code in GradeSheet. java Submit the JUnit test file 2) Check the code coverage of your JUnit using eclEmma (or an emma or JaCoCo plugin for an alternative environment if you pref What is the instruction coverage? What is the branch coverage? If you are not 100%, indicate why you think that is. Is it a problem? How could you resolve it? /** * GradeSheet - a simple class for holding a grade sheet. * Currently the grade sheet is limited to assignments all of the same weight, * although it does support dropping the lowest grade. * * */ public class GradeSheet { /** * create a grade sheet for a specified number of assignments * @param numAssignments the number of assignments, >= 0 */ public GradeSheet(int numAssignments) { _assignments = new Integer[numAssignments]; } /** * get the total number of assignments currently supported * @return the number of assignments currently expected, >= 0 */ public int getNumAssignments() { return _assignments.length; } /** * add a new assignment to the grade sheet, increasing the number of assignments * */ public void addAssignment() { Integer[] oldAssigns = _assignments; _assignments = new Integer[oldAssigns.length+1]; for (int i = 0; i < oldAssigns.length; i++) _assignments[i] = oldAssigns[i]; } /** * mark an assignment as ungraded * @param assignment the assignment number from 0 to getNumAssignments()-1 */ public void clearAssignmentGrade(int assignment) { _assignments[assignment] = null; } /** * assign a grade to an assignment in this gradebook * @param assignment the assignment number from 0 to getNumAssignments()-1 * @param grade the grade being assigned to the indicated assignment */ public void setAssignmentGrade(int assignment,int grade) { _assignments[assignment] = Integer.valueOf(grade); } /** * get the grade assigned on a given assignment * @param assignment the assignment number, starting from 0, always < getNumAssignments() * @return the grade or null if the assignment has not yet been graded */ public Integer getAssignmentGrade(int assignment) { return _assignments[assignment]; } /** * get the numeric average of all assignments, assigning a 0 to any assignment that is missing * @return the average */ public float finalAssignmentAverage() { int numAssigns = 0; float total = 0; for (Integer score : _assignments) { numAssigns++; if (score != null) total += score.intValue(); } if (numAssigns == 0) return 0; return total/numAssigns; } /** * get the numeric average of all but the worst assignment, * assigning a 0 to any missing assignment. * @return the average of the best getNumAssignments()-1 assignments */ public float finalAssignmentAverageWithDrop() { int numAssigns = 0; float total = 0; int drop = 0; for (Integer score : _assignments) { numAssigns++; if (score != null) { int scoreValue = score.intValue(); if (numAssigns == 1) drop = scoreValue; else if (drop > scoreValue) drop = scoreValue; total += scoreValue; } } if (numAssigns <= 1) return 0; return (total-drop)/(numAssigns-1); } /** * get the average for all graded assignments, * ignoring any ungraded assignments * @return the average, returns null if no assignments have been graded yet */ public Float currentAssignmentAverage() { int numAssigns = 0; float total = 0; for (Integer score : _assignments) { if (score == null) continue; numAssigns++; total += score.intValue(); } if (numAssigns == 0) return null; return Float.valueOf(total/numAssigns); } private Integer[] _assignments; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!