Write code to accept numbers entered by the user


Homework: 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:

o Create a new project named "ExceptionHandler." (Custom classes are not needed.)
o Write code to accept numbers entered by the user.
o Use error handling to ensure that only numbers are accepted.
o Write code to add all values in the array together and display the result to the user.
o Write code to compare the first two values in the array and report the results
o Write code to divide the larger number by the smaller number from the above comparison
o Use error handling to ensure that the program doesn't crash if it attempts to divide a number by zero.
o Prompt the user for another set of ten numbers.
o If the user entered 9999 during data entry in the last loop cycle, terminate the program.
o Use exception handling to manage out of range exceptions (only numbers are entered)
o Use exception handling to manage division by zero exceptions (as noted)
o Use exception handling to manage by default any errors that don't fall into the above categories.
o Using Catch blocks, display the cause of any exceptions to the user.
o Output instructions to the screen so that the user will know how to operate the program and what to expect.
o Use code comments to annotate your code, indicating what each line of code does as well as how it works.
o Make sure the program runs correctly before submission. (Your instructor is here to help!)
o Create an activity diagram that illustrates how your program works. Your diagram must include all the data items in your program.

Format your homework according to the give formatting requirements:

1. The answer must be double spaced, typed, using Times New Roman font (size 12), with one-inch margins on all sides.

2. The response also includes a cover page containing the title of the homework, the course title, the student's name, and the date. The cover page is not included in the required page length.

3. Also include a reference page. The references and Citations should follow APA format. The reference page is not included in the required page length.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Write code to accept numbers entered by the user
Reference No:- TGS03033138

Now Priced at $70 (50% Discount)

Recommended (96%)

Rated (4.8/5)