Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The following Java program asks for and integer input and outputs a letter grade of A,B,C,D,F or error. There is a modulus % used in

The following Java program asks for and integer input and outputs a letter grade of A,B,C,D,F or error. There is a modulus "%" used in the input that needs to remain. Also the switch needs to remain on the code. Inputs of 0 to 59 should output an F. 60-69 a D, 70-79 a C, 80-89 a B and 90-100 an A. Less than 0 and greater 100 should output "ERROR you have entered an invalid input"

1. The code is mostly working except when "100" is entered it results in an "F". Instead of an A. Correct this issue.

2. Test the code with the following inputs and provide screenshots of the output. The out should match the output listed below

Input Output
-1 ERROR you have entered an invalid input
0 F
1 F
59 F
60 D
69 D
70 C
79 C
80 B
89 B
90 A
100 A
101 ERROR you have entered an invalid input

3. The new code should be able to copied. No handwritten code.

import java.util.Scanner;

public class GradeLetterTestPart2

{

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

if(grade<=100)

{

grade=grade/10 ;

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";

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

Databases Illuminated

Authors: Catherine M. Ricardo

1st Edition

0763733148, 978-0763733148

More Books

Students also viewed these Databases questions

Question

Question Can a Roth IRA invest in stock of the IRA owners business?

Answered: 1 week ago