In this situation, well use exception handling for input validation, which in turn, helps to ensure that were writing more robust and more fault-tolerant programs.

Ok, so the idea here is that were attempting to write a program that allows a user to input integer values into a 10-element array and, in addition, will also allow the searching of the array. This program should allow the user to retrieve values from the array by index or by specifying a value to locate. The program should handle any exceptions that might arise when inputting values or accessing array elements. The program should throw a NumberNotFoundException if a particular value cannot be found in the array during a search. If an attempt is made to access an element outside the array bounds, catch the ArrayIndexOutOfBoundsException and display an appropriate error message. Also, the program should throw an Array-IndexOutOfBoundsException if an attempt is made to access an element for which the user has not yet input a value.

Using the helpful hints as a guide, replace the /* */ comments with Java code. Compile and execute the program. Compare your output with the sample output provided.

Acceptance Criteria: 1. Output is reflective of the sample output provided.

Helpful Hints:

  • When you search the array for a value, you should define a boolean value at the beginning of the try block and initialize it to false. If the value is found in the array, set the boolean value to true. This will help you determine whether you need to throw an exception due to a search key that is not found.
  • Refer to the sample output to decide what messages to display in the error dialogs.
  • Each of the three event handlers will have its own try statement.

Sample output: See image.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.