Question: Help with programming assignment? //Starter Code package set; import java.util.ArrayList; /** * A generic set implementation */ public class Set { /** * A list

 Help with programming assignment? //Starter Code package set; import java.util.ArrayList; /**

* A generic set implementation */ public class Set { /** *

A list of elements contained in the set */ public ArrayList elements;

Help with programming assignment?

//Starter Code

package set; import java.util.ArrayList;

/** * A generic set implementation */ public class Set { /** * A list of elements contained in the set */ public ArrayList elements;

/** * Creates a set using the elements of the ArrayList list. * @param list the ArrayList whose elements are used to create this set. * @throws IllegalArgumentException if list contains a duplicity. */ public Set(ArrayList list) { elements = new ArrayList(); int i, size = list.size(); T elt; for(i = 0; i : Duplicity not " + "allowed in sets"); elements.add(elt); } }

/** * Determines whether a set contains the specified element * @param elt an element * @return true if elt is an element of this set; otherwise, false */ public boolean isElement(T elt) { return elements.contains(elt); }

/** * Determines whether a set is empty * @return true if this set is empty; otherwise, false */ public boolean isEmpty() { return elements.isEmpty(); } /** * Computes the intersection of this set and the specified set. * @param s a set * @return a set representing the intersection of this set and s. */ public Set intersect(Set s) { T elt; ArrayList result = new ArrayList(); int i, size = elements.size(); for (i = 0; i

/** * Computes the union of this set and the specified set. * @param s a set * @return a set representing the union of this set and s. */ public Set union(Set s) { // implement this method Set union = Set.union(elt,s); }

/** * Computes the difference of this set and the specified set. * @param s a set * @return a set representing the difference of this set and s. */ public Set diff(Set s) { // implement this method ArrayList diff = elements(); int i, size = elements.size(); for (i = 0; i

} } /** * Determines whether this set is equal to the specified set. * @param obj an object * @return false if the specified object is not equal to this set; * otherwise, true */ public boolean equals(Object obj) { // implement this method }

/** * Determines whether this set is a subset of the specified set. * @param param s a set * @return false if this set is not a subset of the specified set; * otherwise, true */ public boolean subset(Set s) { // implement this method

} /** * Determines whether this set is a proper subset of the specified set. * @param param s a set * @return false if this set is not a proper subset of the specified set; * otherwise, true */ public boolean properSubset(Set s) { // implement this method

} /** * returns a string {x1,x2,...,xn} representing this set, * where x1,x2,...,xn are elements of this set. * @return a string representation of this set formatted * as specified. */ public String toString() { String setAsString = "{"; int size = elements.size(); if (size > 0) { setAsString += elements.get(0); int i; for (i = 1; i

Csc 1351-03 Spring 2017, Lab 8: Project Set create a project named set that illustrates the use of generic classes and generic methods mplementing a Generic Set Class DEFINITION 1. Generics is a way of defining classes, interfaces and methods by using type pa rameters to represent types. A more technical term for generics is parametric polymorphism A generic method, interface or class is fully specified at run time. In Java, a generic type can only be specialized using an object type. Every primitive type in Java has an associated object type (a wrapper class DEFINITION 2. A set is a finite or infinite collection of objects in which order has no significance and multiplicity is generally also ignored. Members of a set are often referred to as elements and the notation r E A is used to denote that r s an element of a set A. A set is usually denoted as a list of elements. For example, 12. 3. 4, 5. G is a set that contains five elements. In today's lab, you will implement a generic class, the set T class. The class will be generic but its methods will not be generic. Some methods will use the formal type parameter of the class. In this lab, we introduce a basic software engineering concept called composition one object is composed of another. A set is composed of a list We will use the Java API ArrayList class Basic Set Operations DEFINITION 3. The cardinality of a set is the number of elements that the set contains. For example, the cardinality of A f2.3, 4, 5, 6h, denoted A is 5 DEFINITION 4. The intersection of two sets A and B is the set of elements common to A and B. This is written An B.and is pronounced "intersection" or "cap DEFINITION 5. The union of two sets A and B is the set obtained by combining the members of each without allowing multiplicity. This is written A u B, and is pronounced "union" or "cup DEFINITION 6. The difference of sets A and B denoted A-B, is the set of elements belonging to set A but not B

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!