Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a JUnit test file to reasonably test the java code in GradeSheet.java /** * GradeSheet - a simple class for holding a grade sheet.

Write a JUnit test file to reasonably test the java code in GradeSheet.java

/**

* 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

6th Edition

1943153035, 978-1943153039

More Books

Students also viewed these Databases questions

Question

Understand the principles of a learning organization.

Answered: 1 week ago