Menu

[Solved]Java Lab Assignment Write Class Integerset Represents Set Integers Definition Set Contains Q37123067

Java

In this lab assignment, you are to write a class IntegerSet thatrepresents a set of integers (by definition, a setcontains no duplicates). This ADT must be implemented as asingly linked list of integers (with no tailreference and no dummy head node), but it need not be sorted.

The IntegerSet class should have two data fields: thecardinality (size) of the set, and the head reference to the linkedlist. It should provide the following public methods:

  • IntegerSet(int size): this constructor methodcreates a new set of size integers by prompting the user to entersize elements for the set on the keyboard.
  • int size(): this method returns thecardinality of the set.
  • boolean isEmpty(): this method returns true ifthe set has no elements, false otherwise.
  • boolean isMember(int item): this methodreturns true if item is an element of the set, falseotherwise.
  • boolean add(int item): if item is not in theset, this method adds it to the set and returns true; otherwise,the set is unchanged and the method returns false.
  • boolean remove(int item): if item is in theset, this method removes it from the set and returns true;otherwise, the set is unchanged and the method returns false.
  • boolean isSubset(IntegerSet set2): this methodreturns true if every element in set2 is also in the calling set,false otherwise.
  • IntegerSet intersection(IntegerSet set2): thismethod returns a new set that is theintersection of the calling set and set2. An integer is anelement of the intersection set if it is in both the calling setand set2.
  • IntegerSet union(IntegerSet set2): this methodreturns a new set that is theunion of the calling set and set2. An integer is anelement of the union set if it is in either the calling set orset2, or both. Keep in mind that the union set formed should notcontain any duplicates.
  • IntegerSet difference(IntegerSet set2): thismethod returns a new set that is thedifference between the calling set and set2 (in thisorder). An integer is an element of the difference set if it is inthe calling set but not in set2.
  • void display(): this method prints allelements of the set on the screen.

In addition to the IntegerSet class, you are alsorequired to write a test driver that serves as the test harness forthe IntegerSet class. This test harness should provide the userwith options to explicitly test each method in theIntegerSet class.

Please do this in Java

Expert Answer


Answer to Java In this lab assignment, you are to write a class IntegerSet that represents a set of integers (by definition, a set… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *