import java.io.*; 
  
public class PassingGradeFun 
{ 
  static char getGrade() throws Exception 
  { 
    char result = 'X'; // the default value 

    BufferedReader cin; 
    cin = new BufferedReader(new InputStreamReader(System.in)); 

    while (true) 
    { 
      System.out.print("What is your grade? [A, B, C, D, F, or X to quit]: "); 
      result = cin.readLine().charAt(0); 

      if (result == 'A' || result == 'B' || result == 'C') break; 
      if (result == 'D' || result == 'F') break; 
      if (result == 'X' || result == 'x') break; 

      System.out.println("" + result + " is not a valid grade. Try again..."); 
    } // while 

    return result; 
  } // getGrade 

  public static void main(String[] argv) throws Exception 
  { 
    char grade; 
    while (true) 
    { 
      grade = getGrade(); 
      if (grade == 'X' || grade == 'x') break; 
      if (grade == 'A' || grade == 'B' || grade == 'C') 
        System.out.println("You pass"); 
    } // while 
    System.out.println("Thanks for checking your grades!"); 
  } // main 
} // public class 
