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

Assume we have a method that check a student GPA and if GPA is below 2.0 it will

ID: 3733522 • Letter: A

Question

Assume we have a method that check a student GPA and if GPA is below 2.0 it will throw an exception that will be handled by a custom exception handler. Your job is to write a custom exception that handles the case when a student GPA is less than 2.0 which indicates that he cannot graduate from the collage.

Write custom exception handler class

Complete method checkGPA. Exception message should be “student cannot graduate”

Write the main class. Instantiate two objects to test your code.   One to test gpa<2.0 and another one to test gpa >= 2.0

Submit your code and output.

Explanation / Answer

Hi friend, you have not mentioned about language and main program.

I have implemented in Java.

class InvalidGPA extends Exception {

  

   private String msg;

   public InvalidGPA(String msg) {

       this.msg = msg;

   }

  

   public String getMessage() {

       return msg;

   }

}

#########

public boolean checkGPA(double gpa) throws InvalidGPA {

      

       if(gpa < 2) {

           throw new InvalidGPA("student cannot graduate");

       }

      

       return true;

   }