So I am working on a Java program that continually ask the user for double values. I am supposed to use a sentinel-controlled loop with sentinel value of -999. I need to use an ArrayList while using try/catch block to handle inputMismatchExceptions, ArrayStoreExeptions, and general Exceptions.
I am currently having trouble trying to finish the program after entering -999, applying message of a duplicate message from ArrayStoreExceptions and to continue input after inputMismatchExceptions.
public static void main(String[] args) {
double d;
double average;
double max;
double min;
ArrayList<Double> value = new ArrayList<Double>();
Scanner input = new Scanner(System.in);
System.out.println("Enter a double value (-999 to exit):");
d = input.nextDouble();
while (!value.equals(-999)) {
try {
System.out.println("Enter a double value (-999 to exit):");
value.add(input.nextDouble());
} catch (InputMismatchException e) {
System.out.println("That is not a valid double value.");
} catch (ArrayStoreException e) {
System.out.println("Duplicate value");
} catch (Exception e) {
System.out.println("Error");
}
}
}