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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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