Question: *Write Methods for the following class public class Set { private Node head; private Node last; private int size = 0; private class Node {

 *Write Methods for the following class public class Set { private

*Write Methods for the following class

public class Set {

private Node head;

private Node last;

private int size = 0;

private class Node {

private E item;

private Node next;

private Node prev;

private Node(E item) {

this.item = item;

}

}

/* Returns true if target is equal to element. Otherwise,

returns false

*/

private boolean equals(Object target, Object element) {

boolean flag;

if (target == null) {

flag = element == null;

} else {

flag = target.equals(element);

}

return flag;

}

/* Returns true if the item is contained in the Set object.

Otherwise, return false.

*/

public boolean contains(Object item) {

boolean found = false;

Node ptr = head;

while (ptr != null && !found) {

if (equals(ptr.item, item)) {

found = true;

}

ptr = ptr.next;

}

return found;

}

// Return the size of the set

public int size() {

return size;

}

}

Math 140 Programming Assignment 3 In this assignment you will add additional methods to the Set class. Use the Set class posted under HW3 to complete this assignment. In addition, use Test.java to test your code. Upload Set.java when you've completed the assignment. Review the coding standards before uploading your code. The Set class is a LinkedList with two additional properties A Set cannot contain duplicate objects. The data stored in a Set object can be compared with the compareTo method. . Note: If object A null and object B # null then A element. Otherwise, the method returns false. private boolean less(E target, E element) - returns true if target greaterThan(E item) - returns a Set where the Node objects store an item greater than the specified object. public SetcEs lessThan(E item) - returns a Set where the Node objects store an item less than the specified object. public String[] getStrings() - returns an array of Strings that store a String representation of the items stored in the Set object. (If item null then the String representation is "null". Otherwise, the String representation is the String returned by the toString() method.)

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!