Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/** Given two sets of strings (stored in two arrays), determine if they are the same set i.e. contain the same set of strings */

/**
Given two sets of strings (stored in two arrays), determine if they are the same set
i.e. contain the same set of strings
*/
public class SetChecker
{

public static void main(String[] args)
{
String[] setA = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
String[] setB = {"January", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};

System.out.print("The elements of the arrays setA and setB ");

if (!sameSet(setA, setB))
{
System.out.print("do not ");
}
System.out.println("form the same set.");
System.out.println("Expected: The elements of the arrays setA and setB do not form the same set." );


String[] setWinterA = {"Jan", "Feb", "Mar", "Apr"};
String[] setWinterB = {"Jan", "Mar", "Apr", "Feb"};

System.out.print("The elements of the arrays setWinterA and setWinterB ");

if (!sameSet(setWinterA, setWinterB))
{
System.out.print("do not ");
}
System.out.println("form the same set.");
System.out.println("Expected:The elements of the arrays setWinterA and setWinterB form the same set." );
}


public static boolean sameSet(String[] a, String[] b)
{
for (int i = 0; i < a.length; i++)
{
if (!isIn(a[i], b))
{
return false;
}
}
for (int i = 0; i < b.length; i++)
{
if (!isIn(b[i], a))
{
return false;
}
}
return true;
}

/**
Determines if a string is part of a set of strings
@param String elem - the element to search for
@param String[] set - the set of strings stored in an array
@return true or false
*/
public static boolean isIn(String elem, String[] set)
{
   //-----------Start below here. To do: approximate lines of code = 4
   // go through the parameter array named set and check if an element (string) in the array
   // is equal to the given string parameter elem. If elem is in the set, return true
   // After checking through the entire set, if the method hasn't already returned, then return false
   // Hint: don't forget to use .equals() method to compare two strings!!
   
   
   
   
   
   
   
   
   //-----------------End here. Reminder: no changes outside the todo regions.
}
}

Include screenshots too for formatting.

Step by Step Solution

3.44 Rating (157 Votes )

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

Introduction to Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st edition

321321367, 978-0321321367

More Books

Students also viewed these Programming questions

Question

-4 1 9. Let A = Find A-1, (A") and verify that (A")= (A-1)".

Answered: 1 week ago

Question

What are the qualities the character hides from themselves?

Answered: 1 week ago

Question

What would they find most embarrassing if people knew?

Answered: 1 week ago