<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">import java.util.*;

/** An unordered list of unique elements --a mathematical set. */
public class Set {
    private Vector v; // Contains the elements of the set

    /** Constructor: an empty set */
    public Set() {
       v= new Vector();
    }
    
    /**  = this Set's number of elements */
    public int size() {
       return v.size();
    }
    
    /**  = ``this Set is empty'' */
    boolean isEmpty() {
       return size() == 0;
    }

    /**  = ``this Set contains b''. */
    boolean contains(Object b) {
       Enumeration e= v.elements();
       while (e.hasMoreElements()) {
          if ((e.nextElement()).equals(b))
             return true;
       }
       return false;
    }

    /**  = a copy of this Set */
    public Set copy() {
      Set c= new Set();
      Enumeration e= v.elements();
       while (e.hasMoreElements()) {
          c.add(e.nextElement());
       }
       return c;
    }

    /**  Operation (this Set)= (this Set) union {b};. 
         That is, add b to this Set, if it is not already
         in this Set. b should not be null. */
    public void add(Object b) {
       if (!contains(b))
          v.addElement(b);
    }

    /**  = the union of (this Set) and s */
    public Set union(Set s) {
       Set union= s.copy();
       Enumeration e= v.elements();
       while (e.hasMoreElements()) {
          union.add(e.nextElement());
       }
       return union;
    }

    /**  = (this Set) intersected with s */
    public Set intersect(Set s) {
      Set inters= new Set();
       Enumeration e= v.elements();
       while (e.hasMoreElements()) {
          Object elem= e.nextElement();
          if (s.contains(elem))
             inters.add(elem);
       }
       return inters;
    }
    
    /**  = an Enumeration of the elements of this Set.
         Don't change the set while the enumeration is
         being processed
     */
    public Enumeration elements() {
       return v.elements();
    }
    
    /**  = string rep of this Set */
    public String toString() {
       return "No. of elements: " + size() + 
              " Last element: " + v.elementAt(v.size()-1);
    }
    
}
</pre></body></html>