Question: Tasks Sooner or later, every Java programmer should work through the official Java Generics tutoria https : //docs. oracle . com/javase/tutorial/java/generics/index. html/ for an introduction


Tasks Sooner or later, every Java programmer should work through the official Java Generics tutoria https : //docs. oracle . com/javase/tutorial/java/generics/index. html/ for an introduction to Java Generics. You are strongly encouraged to do so on your own time. It will help a lot. What you will find is that most of the textbooks and tutorials you read are derrived from this tutorial. However, there is no hand in associated with this recommendation. Consider the following code snippet, where the printArray () method is used to print out arrays of different types: Integer intArry = {1, 2, 3, 4, 5 ); Double doubarry = {1.1, 2.2, 3.3, 4.4 ); Character charArray = { 'H' , 'E' , 'L' , 'L', '0' ); String strArray = {"once", "upon", "a", ,"time" }; printArray (intArry) ; printArray (doubarry) ; printArray (charArray) ; printArray (strArray) ; 1. Write a Java program with a main method that includes the example code above. Implement the static printArray () method using an array of Objects for the parameter. Compile and run your code. Lab #1 (Generics) Page 1 / 3 2. Comment out, but do not delete, the previous implementation of the printArray () method and im- plement print Array () method using method overloading. Write four versions of printArray () one for each appropriate array type. Compile and run your code. 3. Comment out, but do not delete, the previous implementations of print Array () . Now write a single method that uses the Generic programming technique so that you have a single method supporting all the types and maintain type safety.types and maintain type safely. 4. Using non-generic techniques, write a method get Max ( ) that takes an array of type Comparable and returns the maximum element in the array [ie. "public static Comparable getMax (Comparable anArray) "}. Add the following code to your main routine: System . out . printIn( "max Integer is: " + getMax(intArry) ; System . out . printIn( "max Double is: " + getMax (doubarry) ; System . out . printIn( "max Character is: " + getMax(charArry) ; System . out . printIn( "max String is: " + getMax (strArry) ; Compile your code. Copy and paste any compiler warnings you get into a comment block at the head of your implementation of getMax () . Run your code. 5. Comment out, but do not delete, your previous implementation of get Max ( ) . Using the generic tech- niques to specify super-class relationships, implement a type safe version of get Max ( ) . 6. For solving the same problem, now, you need to use Function interface. (Something really cool... but only availble in Java 8) Create a functional interface (java . util . Function) findMax that takes a Character array as in- put and returns the maximum Character. You can refer https : / /www . javabrahman . com/java- 8/ java- 8- java-util-function-function-tutorial-with- examples/ for an introduction to Java Functional Interface. Submission I Hand in the source code from this lab at the appropriate location on the Blackboard system at learn . rochester. edu. You should hand in a single zip (compressed archive) Labi . zip containing your source code, README, and OUTPUT files, as described below. 1. A plain text file named README that includes your contact information, your partner's name, a brief explanation of the lab (a one paragraph synopsis. Include information identifying what class and lab number your files represent.), and one sentence explaining the contents of any other files you hand in. 2. A single Java source code file representing the work accomplished for sections 1-5 of this lab. All source code files should contain author and partner identification in the comments at the top of the file. 3. Java source code files (you may decide how many you need) representing the work accomplished in section 6 of this lab. All source code files should contain author and partner identification in the comments at the top of the file
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
