Question: package template; public class Assign { public static void main(String[] args) { //You do not need to change the code inside main(...) //They are provided

package template;

public class Assign {

public static void main(String[] args) {

//You do not need to change the code inside main(...)

//They are provided for you to test your own solution.

String[] sweets = {"cake", "choclate", "donut"};

Integer[] numbers = {10, 20, 30, 40};

//When you add your method, uncomment the following three lines.

// contains(sweets, "donut"); //should print Found

// contains(sweets, "cookie"); //should print NOT Found

// contains(numbers, 100); //should print Not Found

}

//Assign Task:

//Write a Java generic method named contains that takes in two parameters:

//

//A variable named anyArray that is an array of any type, and

//A variable named anyValue that is of the same type as the element of anyArray.

//

//The method checks if anyValue is in anyArray. If yes, the method prints the message Found and return true.

//

//Otherwise, the method prints the message Not Found and returns false.

//add your generic method here

//Hints

//- Your method is a static method like checkEqual(...), printGenericArray(...)

//- First write a non-static method taking in non-generic type, such as a String array, and a String.

//- And test your code using the given code in main(...).

//- Then change the non-generic method to generic method.

//- Last test your generic method using the given code in main(...).

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!