Chat with us, powered by LiveChat Top of Form Learning Objective: Practice with the use of generic methods. - Writeedu

Top of Form Learning Objective: Practice with the use of generic methods.

Assignment Content




Top of Form


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 PrintArray provided below, modify the code to overload the generic method of PrintArray 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 PrintArray method should throw a custom exception for InvalidSubscriptException. 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 printArray should return the number of elements printed.


· Create the custom exception InvalidSubscriptException with the following method header; “public class InvalidSubscriptException extends RuntimeException” and should include a String message parameter as part of an overloaded constructor for the custom exception object.


· Overload the generic PrintArray 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. For the addition of two integer arguments, you need to exercise both versions of printArray on all three array 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. SafeAssign has been enabled to verify originality of code.


// Using generic methods to print array of different types.


public class GenericMethodTest 




  // generic method printArray


  public static < E > void printArray( E[] inputArray )




   // display array elements


   for ( E element : inputArray )


     System.out.printf( “%s “, element );




  } // end method printArray


  public static void main( String args[] ) 




   // create arrays of Integer, Double and Character


   Integer[] integerArray = { 1, 2, 3, 4, 5, 6 , 7, 8, 9, 10};


   Double[] doubleArray = { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7 , 8.8, 9.9, 10.1};


   Character[] characterArray = { ‘I’, ‘S’, ‘2’, ‘4’, ‘7’ ,’ ‘ , ‘i’, ‘s’, ‘ ‘ , ‘f’, ‘u’, ‘n’};


   System.out.println( “Array integers:” );


   printArray( integerArray ); // pass an Integer array 


   System.out.println( “nArray doubles:” );


   printArray( doubleArray ); // pass a Double array


   System.out.println( “nArray characters:” );


   printArray( characterArray ); // pass a Character array


  } // end main


} // end class GenericMethodTest

Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteEdu. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.

Do you need an answer to this or any other questions?

Do you need help with this question?

Get assignment help from Paper Writing Website and forget about your problems.

WriteEdu provides custom & cheap essay writing 100% original, plagiarism free essays, assignments & dissertations.

With an exceptional team of professional academic experts in a wide range of subjects, we can guarantee you an unrivaled quality of custom-written papers.

Chat with us today! We are always waiting to answer all your questions.

Click here to Place your Order Now