In: Computer Science
import java.util.Scanner;
public class LetterGrade {
// The method you write will return a String representing a
letter
// grade (e.g., "A", "A-", "B+", etc.).
// The letter grade is determined by the given percentage,
according
// to the scale specified on page 2 of the class syllabus
(available
// here:
https://kyledewey.github.io/comp110-spring18/syllabus.pdf).
// You may assume that the given percentage is between 0.0 and
100.0
// TODO - write your code below this comment.
public static String letterGrade(double percentage){
if (percentage >= 92.5) {
return "A";
}
else if (percentage >= 89.5){
return "A-";
}
else if (percentage >= 86.5){
return "B+";
}
else if (percentage >= 82.5){
return "B";
}
else if (percentage >= 79.5){
return "B-";
}
else if (percentage >= 76.5){
return "C+";
}
else if (percentage >= 72.5){
return "C";
}
else if (percentage >= 69.5){
return "C-";
}
else if (percentage >= 66.5){
return "D+";
}
else if (percentage >= 62.5){
return "D";
}
else if (percentage >= 59.5){
return "D-";
}
else {
return "F";
}
}
// DO NOT MODIFY main!
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter grade as percentage: ");
double percentage = input.nextDouble();
System.out.println("Letter grade: " +
letterGrade(percentage));
}
}
NEED HELP WITH TEST CODE
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class LetterGradeTest {
// TODO - write your code below this comment.
// Write 12 tests, where each test corresponds
// to one of the possible class grades. As a hint,
// most of these tests look a lot like each other, so
// you might be able to work faster by copy-pasting
// the same test and then editing it for the given case.
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions. Thank You! =========================================================================== import static org.junit.Assert.assertEquals; import org.junit.Test; public class LetterGradeTest { // TODO - write your code below this comment. // Write 12 tests, where each test corresponds // to one of the possible class grades. As a hint, // most of these tests look a lot like each other, so // you might be able to work faster by copy-pasting // the same test and then editing it for the given case. @Test public void test1(){ assertEquals(LetterGrade.letterGrade(92.5),"A"); } @Test public void test2(){ assertEquals(LetterGrade.letterGrade(89.5),"A-"); } @Test public void test3(){ assertEquals(LetterGrade.letterGrade(86.5),"B+"); } @Test public void test4(){ assertEquals(LetterGrade.letterGrade(82.5),"B"); } @Test public void test5(){ assertEquals(LetterGrade.letterGrade(79.5),"B-"); } @Test public void test6(){ assertEquals(LetterGrade.letterGrade(76.5),"C+"); } @Test public void test7(){ assertEquals(LetterGrade.letterGrade(72.5),"C"); } @Test public void test8(){ assertEquals(LetterGrade.letterGrade(69.5),"C-"); } @Test public void test9(){ assertEquals(LetterGrade.letterGrade(66.5),"D+"); } @Test public void test10(){ assertEquals(LetterGrade.letterGrade(62.5),"D"); } @Test public void tes11(){ assertEquals(LetterGrade.letterGrade(59.5),"D-"); } @Test public void test12(){ assertEquals(LetterGrade.letterGrade(59.4),"F"); } }
===================================================================