Question: Correcting Problems: Fix the problems in the NumberList program without making any changes to the NumberListDriver class. a) Avoid the possibility of an ArrayIndexOutOfBoundsException by

Correcting Problems:

Fix the problems in the NumberList program without making any changes to the NumberListDriver class.

a) Avoid the possibility of an ArrayIndexOutOfBoundsException by adding to the while condition, size

b) If the entry is not a “q” and if it is not a legal integer, catch the exception, and in the catch block use the getClass method inherited from the Object class to print the name of the exception class followed by the error message with the statement:

System.out.println(e.getClass() + " " + e.getMessage());

c) If a user immediately enters “q” to quit, print “NaN” by making a small program correction that utilizes double’s NaN value, and avoids using the try-catch mechanism to catch the int arithmetic exception.

Sample session: Enter a whole number (q to quit): q Mean NaN =

Sample session: Enter a whole number (q to quit): q Mean NaN =

Step by Step Solution

3.38 Rating (145 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The instructions provided indicate corrections that need to be made to a NumberList program As background for others who may read this a NumberList pr... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Introduction To Programming With Java A Problem Solving Approach Questions!