Write a java program that demonstrates exception handling

Assignment Help JAVA Programming
Reference no: EM13811942

Errors occur in programs, and there are two ways to address the problems. The first is to try to write code that checks for errors and then deals with them. For example, you can use error checking to see if a user selected a valid menu option after making a selection. Error checking tries to prevent errors from occurring. Another method is to go ahead and let errors occur but to handle them gracefully before they can affect the operation of the program. This method, called exception handling, will be the focus of this project.

For this project, you will write a Java program that demonstrates exception handling. Your program will accept from the user ten values and place those numbers in an array. The numbers in the array will be added together and the result displayed to the user. The program will also perform division. The program should compare the values for elements 1 and 2 in the array and divide the larger number by the smaller number. It should compare the values for all odd/even elements and divide the larger by the smaller value. The program should use exception handling to avoid division by zero errors or out of range errors (dictated by the variable's data type) which would cause the program to stop due to the error. The program should prompt the user for a second set of ten numbers. When the user enters 9999 the program should terminate normally.

For this project, do the following:

  • Create a new project in your IDE named "ExceptionHandler."
  • Write code to accept numbers as described above from the user. Your code should ensure that only numbers are accepted.
  • Write code to add all values together and to divide larger numbers by smaller numbers in odd/even elements. Results should be displayed. Loop to get another set of ten numbers from the user until the user enters 9999 as the first number.
  • Use exception handling to handle division by zero and out of range exceptions.
  • In the catch blocks, be sure to display the cause of the exception to the user.
  • Make sure your exception handler will handle any other errors as a default.
  • Create a UML activity diagram that illustrates how your program works. Your diagram must include all the data items in your program.
  • Use good comments to describe how the program works.
  • Make sure the program runs correctly before submission.

Reference no: EM13811942

Questions Cloud

What is bureaucracy : Discuss the role of modern interest groups in politics. When are these groups most effective. What is bureaucracy. Discuss purpose and problems.
Question regarding the whistle-blower definition and statute : After having reviewed the whistle-blower definition and statute, would you agree that despite having the whistle-blower statute in place, some employees are still apprehensive about coming forward with complaints? Please explain.
What is leadership style : What is Leadership Style? What type do you have and does it need changing? Can we change? When we read or talk about leadership style, it is the pattern of behavior used by a leader in attempting to influence (motivate) group members and make deci..
Explain provision protect the employer from civil lawsuits : How is the employer liable for workplace violence. Define the exclusivity provision, and analyze how this provision helps protect the employer from civil lawsuits that are associated with workplace violence
Write a java program that demonstrates exception handling : For this project, you will write a Java program that demonstrates exception handling. Your program will accept from the user ten values and place those numbers in an array
Write a research paper about teenager abusing drugs : Write a research paper about Teenager Abusing Drugs.
What could the team have done differently : How has scope creep affected a project on which you have worked? What could the team have done differently?
Create an application that manipulates a billboard sign : Create an application that manipulates a billboard sign based on the above guidelines. Use comments in your code to demonstrate your understanding of each statement
Java gui program to calculate monthly payment : Java GUI program to calculate monthly payment. The GUI has JTextFields and JButton

Reviews

Write a Review

JAVA Programming Questions & Answers

  Create an array of date objects

Create an array of Date objects of size 4. Initialize the array by using a loop. In the loop, use the Scanner.nextLine() method to input a date as a string, convert it to a date by using the toDate() method, and assign the result to an element in ..

  Write a on the popularity of java

Write a 4-5-page research-oriented paper in APA format that focuses on the "Popularity of Java". The paper must cite at least 5 references, not including the textbook or the Bible.

  Return only the rows where the shipdate

Write a SELECT statement that returns these columns from the Orders table:

  Http://www.homeworkmarket.com/content/need-help-java-program

Write a Java application program that takes in user input from keyboard and calculate semester grade based on the scores. In this assignment, you are going to rewrite the program, instead of taking keyboard input, you will use dialog box to prompt..

  Java class library with thousands of predefined classes

The Java Application Programming Interface is a Java class library with thousands of predefined classes

  Statistics list program

You will also modify your program to accept input from an input file and print a report to an output file. These files are to be named by the user at runtime.

  On any given execution your program

On any given execution your program will produce just one version of the figure. However, you should refer to the class constant throughout your code, so that by simply changing your constant's value and recompiling, your program would produce a f..

  Create a class named employee and its subclasses

Create a class named Employee and its 3 subclasses named Contractor, HourlyEmployee, FullTimeEmployee. The class Employee hold first name and last name information, and defines two methods, respectively computing pay and vacation hours, that needs..

  Generates a random number between 1 and 100

Write a program that generates a random number between 1 and 100 (inclusive) and then prompts the user to guess the number. The user should be given up to 10 chances to guess the number.

  Example of overloading

Implement in different classes and that have the same number and type of parameters - Inheritance models the IS-A relationship, in which the objects of the subclass are also objects of the superclass - Different classes and that have the same number ..

  Convert the while loop in the following code segment

Convert the while loop in the following code segment to a do-while loop

  Need a console program

Need a console program that repeatedly prompts the user to enter data until they type done (any case, Upper, Lower, or Mixed).

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd