Question: Hi, Code the following using Java only and no loops. Part 1 is completed, I need help with Part 2. Not sure how to use
Hi, Code the following using Java only and no loops. Part 1 is completed, I need help with Part 2. Not sure how to use modulus, keep in mind same conditions apply from Part 1 to Part 2. Also the tested inputs below must produce the same output from part 1.
Part I
Create a program that input a grade from the user. The grade input from the user will be an integer. Once the input is stored, use an if-else-if block of code to determine the letter grade of the inputted integer grade. Do not use if statements by itself or another strategy to solve this problem. You will print and 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 &&. 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 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.
140 -42 85 The output of your program should print the following from the above test:
ERROR You have entered an invalid input
ERROR You have entered an invalid input
You have earned the letter grade: B
Part II
Convert the if-else-if code block to a switch statement to solve the problem. Use modulus 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.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
