Question
JAVA 3 SMALL QUESTIONS problem1_minmax (20 pts) Implement a static generic method named problem1_minmax that takes as a parameter an array of type T and
JAVA 3 SMALL QUESTIONS
problem1_minmax (20 pts)
Implement a static generic method named problem1_minmax that takes as a parameter an array of type T and returns a Pair containing the minimum and maximum value in the array. Require that the array elements implement the Comparable interface. Assume that there will always be at least one element in the array.
Example: Integer[] nums = { 10, 100, 50, 15, 8, 99 };
Pair
mm.getFirst(); // returns 8
mm.getSecond(); // returns 100
String[] strs = { "Java", "C++", "Python", "JavaScript", "Lua" };
Pair
mm2.getFirst(); // returns "C++"
mm2.getSecond(); // returns "Python"
problem2_append (20 pts)
Implement a static generic method named problem2_append that takes as a parameter two generic array lists (a and b), and appends the elements of b to a (returning void). The elements in b must be either the same type as the elements of a, or else a subtype of the elements of a. For example, if people is an ArrayList
Example: ArrayList
ArrayList
a.add(new Person("Fred"));
a.add(new Person("Sally"));
b.add(new Student("Bob", "Bioinformatics"));
b.add(new Student("Rubia", "Computer Science"));
problem2_append(a, b);
// a now contains Fred, Sally, Bob, Rubia
problem5_isIncreasing (20 pts)
Implement a static generic method named problem5_isIncreasing that takes as a parameter a generic array list and returns true if it its elements are in increasing order, or false if not. Increasing order in this case means non-decreasing, so there can be multiple equivalent elements next to each other (e.g., 0, 2, 2, 4) and it will still be considered increasing. Require that the array list elements implement the Comparable interface.
Example: ArrayList
a.add("cupcake");
a.add("banana");
a.add("apple");
problem5_isIncreasing(a)); // false
ArrayList
b.add(2);
b.add(4);
b.add(4);
b.add(6);
b.add(8);
problem5_isIncreasing(b)); // true
package labs.lab8; public class Main { /** * Takes as a parameter an array of type T and returns a Pair containing the * minimum and maximum values in the array. Require that the array elements * implement the Comparable interface. Assume that there will always be at least * one element in the array. * * @param
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started