AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

Testing Grade Conversion Using Arrays

APCSA-V6VXHK

A school has a three tier grading scale:

A = 85-100
C = 70-84
F = 0-69

The following method accepts the numeric grade as the parameter and returns the corresponding letter grade:

public static String letterGrade(int numGrade)
{
    // code not shown
}

Which of the following segments of code will best test this method and determine which grades are not being converted correctly?

A
int[] numGrades = {100, 95, 90, 87, 83, 80, 77, 70, 69, 65, 50, 0 };
String[] letterGrades = {"A","A","A","A","C","C","C","C","F","F","F","F"};

for (int i=0; i<numGrades.length; i++)
{
    String letter = letterGrade(numGrades[i]);
    if (!(letter.equals(letterGrades[i])))
        System.out.println("Incorrect conversion: " + numGrades[i] + " to " + letterGrades[i]);
}
B
int[] numGrades = {100, 90, 86, 80, 77, 70, 69, 50, 0 };
String[] letterGrades = {"A","A","A","C","C","C","F","F","F"};

for (int i=0; i<letterGrades.length; i++)
{
    if (letterGrade(!(letterGrades[i]).equals(numGrades[i])))
        System.out.println("Incorrect conversion: " + letterGrades[i] + " to " + numGrades[i]);
}
C
int[] numGrades = {100, 90, 85, 84, 77, 70, 69, 60, 0 };
String[] letterGrades = {"A","A","A","C","C","C","F","F","F"};

for (int i=0; i<numGrades.length; i++)
{
    String letter = letterGrade(numGrades[i]);
    if (!(letter.equals(letterGrades[i])))
        System.out.println("Incorrect conversion: " + numGrades[i] + " to " + letterGrades[i]);
}
D
int[] numGrades = {100, 90, 80, 77, 60, 0 };
String[] letterGrades = {"A","A","C","C","F","F"};

for (int i=0; i<numGrades.length; i++)
{
    String letter = letterGrade(numGrades[i]);
    if (!(letter.equals(letterGrades[i])))
        System.out.println("Incorrect conversion: " + numGrades[i] + " to " + letterGrades[i]);
}
E
int[] numGrades = {100, 90, 85, 84, 77, 70, 69, 60, 0 };
String[] letterGrades = {"A","A","A","C","C","C","F","F","F"};

for (int i=0; i<letterGrades.length; i++)
{
    String letter = letterGrade(letterGrades[i]);
    if (!(letter.equals(numGrades[i])))
        System.out.println("Incorrect conversion: " + letterGrades[i] + " to " + numGrades[i]);
}