COMP2247 - Algorithms and Data Structures

Syllabus Software Installation Assignments Tests
Lectures and Labs
**Back to Full Menu**

Exception Handling Practice1.java QuadraticEquation.java YouthLeague.java HandleTimeException Program
InvalidHourException.java
InvalidMinuteException.java
InvalidSecondException.java
HandleTimeException.java
HardwareStore Programs



YouthLeague Program


Description

This program inputs an integer: age (12 to 18), for joining a youth league, then uses exception handling techniques to handle exceptions.

Associated Concepts:

Exception Handling

Algorithm:

main method:

Input an integer: age, for joining a youth league.

If the user entered an invalid integer, the try block terminates immediately, and the program execution jumps to the matching catch block to handle the InputMismatchException.

If the user input is less than 0, the program throws an exception of the superclass Exception object with "N" as the argument.

If the user input is less than 12, the program throws an exception of the superclass Exception object with "Y" as the argument.

If the user input is greater than 18, the program throws an exception of the superclass Exception object with "O" as the argument.

The program prints a message to indicate that the person is qualified to join the youth league if no exception occurred.

Source Code



Sample Run



Video