Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I got this code when I used JUnit in the Netbeans, How to adjust it to pass the

ID: 3673725 • Letter: I

Question

I got this code when I used JUnit in the Netbeans, How to adjust it to pass the test?

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gradebooktest;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
*
* @author Win-8.1
*/
public class GradeBookTest {
  
public GradeBookTest() {
}
  
@BeforeClass
public static void setUpClass() {
}
  
@AfterClass
public static void tearDownClass() {
}
  
@Before
public void setUp() {
}
  
@After
public void tearDown() {
}

/**
* Test of setCourseName method, of class GradeBook.
*/
@Test
public void testSetCourseName() {
System.out.println("setCourseName");
String name = "";
GradeBook instance = null;
instance.setCourseName(name);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}

/**
* Test of getCourseName method, of class GradeBook.
*/
@Test
public void testGetCourseName() {
System.out.println("getCourseName");
GradeBook instance = null;
String expResult = "";
String result = instance.getCourseName();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}

/**
* Test of displayMessage method, of class GradeBook.
*/
@Test
public void testDisplayMessage() {
System.out.println("displayMessage");
GradeBook instance = null;
instance.displayMessage();
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}

/**
* Test of processGrades method, of class GradeBook.
*/
@Test
public void testProcessGrades() {
System.out.println("processGrades");
GradeBook instance = null;
instance.processGrades();
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}

/**
* Test of getMinimum method, of class GradeBook.
*/
@Test
public void testGetMinimum() {
System.out.println("getMinimum");
GradeBook instance = null;
int expResult = 0;
int result = instance.getMinimum();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}

/**
* Test of getMaximum method, of class GradeBook.
*/
@Test
public void testGetMaximum() {
System.out.println("getMaximum");
GradeBook instance = null;
int expResult = 0;
int result = instance.getMaximum();
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}

/**
* Test of getAverage method, of class GradeBook.
*/
@Test
public void testGetAverage() {
System.out.println("getAverage");
int[] setOfGrades = null;
GradeBook instance = null;
double expResult = 0.0;
double result = instance.getAverage(setOfGrades);
assertEquals(expResult, result, 0.0);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}

/**
* Test of outputBarChart method, of class GradeBook.
*/
@Test
public void testOutputBarChart() {
System.out.println("outputBarChart");
GradeBook instance = null;
instance.outputBarChart();
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}

/**
* Test of outputGrades method, of class GradeBook.
*/
@Test
public void testOutputGrades() {
System.out.println("outputGrades");
GradeBook instance = null;
instance.outputGrades();
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
  
}

-----------------------------------------------------------------

the original code is:

// Grade book using two-dimensional array to store grades.
public class GradeBook
{
private String courseName; // name of course this grade book represents
private int grades[][]; // two-dimensional array of student grades
public GradeBook( String name, int gradesArray[][] )
{
courseName = name; // initialize courseName
grades = gradesArray; // store grades
} // end two-argument GradeBook constructor
public void setCourseName( String name )
{
courseName = name; // store the course name
} // end method setCourseName
public String getCourseName()
{
return courseName;
} // end method getCourseName
public void displayMessage()
{
System.out.printf( "Welcome to the grade book for %s! ",
getCourseName() );
} // end method displayMessage
public void processGrades()
{
outputGrades();
System.out.printf( " %s %d %s %d ",
"Lowest grade in the grade book is", getMinimum(),
"Highest grade in the grade book is", getMaximum() );
outputBarChart();
} // end method processGrades
public int getMinimum()
{
int lowGrade = grades[ 0 ][ 0 ];
for ( int studentGrades[] : grades )
{
for ( int grade : studentGrades )
{
if ( grade < lowGrade )
lowGrade = grade;
} // end inner for
} // end outer for
return lowGrade;
} // end method getMinimum

public int getMaximum()
{
int highGrade = grades[ 0 ][ 0 ];
for ( int studentGrades[] : grades )
{
for ( int grade : studentGrades )
{
if ( grade > highGrade )
highGrade = grade;
} // end inner for
} // end outer for
return highGrade;
} // end method getMaximum
public double getAverage( int setOfGrades[] )
{
int total = 0; // initialize total
for ( int grade : setOfGrades )
total += grade;
return (double) total / setOfGrades.length;
} // end method getAverage
public void outputBarChart()
{
System.out.println( "Overall grade distribution:" );
int frequency[] = new int[ 11 ];
for ( int studentGrades[] : grades )
{
for ( int grade : studentGrades )
++frequency[ grade / 10 ];
} // end outer for
for ( int count = 0; count < frequency.length; count++ )
{
if ( count == 10 )
System.out.printf( "%5d: ", 100 );
else
System.out.printf( "%02d-%02d: ",
count * 10, count * 10 + 9 );
for ( int stars = 0; stars < frequency[ count ]; stars++ )
System.out.print( "*" );
System.out.println(); // start a new line of output
} // end outer for
} // end method outputBarChart
public void outputGrades()
{
System.out.println( "The grades are: " );
System.out.print( " " );
for ( int test = 0; test < grades[ 0 ].length; test++ )
System.out.printf( "Test %d ", test + 1 );
System.out.println( "Average" );
for ( int student = 0; student < grades.length; student++ )
{
System.out.printf( "Student %2d", student + 1 );
for ( int test : grades[ student ] )
System.out.printf( "%8d", test );
double average = getAverage( grades[ student ] );
System.out.printf( "%9.2f ", average );
} // end outer for
} // end method outputGrades } // end class GradeBook

Explanation / Answer

To pass the test means it should not be less than minimum i.e,

public int getMinimum()
{
int lowGrade = grades[ 0 ][ 0 ];

int testpass;
for ( int studentGrades[] : grades )
{
for ( int grade : studentGrades )
{
if ( grade < lowGrade )
lowGrade = grade;

} // end inner for

} // end outer for
return lowGrade;
} // end method getMinimum

if(testpass>=grade)

{

system.out.println("the test will be passed");

}