Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part A: Build a program that will input a grade from the user. Your grade input from the user will be an integer. When the

Part A:

Build a program that will input a grade from the user. Your grade input from the user will be an integer. When the input is stored, use an if-else-if block of code to determine the letter grade of the inputted integer grade. Don't use if statements by itself or another strategy to solve this problem. You will print an Error for inputs greater than 100. You will also print an Error for inputs less than 0. Both errors must be handled together by a compound conditional statement that is joined by a short circuit && or ||. The error should not be a print statement. It should use a String variable that is assigned the value of ERROR. You must a Char variable for each letter grade. You must use a System.out.println for printing the error. You must use a System.out.printf for printing the letter grade.

You will run the program three times. Each time you run the program you will enter three different inputs.

1. 140

2. -42

3. 85

The output of your program should print the following:

ERROR You have entered an invalid input

ERROR You have entered an invalid input

You have earned the letter grade: B

Part B:

Convert the if-else-if code block to a switch statement to solve the problem. Use modulus or division to convert the grade input so that the range of grades are converted to one value. All other requirements from part I is still required for part two. Use the same inputs and output should also remain the same.

Part C:

Write a paragraph on why you should not use if statements by itself to solve part a and why using if-else-if statements is a better technique.

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

Handbook Of Relational Database Design

Authors: Candace C. Fleming, Barbara Von Halle

1st Edition

0201114348, 978-0201114348

More Books

Students also viewed these Databases questions