Write a program using the switch statement name GradeReport that reads a grade a
ID: 3927480 • Letter: W
Question
Write a program using the switch statement name GradeReport that reads a grade as an integer value from the user and prints the comments accordingly. Prompt the user to enter their grade User must be prompt to enter a numeric grade (0 to 100) if the input isn't an integer between 0 and 100, prompt the user to re-enter Use a while loop for the re-enter of grade then if condition is not met or grade is not between 0 and 100 then prompt the user on the screen as follows ("Error: You must enter an integer between 0 and 100");" Also incorporate a while loop to keep track of tries. Create a variable name "tries" that will keep track of tries no more than 3 therefore if the input isn't an integer between 0 and 100, prompt the user to re-enterExplanation / Answer
GradeReport.java
public class GradeReport {
public static void main(String[] args) {
java.util.Scanner in = new java.util.Scanner(System.in);
int grade = 0;
int tries = 0;
int TOTAL_CHANCES = 3;
int category = 0;
while(tries < TOTAL_CHANCES){
System.out.println("Please enter the grade between 0 and 100");
grade = in.nextInt();
if(grade >= 0 && grade <= 100){
category = grade / 10;
switch(category){
case 10: System.out.println("Perfect score job well"); break;
case 9: System.out.println("well above average. Excellent"); break;
case 8: System.out.println("above average Nice job"); break;
case 7: System.out.println("average"); break;
case 6:
case 5:
case 4:
case 3:
case 2:
case 1:
case 0: System.out.println("below average you should see the professor...to clarify the material presented in class..."); break;
default: System.out.println("Invalid case"); break;
}
break;
}
else{
System.out.println("Error: You must enter an integer between 0 and 100");
tries++;
}
}
}
}
Output:
Please enter the grade between 0 and 100
101
Error: You must enter an integer between 0 and 100
Please enter the grade between 0 and 100
102
Error: You must enter an integer between 0 and 100
Please enter the grade between 0 and 100
103
Error: You must enter an integer between 0 and 100
Please enter the grade between 0 and 100
78
average
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.