Question: Need help filling in the code with JAVA, ONLY edit the parts between the bolded. import java.util.TreeSet; import java.util.Set; /** Illustrates basic operations of a

Need help filling in the code with JAVA, ONLY edit the parts between the bolded.

import java.util.TreeSet;

import java.util.Set;

/**

Illustrates basic operations of a set.

Your job is to write the static method for set intersection.

*/

public class SetTester1

{

public static void main(String[] args)

{

Set set1 = new TreeSet() ;

set1.add("A") ;

set1.add("B") ;

set1.add("C") ;

set1.add("D") ;

set1.add("F") ;

set1.add("G") ;

System.out.println("set1, the hash set: " + set1) ;

Set set2 = new TreeSet() ;

set2.add("B") ;

set2.add("D") ;

set2.add("E") ;

set2.add("F") ;

set2.add("G") ;

System.out.println("set2, the tree set: " + set2) ;

System.out.println("C is in set1: " + set1.contains("C")) ;

System.out.println("C is in set2: " + set2.contains("C")) ;

System.out.println("Removing C from set1: " +set1.remove("C")) ;

System.out.println("Removing C from set2: " +set2.remove("C")) ;

Set set3 = intersection(set1, set2) ;

System.out.println("Intersection: " + set1 + " ^ " + set2

+ " = " + set3) ;

}

/**

A method that returns the intersection of two sets.

@param x first set

@param y second set

@return the intersection set

*/

public static Set intersection(Set x, Set y)

{

//-----------Start below here. To do: approximate lines of code = 5

// 1. fill in the intersection method

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.

}

}

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!