Write code to prompt the user to enter a number


Homework

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.

Format your homework according to the give formatting requirements:

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

b. 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.

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

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: Write code to prompt the user to enter a number
Reference No:- TGS03118174

Expected delivery within 24 Hours