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.
Step by Step Answer:
Introduction To Programming With Java A Problem Solving Approach
ISBN: 9781260575248
3rd International Edition
Authors: John Dean