Question: Create a new JAVA class called ListSetOperator, which will be used to perform set operations with UList objects. The class should include methods: public UList
Create a new JAVA class called "ListSetOperator", which will be used to perform set operations with UList objects.
The class should include methods:
public UList union(UList Set 1, UList Set2) that returns a reference to a new list containing all of the items from Set1 or Set2 with no repeats,
public UList intersect(UList Set1, UList Set2) that returns a reference to a new list containing only the items from both Set1 and also Set2 with no repeats, and
public UList subtract(UList Set 1, UList Set2) that returns a reference to a new list containing all of the items that are in Set1 but not Set2
Write a ListSetMain class to demonstrate that your methods work. Include code that displays the IDs of all of the elements in the resulting sets (in any order). Use "A', "B", "C",... as elements.
public class UList {
public static final int MAXSIZE = 100;
public UList() {
size = 0;
item = new ListElement[MAXSIZE];
}
public boolean fullCheck() {
return (size == MAXSIZE);
}
public int getSize() {
return size;
}
public boolean exists(String value) {
boolean found = false;
int i=0;
while ((i if ((item[i].key).equalsIgnoreCase(value)) found = true; i++; } return found; } public int remove(String value) { boolean found = false; int i=0; while ((i if (item[i].key == value) { found = true; item[i] = item[size-1]; size--; } i++; } if (found) return 0; else return -1; } public int insert(String value, Object o) { if (fullCheck() || exists(value)) return -1; else { item[size++] = new ListElement (value, o); return 0; } } // Navigator methods public void first() { navLoc = 0; } public boolean lastCheck() { return (navLoc == size); } public String currKey() { return item[navLoc].key; } public Object currObj() { return item[navLoc].payload; } public void next() { if (!lastCheck()) navLoc++; } private int size; private ListElement[] item; private int navLoc; // used to navigate the list }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
