Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(JAVA Programming) Write a program using the switch statement name GradeReport t

ID: 3682808 • Letter: #

Question

(JAVA Programming) Write a program using the switch statement name GradeReport that reads a grade from the user and prints the comments accordingly.

Instruction: 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 do 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 reenter

//I have a problem combining the switch statement with the do/while loops.

Explanation / Answer

import java.util.*;

class GradeReport
{
   public static void main(String args[])
   {
       int g;

       Scanner scan=new Scanner(System.in);
       do
       {
       System.out.println("enter the grade");
       g=scan.nextInt();
       if(g>=0 && g<=100)
           break;
       }while(true);

       switch((int) g/10)
       {
           case 1:
               System.out.println("Grade i");
               break;

           case 2:
               System.out.println("Grade h");
               break;
           case 3:
               System.out.println("Grade g");
               break;
           case 4:
               System.out.println("Grade f");
               break;
           case 5:
               System.out.println("Grade e");
               break;
           case 6:
               System.out.println("Grade d");
               break;
           case 7:
               System.out.println("Grade c");
               break;
           case 8:
               System.out.println("Grade b");
               break;
           case 9:
               System.out.println("Grade a");
               break;

       }
   }
}