Question: Problem 2 (throws and throw) Complete the program below in order to make run properly by adding try-catch blocks in the main method public class

 Problem 2 (throws and throw) Complete the program below in order

to make run properly by adding try-catch blocks in the main method

Problem 2 (throws and throw) Complete the program below in order to make run properly by adding try-catch blocks in the main method public class Exceptionwi thThrow public static Scanner openFile (String fileNae throws FileNotFoundExceptioni FileRe ader frnew FileReader (fileName) ; Scanner sc-new Scanner (fr) return sc: public static boolean isValidIdentifier (String name) // check here if the name is a valid identifier name public static String readValidIdentifierName( throws InputMi smatchException Scanner input- new Scanner (System.in) String name- input .next } ; if isValidIdentifier) throw new InputMismatchException ) return name: public static int readInteger throws InputMismatchException Scanner input-ne Scanner (System.in) int numinput.nextinto return num public static boolean isDivisible (int x, int y) throws ArithmeticException if (y-0) if (x % y0) else throw new ArithmeticException) return true return false public static void main (String) args) // Add try and catch blocks around appropriate statements /I Two exceptions are expected here System.out println("Please enter the input file name:") String Name-readValidI dentifierName O Scanne r fsc- openFile(fName); // One exception is expected here System.out println("Please give me an integer number") int firstNum-readInteger System.out println("Please give me another integer number" int secondNum- readInteger ) // One exception is expected here if sDivi sible (firstNun, se condNum } }{ System.out.printin (first Numis divisible bysecondNum) else System.out.printin (firstNum "is NOT diviile by"secondNum) Note A valid identifier name 1. can have letters (A. .Z, a. .z) 2. Can have digits (0..9) 3. Can have or 4. Can not have any other special characters 5. Can not start with a digit 6. Can not be a reserved word

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!