please help me understand this code in java (using generic method). More specifically why was item1,item2, item3 parameter names never used again and what is the purpose of this line of code: TheType tripleMin(TheType item1, TheType item2, TheType item3) {

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter11: Advanced Inheritance Concepts
Section: Chapter Questions
Problem 5RQ
icon
Related questions
Question
100%

please help me understand this code in java (using generic method). More specifically why was item1,item2, item3 parameter names never used again and what is the purpose of this line of code:

TheType tripleMin(TheType item1, TheType item2, TheType item3) {  

public class ItemMinimum {
public static <TheType extends Comparable<TheType>>
TheType tripleMin (TheType item1, TheType item2, TheType item3) {
TheType minVal iteml; // Holds min item value, init to first item
}
}
if (item2.compareTo (minVal) < 0) {
minVal =
}
item2;
}
if (item3.compareTo (minVal) < 0) {
minval =
item3;
}
return minVal;
public static void
Integer num1 55;
Integer num2 = 99;
Integer num3 = 66;
main(String[] args) {
// Test case 1, iteml
// Test case 1, item2
// Test case 1, item3
iteml
Character let1 = = 'a'; // Test case 2,
Character let2 = 'z'; // Test case 2, item2
Character let3 'm'; // Test case 2, item3
String strl "zzz";
// Test case 3,
String str2 "aaa"; // Test case 3,
String str3 = "mmm"; // Test case 3,
"1
+ num2 +
+ num3);
// Try tripleMin method with Integers
System.out.println("Items: + num1 +
System.out.println("Min: " + tripleMin (numl, num2, num3) + "\n");
"1
item1
item2
item3
// Try tripleMin method with Strings
System.out.println("Items: + strl +
System.out.println("Min:
// Try tripleMin method with Characters
System.out.println("Items: + let1 +
+ let2 +
+ let3);
System.out.println("Min: " + tripleMin (letl, let2, let3) + "\n");
"1
"1
11
11
"1
11
"1 "1
"1 "I
+ str2 +
+ tripleMin(str1, str2, str3) + "\n");
+ str3);
run:
Items: 55 99 66
Min: 55
Items: az m
Min: a
Items: zzz aaa mmm
Min: aaa
Transcribed Image Text:public class ItemMinimum { public static <TheType extends Comparable<TheType>> TheType tripleMin (TheType item1, TheType item2, TheType item3) { TheType minVal iteml; // Holds min item value, init to first item } } if (item2.compareTo (minVal) < 0) { minVal = } item2; } if (item3.compareTo (minVal) < 0) { minval = item3; } return minVal; public static void Integer num1 55; Integer num2 = 99; Integer num3 = 66; main(String[] args) { // Test case 1, iteml // Test case 1, item2 // Test case 1, item3 iteml Character let1 = = 'a'; // Test case 2, Character let2 = 'z'; // Test case 2, item2 Character let3 'm'; // Test case 2, item3 String strl "zzz"; // Test case 3, String str2 "aaa"; // Test case 3, String str3 = "mmm"; // Test case 3, "1 + num2 + + num3); // Try tripleMin method with Integers System.out.println("Items: + num1 + System.out.println("Min: " + tripleMin (numl, num2, num3) + "\n"); "1 item1 item2 item3 // Try tripleMin method with Strings System.out.println("Items: + strl + System.out.println("Min: // Try tripleMin method with Characters System.out.println("Items: + let1 + + let2 + + let3); System.out.println("Min: " + tripleMin (letl, let2, let3) + "\n"); "1 "1 11 11 "1 11 "1 "1 "1 "I + str2 + + tripleMin(str1, str2, str3) + "\n"); + str3); run: Items: 55 99 66 Min: 55 Items: az m Min: a Items: zzz aaa mmm Min: aaa
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Generic Type
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT