Computer Science 1260 – Classwork 6
October 5, 2018 / Exception Handling / Due: ______

Purpose

The purpose of this exercise is to gain experience with exception handling including the use of the try-catchmechanism. The context of the exercise is the calculation of a grade point average based on the number of credits earned and the number of credit hours completed. All .java files should be in the gpaCalculator package.

Specifications

AGPACalculator class that computes a GPA based on a number of credits earned and the number of credit hours completed is provided. It checks for several types of input errors and throws exceptions with appropriate error messages in them. A GPAException class is also provided. Spend some time studying and understanding the GPACalculator class and review the methods provided by the GPAException class before you start writing the driver.

Make no changes to either of these provided classes. Use them as they are.

You should create a driverclass that handles all input and output including the error messages. Where exceptional conditions are detected by the GPACalculator class and exceptions are thrown, display the error messages those exception objects contain rather than hard-coding your own messages.

Use the exceptionhandlingmechanism to deal with all problematic situations including, but not limited to the following:

  • Dividing by 0
  • Negative values for either hours or credits or both
  • A combination of hours and credits that results in an invalid GPA (i.e., a GPA not between 0.00 and 4.00)
  • Invalid input (hours or credits not an integer)

The GPACalculator class provided detects all exceptional conditions other than invalid numeric input and throws appropriate exceptions.

The driverclass should do all I/Oincluding error messages. The driverclass must catch all exceptions in this exercise. The GPA should always have exactly two digits after the decimal and one digit before the decimal.

At least twodifferentexceptiontypesmight be thrown in this exercise. The GPAException class is provided and it represents one type of exception thrown byGPACalculator.

At the end of this document, there is a sample of output produced by a solution to this exercise. Your output should be similar if the same input is provided.

Submission

Submit a zippedfile containing your .Java files only for this exercise (include GPACalculator.java and GPAException.java with your driver file). Name the submission CW6 – ExceptionHandling plus your course, section, and name as specified in the Course Factson the courseweb site. This must be submitted by the end of class today.

Example Output from One Solution

Exception Handling ClassworkPage 1