**THIS IS AN IN CLASS EXCERCISE AND WILL NOT DIRECTLY AFFECT YOUR GRADE**

* Your solutions will be evaluated by the TAs to judge your knowledge of the material so please write neatly and keep your solution organized.

Problem #1: Trace through the code below and identify which exceptions will occur. Also, propose solutions to all exceptions that could occur. Identify and correct exceptions in the order they occur.

Problem #2: Return to the original code example. Instead of correcting the code to not allow the exceptions to occur, catch the specific exceptions that will occur. Handle the exceptions to allow the code to continue (adding loops if necessary) and so that the program will end cleanly.

Problem #3: Instead of handling an exception when it is caught, re-throw the exception to the method's calling location. Recall that first you will need to claim the exception you will throw. If you do not claim any exceptions, yet you throw/re-throw an exception, state in detail why this is possible.

Problem #4: Create the class RationalNumber. The class will have properties num and den for the numerator and the denominator. Provide methods for adding, subtracting, multiplying, and dividing two rational numbers. Each method will receive a rational number and return the rational number result. If an irrational number is identified, generate a NumberFormatException (claim and throw this exception).

Problem #5: Create the class IrrationalNumberException. Define what properties and methods you will use in the class and create them. Modify your class RationalNumber to generate an IrrationalNumberException where appropriate.

Code used in Problems #1, #2, & #3:

class TestingExceptions {
  public static void main(String args[]) {
    method1();
    method2();
    method3();
  }

  public static void method1() {
    int number = 5;
    char ch = 'e';
    double decimal = 7.42;
    String s = new String("Test");

    //  number = decimal;
    //  ch = number;
    //  s = ch;
    //
    //  Note the code above is commented so the program will compile,
    //  the exception that would have occurred here does not because
    //  the compiler helps us out.

    System.out.print("Enter a number:  ");
    number = UserInput.readInt();

    System.out.print("Enter a String:  ");
    s = UserInput.readString();
  }
  public static void method2() {
    Circle c[] = new Circle[10];
    int k = 0;

    for(k = 2; k < 7; k++) {
      c[k] = new Circle(k);
    }
    for(k = 0; k < 10; k++) {
      c[k].calculateArea();
    }
  }
  public static void method3() {
    Circle c[] = new Circle[3];
    int k = 0;

    for(k = 0; k < 7; k++) {
      c[k] = new Circle(k);
    }
    for(k = 0; k < 7; k++) {
      c[k].calculateArea();
    }
  }
}

class Circle {
  public double radius;

  public Circle(double r) {
    radius = r;
  }
  public double calculateArea() {
    return radius * radius * Math.PI;
  }
}