Program Description:
For this project, you will write a Java program that demonstrates exception handling. Your program will accept from the user ten numbers and place them in an array. The numbers in the array will be added together and the result displayed to the user. The program will compare the values for the first two elements in the array (only) and determine which number is larger and report that information on screen. Then divide the larger number by the smaller number and report the result of that calculation. The program must use exception handling to avoid division by zero errors or out of range errors, then present a friendly error message to the user. The program must then repeat (loop), prompting the user for new data entry. When the user enters 9999, the program must terminate on the next loop cycle, and this must be indicated in the program text (Enter 9999 to exit.)
Project Steps:
- Create a new project named “ExceptionHandler.” (Custom classes are not needed.)
- Write code to accept numbers entered by the user.
- Use error handling to ensure that only numbers are accepted.
- Write code to add all values in the array together and display the result to the user.
- Write code to compare the first two values in the array and report the results
- Write code to divide the larger number by the smaller number from the above comparison
- Use error handling to ensure that the program doesnt crash if it attempts to divide a number by zero.
- Prompt the user for another set of ten numbers.
- If the user entered 9999 during data entry in the last loop cycle, terminate the program.
- Use exception handling to manage out of range exceptions (only numbers are entered)
- Use exception handling to manage division by zero exceptions (as noted)
- Use exception handling to manage by default any errors that dont fall into the above categories.
- Using Catch blocks, display the cause of any exceptions to the user.
- Output instructions to the screen so that the user will know how to operate the program and what to expect.
- Use code comments to annotate your code, indicating what each line of code does as well as how it works.
- Make sure the program runs correctly before submission. (Your instructor is here to help!)
- Create an activity diagram that illustrates how your program works. Your diagram must include all the data items in your program.
- Formal UML is not required but may be used if preferred. (You may use any software for this, but it must be submitted in Microsoft Word.)
- ZIP your project folder and submit that and your Word document (containing the activity diagram) to the portal for grading.
This assignment will also be assessed using additional criteria provided (see attachment).