Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
895 B
4
Indexable
public class VotingEligibilityApp {
    public static void main(String[] args) {
        VotingEligibilityChecker checker = new VotingEligibilityChecker();
        int age = 16; // Change the age to test eligibility

        try {
            checker.checkAge(age);
        } catch (NotEligibleForVotingException e) {
            System.out.println("Exception: " + e.getMessage());
        }
    }
}
class VotingEligibilityChecker {
    public void checkAge(int age) throws NotEligibleForVotingException {
        if (age < 18) {
            throw new NotEligibleForVotingException("You are not eligible for voting as you are under 18 years old.");
        } else {
            System.out.println("You are eligible for voting.");
        }
    }
}
class NotEligibleForVotingException extends Exception {
    public NotEligibleForVotingException(String message) {
        super(message);
    }
}