Assignment Description Assignment Details For this project, you will write


 

Assignment Description

Assignment Details

For this project, you will write a Java program that demonstrates exception handling. To facilitate this, you will need to collect input from a user, perform calculations, and send output to the screen. Exception handling will catch any input and calculation errors that may arise. For this project you will need the following variables (all integers): Three to store the input from the user, one to store the sum, and one to store the total. Remember to set their initial values to zero.

Create a new Java project. Write code to prompt the user to enter a number, then repeat this for a second number and a third. As each number is entered, store it in a variable. In each case, use an Input Mismatch Exception handler to catch when the user enters a letter instead of a number. Use the Catch block to inform the user that they should only enter numbers.

When all three numbers have been stored in variables, add the three numbers (their variables) together and store the sum in another variable.

Next, calculate a total that equals the sum of the three variables divided by the third input variable. (Put another way, divide the sum of the numbers by the third number that the user entered.) Use an Arithmetic Exception to handle situations where the third number that was entered by the user was a zero, informing the user that the program has produced a “Divide by zero error.”

Document your code thoroughly with code comments and be sure to explain how each exception works and what it is doing.

Tip: No custom classes, loops, or IF/ELSE statements are needed for this assignment.
Tip: Remember to initialize your variables!

Looking for a Similar Assignment? Our Writers can help. Use the coupon code SAVE15 to get your first order at 15% off!