Question: Below is a java program that inputs an integer grade and turns it into a letter grade. Update the below java code as follows and

Below is a java program that inputs an integer grade and turns it into a letter grade.

Update the below java code as follows and comment each line to explain what is happening:

1. Convert the if-else-if code block to a switch statement to solve the problem.

2. Use modulus to convert the grade input so that the range of grades are converted to one value. (comment the line)

import java.util.Scanner;

public class GradeLetterTest {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.println("Enter integer grade");

String s = "";

char c ;

int grade = scan.nextInt();

if(grade<0 || grade> 100) {

s ="ERROR You have entered an invalid input";

System.out.println(s);

} else {

if(grade>=90) {

c = 'A';

} else if(grade>=80 && grade<90) {

c = 'B';

} else if(grade>=70 && grade<80) {

c = 'C';

} else if(grade>=60 && grade<70) {

c = 'D';

} else {

c='F';

}

System.out.printf("You have earned the letter grade: %c ",c);

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!