Question: Implement a GENERIC Class named MagicBox Write a generic method to exchange the positions of two different elements in a list Write a generic method

Implement a GENERIC Class named MagicBox

Write a generic method to exchange the positions of two different elements in a list

Write a generic method that will count the occurrences of an item in the list

YOU MUST USE GENERICS!

Test your program with the following code

public class CountTest {

public static void main(String[] args) {

MagicBox occurances = new MagicBox();

String[] helloWorld = {"h", "e", "l", "l", "o", "w", "o", "r", "l", "d"};

int char_count = occurences.count(helloWorld, "l");

System.out.println("#occurrences of l: " + char_count);

Integer[] myints = {1, 9, 8, 8, 0, 0, 2, 0, 1, 7, 1, 0, 1, 0, 1, 0, 0};

int int_count = occurences.count(myints, 0);

System.out.println("#occurrences of zeros: " + int_count);

//before swap

System.out.println(helloWorld);

occurances.swap(helloWorld, 4,5);

//after swap

System.out.println(helloWorld);

//before int swap

System.out.println(myints);

occurances.swap(myints,7,8);

//after int swap

System.out.println(myints);

}

}

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!