Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server Query Performance Tuning

Authors: Sajal Dam, Grant Fritchey

4th Edition

1430267429, 9781430267423

More Books

Students also viewed these Databases questions

Question

Describe the various types of data.

Answered: 1 week ago

Question

2 What is the philosophy of performance management?

Answered: 1 week ago

Question

=+j Enabling a productive global workforce.

Answered: 1 week ago