import java.util.Arrays;
public class ArgumentWrapper {
private static final int MAX_VALUE_1 = 100;
private static final int MIN_VALUE_1 = 0;
private static final int MAX_VALUE_2 = 50;
private static final int MIN_VALUE_2 = -10;
public static int processArgument(String[] args) {
// Process the first argument
int arg1 = -1;
if (args.length > 0) {
try {
arg1 = Integer.parseInt(args[0]);
if (arg1 < MIN_VALUE_1 || arg1 > MAX_VALUE_1) {
System.err.println("Error: Argument 1 out of range. Must be between " + MIN_VALUE_1 + " and " + MAX_VALUE_1);
return -1; // Indicate an error
}
} catch (NumberFormatException e) {
System.err.println("Error: Argument 1 must be an integer.");
return -1; // Indicate an error
}
}
// Process the second argument
int arg2 = -1;
if (args.length > 1) {
try {
arg2 = Integer.parseInt(args[1]);
if (arg2 < MIN_VALUE_2 || arg2 > MAX_VALUE_2) {
System.err.println("Error: Argument 2 out of range. Must be between " + MIN_VALUE_2 + " and " + MAX_VALUE_2);
return -1; // Indicate an error
}
} catch (NumberFormatException e) {
System.err.println("Error: Argument 2 must be an integer.");
return -1; // Indicate an error
}
}
// Combine or use the processed arguments (example: sum them)
if (arg1 != -1 && arg2 != -1) {
return arg1 + arg2;
} else if (arg1 != -1) {
return arg1;
} else if (arg2 != -1) {
return arg2;
}
else {
return 0; // Default value if no arguments provided
}
}
public static void main(String[] args) {
// Example Usage
int result = processArgument(args);
System.out.println("Result: " + result);
}
}
Add your comment