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

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 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 =

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: