Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please i need some help with my programing assigment in Java Create a main method to demonstrate the jvm throwing each of these exceptions. You

Please i need some help with my programing assigment in Java

image text in transcribed

Create a main method to demonstrate the jvm throwing each of these exceptions. You might have to dig around a bi o find out what they are and who (what methods) throw them. Note that you are not going to create an Exception of this type and throw it, you will write a snippet of code that causes one to be thrown. ArrayIndexOutOfBoundsException = eg. Create an array and access an element that is one to be is not there will cause this one to be thrown. ClassCastException IllegalArgumentException NullPointerException NumberFormatException File Not FoundException NegativeArraySizeException These 2 might be tough... do them if you like a challenge. StackOverflowError NoClass Def ound Error Demonstrate the use of multiple catch blocks as follows: there is one line of code below that might throw an ArithmeticException, or ArrayIndexOutOfBoundsException. Random r = new Random (); int [] array = {10, 20}; int result = array {r.netInt{array. length +1}]/r.netInt(2); Explain why each of these might happen Put this code in a try block that can distinguish between which one has been thrown (2 catch blocks). Run the code until you have demonstrated all 3 possibilities: no exceptions, Array IndexoutOfBoundsExceptional ArithmeticException Write a method called average() that accepts an array of integers called grades. If the method does not throw an exccption. it will return the average of the grades array. Start by implementing that. The method will throw an exception of type InvalidGradeException.if any element of the array is greater than 100 or less than 0 You must create the InvalidGradeException class. The InyalidGradeException object should contain information about what went wrong i.e., which of the grades was invalid (its index), and what the invalid value was. The exception will be caught by the caller (the main method) and print out the information contained in the InvalidGradeException object. You are demonstrating that you can pass information from a method back to the caller, by putting it in an Except on object and throwing it. The average () method will change all the grades in the array to 60 that are less than 60 after the average is calculated. This will also be done if an exception is thrown, and the average is not calculated. This will be done in a finally block INSIDE the average method. Demonstrate at the average method will work for a int array of various sizes, given though the method has only one parameter. Demonstrate that your method will work with an array that has no invalid grades, AND with an array that valid grades

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions

Question

Define capital structure.

Answered: 1 week ago

Question

List out some inventory management techniques.

Answered: 1 week ago

Question

=+Have they changed the way employees view IP?

Answered: 1 week ago