Question: 1) The checkage() method below prints an error message to signal an error. Define an exception illegalAgeException and re-write the code below to use exceptions

 1) The checkage() method below prints an error message to signal

1) The checkage() method below prints an error message to signal an error. Define an exception illegalAgeException and re-write the code below to use exceptions instead of using error messages. Your code should try to recover from the exception in the main. import java.util.Scanner; int age public class ExceptionDemo { public static void main(String[] args) { //Reading user input Scanner sc = new Scanner (System.in); System.out.print("Please enter your age: "); sc.nextInt (); checkAge (age); } private static void checkAge (int age) { if (age>18){ System.out.println("You are authorized to view the page"); //other business logic } else System.out.println("You are not authorized to view page"); } }

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!