For this assignment you will make two changes to the (linked-list version of the) List class:

  1. Make the List class a public class, and put all of your code into a package called ListPkg, in a subdirectory called ListPkg.

  2. Add a public exception called NoNextElementException, and change the nextElement method so that it throws that exception when it has been called and hasMoreElements is false (i.e., an attempt is made to get the current item from an empty list or from a list in which the current-object "pointer" has fallen off the end of the list).
Write a main function to test the new version of the nextElement method in a (public) class named Test in the parent directory of the ListPkg subdirectory. The main function should include calls that cause the new exception to be thrown, and should include code to catch and handle the exception (e.g., first print a message saying that a bad call is about to be made, then in the catch clause for the exception print a message saying that the exception was thrown and caught). The main function should also include calls to nextElement that do not cause the exception to be thrown.

What to Hand In

Upload your List code and Test.java file.