-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorkingHoursException.java
More file actions
38 lines (33 loc) · 1.36 KB
/
WorkingHoursException.java
File metadata and controls
38 lines (33 loc) · 1.36 KB
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
29
30
31
32
33
34
35
36
37
38
// Custom exception class
class ExcessiveWorkingHoursException extends Exception {
public ExcessiveWorkingHoursException(String message) {
super(message);
}
}
public class WorkingHoursValidator {
// Method to validate working hours
public static void validateWorkingHours(int hours) throws ExcessiveWorkingHoursException {
if (hours > 8) {
throw new ExcessiveWorkingHoursException("Excessive working hours: " + hours + " hours. Maximum allowed is 8 hours.");
} else {
System.out.println("Working hours are within the acceptable range: " + hours + " hours.");
}
}
public static void main(String[] args) {
// Check if an argument is passed (working hours)
if (args.length == 0) {
System.out.println("Please provide working hours as a command-line argument.");
return;
}
try {
// Parse the working hours from command-line argument
int workingHours = Integer.parseInt(args[0]);
// Validate the working hours
validateWorkingHours(workingHours);
} catch (NumberFormatException e) {
System.out.println("Invalid input! Please enter a valid number for working hours.");
} catch (ExcessiveWorkingHoursException e) {
System.out.println(e.getMessage());
}
}
}