-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuvery
28 lines (25 loc) · 828 Bytes
/
suvery
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Custom Exception Class
class InvalidToVoteException extends Exception {
public InvalidToVoteException(String message) {
super(message);
}
}
// Main Class
public class VoterIDApplication {
// Method to check voting eligibility
public static void checkEligibility(int age) throws InvalidToVoteException {
if (age < 18) {
throw new InvalidToVoteException("Age is below 18. Not eligible to vote.");
} else {
System.out.println("Welcome to Vote!");
}
}
public static void main(String[] args) {
int userAge = 16; // Example age, you can test with other values
try {
checkEligibility(userAge);
} catch (InvalidToVoteException e) {
System.out.println("Exception: " + e.getMessage());
}
}
}