Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Databases A Tour

Authors: Shashi Shekhar, Sanjay Chawla

1st Edition

0130174807, 978-0130174802

More Books

Students also viewed these Databases questions

Question

Explain the different types of marketing strategies.

Answered: 1 week ago

Question

Explain product positioning.

Answered: 1 week ago

Question

Explain Industrial market segment.

Answered: 1 week ago