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:
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();
//here we have divded the input grade by 10 to convert into one digit
int input = grade/10;
//here we are switiching to each case
switch(input)
{
//if input is 10 or 9 grade is A case 10:
case 9:
c = 'A';
System.out.printf("You have earned the letter grade: %c ",c);
break;
//if input is 8 grade is B
case 8: c = 'B';
System.out.printf("You have earned the letter grade: %c ",c);
break;
//if input is 7 grade is C
case 7: c = 'C';
System.out.printf("You have earned the letter grade: %c ",c);
break;
//if input is 6 grade is D
case 6: c = 'D';
System.out.printf("You have earned the letter grade: %c ",c);
break;
//cases if grade is F
case 5:
case 4:
case 3:
case 2:
case 1:
case 0: c = 'F';
System.out.printf("You have earned the letter grade: %c ",c);
break;
//if grade is invalid i.e input default:
s ="ERROR You have entered an invalid input";
System.out.println(s);
break;
}
}
}
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