Question: You have been asked to write a program to test the functionality of a co-worker's method. You are given this method signature for getLetterGrade in
You have been asked to write a program to test the functionality of a co-worker's method. You are given this method signature for getLetterGrade in the GradeEstimator class, but you do not know how the method is defined (coded).
/** * Return the letter grade assigned for the given percentage. * This is determined based on the array of letter grades available * and the minimum percentage needed (threshold) for each letter grade. * * PRECONDITIONS: * 1. letter and threshold are non-null and have the same number of elements * 2. each element of letter corresponds with each threshold * 3. thresholds are given in decreasing order * 4. percent is a positive value in range [0,100] * * POSTCONDITION: * 1. parameter arrays are unchanged * 2. a letter grade from the array of letter is returned * * @param letter Array of possible letter grades * @param thresholds The minimum percent that will earn that letter grade * @param percent The percent being evaluated * @return */ private static String getLetterGrade(String[] letter,double[] threshold, double percent)
Which of the available code fragments will best test this method based on the functionality described in the comments? Assume your test code will be in a method in a class in the same package, so that no import statement is needed.
A. String [] letters = {"A","B","C","D","F"}; double [] thresholds = {90,80,70,60,0}; double[] student_percent = {104,95.12,90,89.23,0,50,100,-1}; int n=0; for (double p : student_percent) { String letter = GradeEstimator.getLetterGrade(letters,thresholds,p); System.out.printf("%d. %s ",(++n),p,letter); }
B. System.out.println("This should be an A " + GradeEstimator.getLetterGrade(90));
C. String [] letters = {"A","B","C","D","F"}; double [] thresholds = {90,80,70,60,0}; double[] student_percent = {100,90,80,70,60,50,95.12,89.9999,75,34,0,50,100,67.3}; int n=0; for (double p : student_percent) { String letter = GradeEstimator.getLetterGrade(letters,thresholds,p); //System.out.println((++n) +". \t"+p+"% \tearns "+letter); System.out.printf("%d. %7.2f%% earns %s ",(++n),p,letter); }
D. String [] letters = {"A","B","C","D","F"}; double [] thresholds = {90,80,70,60,0}; int n=0; for (double p = 0.0 ; p <= 100 ; p+=1) { String letter = GradeEstimator.getLetterGrade(letters,thresholds,p); //System.out.println((++n) +". \t"+p+"% \tearns "+letter); System.out.printf("%d. %7.2f%% earns %s ",(++n),p,letter); }
E. String [] letters = {"A","B","C","D","F"}; double [] thresholds = {90,80,70,60,0}; double[] student_percent = thresholds; int n=0; for (double p : student_percent) { String letter = GradeEstimator.getLetterGrade(letters,thresholds,p); //System.out.println((++n) +". \t"+p+"% \tearns "+letter); System.out.printf("%d. %7.2f%% earns %s ",(++n),p,letter); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
