Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 = problem1_minmax(nums);

mm.getFirst(); // returns 8

mm.getSecond(); // returns 100

String[] strs = { "Java", "C++", "Python", "JavaScript", "Lua" };

Pair mm2 = problem1_minmax(strs);

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 and students is an ArrayList (and Student Download Student is a sub-class of Person Download Person), then append(people, students) should compile, but append(students, people) should not.

Example: ArrayList a = new ArrayList<>();

ArrayList b = new 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 = new ArrayList<>();

a.add("cupcake");

a.add("banana");

a.add("apple");

problem5_isIncreasing(a)); // false

ArrayList b = new 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 type of array element * @param a input array * * @return a Pair containing the minimum and maximum values in the array */ // WRITE PROBLEM 1 METHOD HERE /** * 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. * * @param type of the elements of array list a * @param a first array list * @param b second array list */ // WRITE PROBLEM 2 METHOD HERE /** * 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. * * @param type of the elements of array list a * @param a input array list * * @return true if the elements are in increasing order, false if not */ // WRITE PROBLEM 5 METHOD HERE }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inductive Databases And Constraint Based Data Mining

Authors: Saso Dzeroski ,Bart Goethals ,Pance Panov

2010th Edition

1489982175, 978-1489982179

More Books

Students also viewed these Databases questions

Question

Please be clear and give the answers clearly for each box \f\f\f

Answered: 1 week ago