Question

Part I Create a Java program that inputs a grade from the user. The grade input...

Part I

Create a Java program that inputs 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 a bunch of if statements by themselves to solve this problem. You will print an error message for inputs greater than 100 and for inputs less than 0. Both errors must be handled together by a compound conditional statement that is joined by a short circuit AND or OR operator. Assign your error message to a String variable and use that variable in a System.out.println statement to print the error. You must assign a char variable for each letter grade. Use System.out.printf to print the letter grade.

Run your program several times using these inputs and ensure that you are receiving these outputs:

  • input: 140
    • expected output: ERROR - You have entered an invalid input.
  • Input: -42
    • expected output: ERROR - You have entered an invalid input.
  • input: 85
    • expected output: You have earned the letter grade B.

Run it a few more times using various other inputs

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;

class GradeDemo
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
int grade;
char letter;
String error="";

while(true)
{
System.out.print("Enter a grade : ");
grade=input.nextInt();

if(grade>100 || grade<0)
{
error="ERROR - You have entered an invalid input.";
System.out.println(error);
}
else
{
if(grade>=90)
{
letter='A';
System.out.printf("You have earned the letter grade %c .",letter);
break;
}
else if(grade>=60 && grade<90)
{
letter='B';
System.out.printf("You have earned the letter grade %c .",letter);
break;
}
else if(grade>=40 && grade<60)
{
letter='C';
System.out.printf("You have earned the letter grade %c .",letter);
break;
}
else
{
letter='D';
System.out.printf("You have earned the letter grade %c .",letter);
break;
}
}
}

}
}

Windews Powershel PS C:\Users\user\Desktop> javac GradelDemo. java ktop> java GradeDemo 140 Enter a grade: ERROR You have ent

Add a comment
Know the answer?
Add Answer to:
Part I Create a Java program that inputs a grade from the user. The grade input...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java programming only Create a Java program that inputs a grade from the user. The grade input from the user will be an...

    Java programming only Create a Java program that inputs 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 a bunch of if statements by themselves to solve this problem. You will print an error message for inputs greater than 100 and for inputs less than 0. Both errors must be...

  • Below is a java program that inputs an integer grade and turns it into a letter...

    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)...

  • Question 1: Consider the following specification for a program. The program reads two inputs from the...

    Question 1: Consider the following specification for a program. The program reads two inputs from the user: a string s and an integer number n. The program concatenates s with itself n-1 times, if the following conditions are satisfied: 1- s consists of 3 characters. 2- The first character in s is a letter. 3- s consists of letters (A-Z a-z) and digits only (0-9) 4-0< n<5 If any of these conditions is not satisfied, the program terminates and prints...

  • p1 p2 in p2 there is a typo, if grade <0 or grade >100: should be...

    p1 p2 in p2 there is a typo, if grade <0 or grade >100: should be if percent <0 or percent > 100: Write a program to compute a person's height & print out a message. The user will input feet and inches. The program will convert that to inches, and then print a message, based on the total inches. If the total inches is greater than 72, the message should be something like, "You're tall." If the total inches...

  • Write a C++ program that will provide a user with a grade range if they enter...

    Write a C++ program that will provide a user with a grade range if they enter a letter grade. Your program should contain one function. Your function will accept one argument of type char and will not return anything (the return type will be void), but rather print statements to the console. Your main function will contain code to prompt the user to enter a letter grade. It will pass the letter grade entered by the user to your function....

  • Wrote a program called ExceptionalDivide that asks the user for 2 integer values and displays the...

    Wrote a program called ExceptionalDivide that asks the user for 2 integer values and displays the quotient of the first value divided by the second value. Make sure the your program reads in the two input values as ints. Your program must catch either of two exceptions that might arise and crash your program java.util.InputMismatchException //wrong data type inputted java.lang.ArithmeticException //divide by zero error Once you catch these exceptions, your program must print out a message explaining what happened and...

  • Implement a Java program using simple console input & output and logical control structures such that...

    Implement a Java program using simple console input & output and logical control structures such that the program prompts the user to enter 5 integer scores between 0 to 100 as inputs and does the following tasks For each input score, the program determines whether the corresponding score maps to a pass or a fail. If the input score is greater than or equal to 60, then it should print “Pass”, otherwise, it should print “Fail”. After the 5 integer...

  • Matlab a) Write a MATLAB code that takes the grade letters from the user and provide him/her with the GPA for that seme...

    Matlab a) Write a MATLAB code that takes the grade letters from the user and provide him/her with the GPA for that semester Enter your grades (letters): AABBC (input) Your GPA is 3.2 output) b) Write a Matlab user defined function to that takes a letter grade and return a numeric grade as shown in the table below. Any other value should give an error message (Invalid Grade). You function name should be Letter2Grade Use the following information to calculate...

  • In Matlab. Use loops. 2. Create an algorithm to allow the user to enter a list...

    In Matlab. Use loops. 2. Create an algorithm to allow the user to enter a list of courses they have taken along with the grades received and the credit hours for each course, and then calculate the user's GPA. The program should first ask the user to type either Yes or No in response to the question, "Do you want to enter a grade?" If the answer is Yes, the user should be asked to enter the name of the...

  • Write a program which: - prompts the user for 2 numerical inputs - stores their two...

    Write a program which: - prompts the user for 2 numerical inputs - stores their two inputs in variables as floats - Use a while in loop to ask a user for a valid operation: (if the user's input operation isn't one of those listed above, instead print a message telling them so, and continue asking for the valid operation) - prompts the user for an arithmetic operation ( + - * / %) - stores the user's input as...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT