Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

) Given the below function, its partitions and blocks, provide valid values for

ID: 654198 • Letter: #

Question

) Given the below function, its partitions and blocks, provide valid values for each block.

public Set convert(Set a1, Set a2)

/*

Effects: if a1 or a2 are null, throw NullPointerException

else return the non-null Set that is the result of conversion of sets

*/

Type of a1

b1: a1 is null

b2: a1 is empty set

b3: a1 has one element

b4: a1 has more than one element

Relationship between a1 and a2

b1: a1 and a2 represent same set

b2: a1 is a subset of a2

b3: a2 is a subset of a1

b4: a1 and a2 do not have any elements in common

Set a1 contains null elements

b1: true

b2: false

Type of data in set a2

b1: characters

b2: integers

b3: strings

Explanation / Answer

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class MySet {  
  
  
   public Set convert(Set a1, Set a2){
      
       if(a1==null||a2==null){
           throw new NullPointerException();
       }else{
           a1.add(a2);
           return a1;
       }
      
   }
      public static void main(String[] a) {
          String typeOfa1,relationshipA1A2;
          boolean a1ContainsNull;
          char b1[]={'a','b','c','d'};
          int b2[]={1,2,3,4,5};
          String b3[] = { "A", "B", "C", "D", "E" };
          Set a1=new HashSet<String>();
          Set a2 = new HashSet(Arrays.asList(b1));
          a2.add(b2);
          a2.add(b3);
          MySet ms=new MySet();
          ms.convert(a1,a2);
          if(a1.equals(null)){
              typeOfa1="b1";
          }
          if(a1.isEmpty()){
              typeOfa1="b2";
          }
          if(a1.size()==1){
              typeOfa1="b3";
          }
          if(a1.size()>1){
              typeOfa1="b4";
          }
          if(a1.equals(a2)){
              relationshipA1A2="b1";
          }
          if(a2.contains(a1)){
              relationshipA1A2="b2";
          }
          if(a1.contains(a2)){
              relationshipA1A2="b3";
          }
          if(!a1.equals(a2)){
              relationshipA1A2="b4";
          }
          Iterator<Set> i=a1.iterator();
          while (i.hasNext()){
                 if(i.next()==null){
                   a1ContainsNull=true;
                 }else{
                   a1ContainsNull=false;
                 }
          }
      }
}