Question: Write a generic method that compares its 2 arguments using theequals method and returnstrue if they are equal andfalse otherwise. Ensure that the name of
- Write a generic method that compares its 2 arguments using theequals method and returnstrue if they are equal andfalse otherwise.Ensure that the name of your method includes your last name.
- Use your generic method in a program that tests it with a variety of built-in types such asObject orInteger.
- Take a screenshot of your output and paste it into a new Word document under an "Exercise 1" heading.
- Below the screenshot in the Word document, briefly discuss the results that you saw when you ran the program. Did you see what you expected to see? Why or why not?
Exercise 2
- Write a generic classPair which has 2 type parameters,F andS, representing the type of the first and second elements of a pair respectively.
- Add get and set methods for the first and second elements of the pair.
- Override thetoString() method to display the first and second values of the pair in a format of your choosing.
- Use thePair class in a program that creates anArrayList of 10Pair objects containing values of your choosing. The program will then print the string representation of eachPair toSystem.out (i.e., use thetoString() method).
- Take a screenshot of your output and paste it into the Word document you created for the first exercise, but place the screenshot under a header for "Exercise 2."
Step by Step Solution
3.43 Rating (153 Votes )
There are 3 Steps involved in it
public class IsEqual public static void mainString args Object one new Object Object two one ifisEqualToonetwo SystemoutprintlnObjects one and two are equal Object three new Object ifisEqualToonethree ... View full answer
Get step-by-step solutions from verified subject matter experts
