Homework 10

1. SafeIntArray class (5 points)

A student had a good idea and defined a new SafeIntArray class that would throw a descriptive ArrayIndexOutOfBoundsException whenever someone tried to read from a location that did not exist in the array. This new class gives some more information in the error messages generated by the getElementAt method. However, they forgot to apply the idea to the setElementAt method, which allows someone to write a value to particular location in the array.

2. SafeIntArrayTest class (10 points)

The student also defined a test class SafeIntArrayTest to test the functionality of their new SafeIntArray class. Unfortunately, their test program crashes whenever an out of bounds index is entered by the user. Fix this problem in two ways (you should have two separate modified SafeIntArrayTest programs when you are done):