import java.util.Scanner; // -------- User-defined exception: TooOlder -------- class TooOlder extends Exception { public TooOlder(String message) { super(message); } } // -------- User-defined exception: TooYounger -------- class TooYounger extends Exception { public TooYounger(String message) { super(message); } } // -------- Employee class -------- class Employee { String name; int age; Employee(String name, int age) { this.name = name; this.age = age; } // Method to validate age eligibility void validateAge() throws TooOlder, TooYounger { if (age > 45) { throw new TooOlder("Candidate is too old for recruitment"); } else if (age < 18) { throw new TooYounger("Candidate is too young for recruitment"); } else { System.out.println("Eligible"); System.out.println("Candidate Name: " + name); } } } // -------- Main class -------- public class EmployeeRecruitment { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter Candidate Name: "); String name = sc.nextLine(); System.out.print("Enter Candidate Age: "); int age = sc.nextInt(); Employee emp = new Employee(name, age); try { emp.validateAge(); } catch (TooOlder e) { System.out.println("Exception: " + e.getMessage()); } catch (TooYounger e) { System.out.println("Exception: " + e.getMessage()); } sc.close(); } }