Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE USE JAVA A set is a collection of elements in which no element occurs more than once (distinct elements). We can implement a simple

PLEASE USE JAVA

A set is a collection of elements in which no element occurs more than once (distinct elements). We can implement a simple set as a linked list to store the items in the set.

Fundamental Set operations are add(E element), remove(E element), union(Set otherSet), intersection(Set otherSet) and difference(Set otherSet).

MySet

head

tail

size

+ MySet()

+ MySet(arr : E[])

+ MySet(otherList : List)

+ Boolean Add(element:E): boolean

+ Boolean Remove(element:E): boolean

+ union(otherSet: MySet): MySet

+ intersection(otherSet: MySet): MySet

+ difference(otherSet: MySet): MySet

The class should implement the MyList interface (all abstract methods defined in MyList should be implemented in MySet) and should contain three constructors to create an empty set, create a set from an array of objects or create a set from a List (ArrayList, LinkedList).

Define and implement the following methods in MySet:

Boolean add(E element) : add element to the set, return true if element is added

Boolean remove(E element): remove element from the set, return true if element is found and removed

MySet union(MySet otherSet): return a set containing elements from both sets

MySet Intersection(MySet otherSet): return the intersection of two sets

MySet Difference(MySet otherSet): return the difference of two sets

Write a test program that creates Three MySet instances, set1, set2 and set3 and show that the three constructors and all methods implemented in MySet class are working properly.MySet Intersection(MySet otherSet): return the intersection of two sets

MySet Difference(MySet otherSet): return the difference of two sets

Write a test program that creates Three MySet instances, set1, set2 and set3 and show that the three constructors and all methods implemented in MySet class are working properly.

Step by Step Solution

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

Data Management Databases And Organizations

Authors: Richard T. Watson

2nd Edition

0471180742, 978-0471180746

More Books

Students also viewed these Databases questions

Question

Understand the role of corporate design in communications.

Answered: 1 week ago