Create a main method to demonstrate the jvm throwing

Assignment Help JAVA Programming
Reference no: EM132088480

Create a main method to demonstrate the jvm throwing each of these exceptions. You might have to dig around a bit to 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 not there will cause this one to be thrown.

ClassCastException

IllegalArgumentException

NullPointerException

NumberFormatException

FileNotFoundException

NegativeArraySizeException

These 2 might be tough... do them if you like a challenge.

StackOverflowError

NoClassDefFoundError

Part 3

Demonstrate the use of multiple catch blocks as follows:

there is one line of code below that might throw an ArithmeticException, or an ArrayIndexOutOfBoundsException.

Random r = new Random();

int[] array = {10, 20};

int result = array[r.nextInt(array.length + 1)] / r.nextInt(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:

1. no exceptions,

2. ArrayIndexOutOfBoundsException

3. ArithmeticException

Part 4

Write a method called average() that accepts an array of integers called grades.

If the method does not throw an exception, it will return the average of the grades in the 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 InvalidGradeException 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 Exception 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 that the average method will work for an int array of various sizes, even 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 has invalid grades.

Reference no: EM132088480

Questions Cloud

What are the possible genotypes for this cross : What are the possible genotypes for this cross?
Prepare journal entries to record the purchase of materials : The standard materials price is $2.10 per pound. The actual materials price was $2.00 per pound. Prepare the journal entries to record the purchase of materials
Design an algorithm that switches two arbitrary trucks : Design an algorithm that switches two arbitrary trucks (not necessarily at distance at most k) in O(n/k) truck swaps.
Indicate the phenotype : Dimples (D) is dominant to (d) no dimples. The Widow's peak (W) is dominant to no widow's peak (w). For each genotype, indicate the phenotype.
Create a main method to demonstrate the jvm throwing : Create a main method to demonstrate the jvm throwing each of these exceptions. You might have to dig around a bit to find out what they are.
Compute cost of goods sold expense : Martin Corp. began the year with 2,000 units of inventory that had been purchased for $6 per unit. Compute cost of goods sold expense
Draw a legal binary min heap that stores these keys : Draw a legal binary min heap that stores these keys such that after deleting 8 from the heap, the resulting repair of the binary heap involves.
Create an html web page contains an image : Add a form to your web page from Part 1. The action of the form should be to the formmail.cgi script on the personal web server .
Analyse available purchase methods : MBA404 - Consumer Behaviour and Marketing Psychology - Evaluate alternatives and narrow down the attributes of the FMCG product that satisfy the need or want

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a program to reverse a string using a stack

Write a program to reverse a string using a stack. Please show code in Java. The response must be typed, single spaced.

  Associative memory device

1. How can the associative memory device needed for a TLB be implemented in hardware, and what are the implications of such a design for expandability?

  Create a calorie counter application

Create a calorie counter application. The user should be able to set a daily calorie maximum using preferences. Individual meal entries can be entered for the day and all information will be saved to a local file (Not SQLite)

  Write the definition of a void method

Write the definition of a void method that takes as input two parameters of type int, say sum and testScore. The method updates the value of sum by adding the value of testScore. The new value of sum is sent back to the caller statement

  Prepare a method rearrange that takes a queue

Prepare a method rearrange that takes a queue of integers as a parameter and rearranges the order of the values so that all of the even values appear before the odd values and that otherwise preserves the original order of the list.

  Purchasing type of mobile device

Mobile devices use touch screens to interact with the individual. Select a mobile device and identify three (3) important usability features that are important to you when purchasing this type of mobile device. Provide a rationale for your respons..

  Latin squares - puzzle

Solve button causes the program to display a single solution by using only the symbols from the top row of six text fields in such a way that the non-empty grid symbols are not altered.

  The license plate game and csv parsing

Resulting method will correctly estimate that there are two syllables in quokka and two syllables in springbok, though it does get the number of syllables

  Design the appropriate accessor and mutator methods

Design an Employee class that has fields for the following pieces of information: Employee Name Employee Number Next, design a class named ProductionWorker that extends the Employee class.

  Write a recursive method that converts a decimal integer

Write a recursive method that converts a decimal integer to a binary swing. Write a recursive method that converts a binary string to a decimal integer.

  How to count number of objects (instances) created

How to count number of objects (instances) Created, use java code and please be descriptive

  Create an application that calculates figures for business

The remainder goes to the movie company. Create an application that calculates and displays following figures for one night's box office business at a theater.

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