Complete the following Java program by typing in the missing statements in the space provided. This program inputs a value/s from user, and displays the result of some operation. If the operation...



Complete the following Java program
 by typing in the missing statements in the space provided. This program inputs a value/s from user, and displays the result of some operation. If the operation generated an exception / error,  it is handled by the user defined exception class. The main method in the application class is declared to throw a user-defined exception which will take care of the exception.









import   //  for input from keyboard


public class MyExceptionApp  {


   public static void main(  ) throwsMyDivByZeroException  {



       Scanner kb =


       System.out.println("Enter two numbers for division :  ");


       double n1 = kb.nextDouble();


       double n2 = kb.nextDouble();



       try{


            if( n2 == 0 )


throw


            else


                System.out.println("Answer = " + n1/n2);


       }


       catch (   e){


               System.out.println("Exception caught : "  + e);


       }


       System.out.println("Program terminated normally ... ");


   }


}


// definition of MyDivByZeroException  class


class MyDivByZeroException  {


     {   // default constructor is required


    }


     {    // a constructor with String argument is also required


        System.out.println(msg);


   }


}




Jun 05, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here