Write a program using the switch statement name GradeReport

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-enter

Solution

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

 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 th
 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 th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site