Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started