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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started