Print Array – Generic Methods

Overloaded generic print array

Assignment Content Learning Objective: Practice with the use of generic methods. Practice creating custom exceptions. Ability to overload a generic method. Practice with arrays. Using the example code for the generic Print Array provided below, modify the code to overload the generic method of Print Array twice for each of the following: take two additional integer arguments, low and high, entered by the user. When you call the method with these arguments, it prints out only the portion of the array that is between the two subscripts. Your program needs to validate that the low and high are within the range of the array bounds. If either is out of range, then the overloaded method should throw a custom exception for Invalid Subscript Exception.

The exception should be caught by the main program and an error message to the user should notify them of the issue and allow them to enter a correct value. If no exception is thrown, then print Array should return the number of elements printed. Create the custom exception Invalid Subscript Exception with the following method header; “public class Invalid Subscript Exception extends Runtime Exception”. They should include a String message parameter as part of an overloaded constructor for the custom exception object. Overload the generic Print Array with a non-generic version of the method that specifically prints an array of Strings. You can make up your own names to use in the array) in neat, tabular format as shown below

: The following names are in the array; Tom Abdul Han Mark Sara Hamilton Anna Tatiana You will need to modify the main program to exercise all versions of the overloaded method.

Further Description

For the addition of two integer arguments, you need to exercise both versions of print Array on all three types (integer, double, and character). For the non-generic version, you need to show the ability to exercise the method and print out the nicely formatted string array content. Make sure to submit your java code file(s) and your execution screenshots. Don’t forget to include a program header with your name, section, assignment title, and a description of the program. The execution screenshots are required for credit. Make sure to submit your own original code. Safe Assign has been enabled to verify originality of code.

Attached Files


Powered by WordPress and MagTheme