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

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!