Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone please help me with this code? My instructor has lost me on how to d

ID: 3674141 • Letter: C

Question

Can someone please help me with this code? My instructor has lost me on how to do this hash table. He has a serious language barrier as he is a foreigner. Do the section only in Bold on the Set class. Thank you. I have provided the Tester, Set, and SLL classes.

Here are the instructions:

//Here is the Tester class.

public class Tester{
// Have this method to display YOUR name.
static void displayName(){
System.out.println("Written by. ");
}

// DO NOT MODIFY THE MAIN METHOD
public static void main(String[] args){
displayName();
Set set1 = new Set();
Set set2 = new Set();

set1.add(13);
set1.add(23);
set1.add(33);
set1.add(13);
set1.add(54);
set1.add(75);

set2.add(15);
set2.add(26);
set2.add(26);

System.out.println("Contents of set set1: ");
set1.output();
System.out.println("Contents of set set2: ");
set2.output();
}
}

//Here is the SLL class.

public class SLL {
public class Node {
private int data;
private Node next;

public Node() {
data = 0;
next = null;
}

public Node(int newData, Node linkValue) {
data = newData;
next = linkValue;
}

public int getData() {
return data;
}

public Node getLink() {
return next;
}
}// End of Node inner class

private Node head;

public SLL() {
head = null;
}

public void addToStart(int itemData) {
head = new Node(itemData, head);
}

public boolean contains(int item) {
return (find(item) != null);
}


public Node find(int target) {
Node position = head;
int itemAtPosition;
while (position != null) {
itemAtPosition = position.data;
if (itemAtPosition == target) {
return position;
}
position = position.next;
}
return null; // target was not found
}

public void outputList() {
Node position = head;
while (position != null) {
System.out.print(position.data + " ");
position = position.next;
}
System.out.println();
}
}

//Here is the Set class.

public class Set {
private SLL[] hashArray;
private int size = 10;

public Set() {
hashArray = new SLL[size];
}

private int computeHash(int s) {
return s % size;
}

public boolean contains(int item) {
int hash = computeHash(item);
SLL list = hashArray[hash];
if (list.find(item) == null)
return false;
return true;
}

// DO NOT MODIFY ANY CODE ABOVE THIS LINE

// COMPLETE BELOW

}

Here is what it should look like when correctly finished:

Follow the instructions as commented in the codes. Do not have empty linked lists in your program. Create linked lists only when you need it. Remember that duplicates are not allowed in the set. Your program must work with any input correctly. Use SLL and Tester classes as they are given. Do not modify them. Use SLL and Tester classes as they are given. Do no modity them.

Explanation / Answer

public class Tester{

   // Have this method to display YOUR name.
   static void displayName(){
   System.out.println("Written by. ");
   }

   // DO NOT MODIFY THE MAIN METHOD
   public static void main(String[] args){
   displayName();
   MySet set1 = new MySet();
   MySet set2 = new MySet();

   set1.add(13);
   set1.add(23);
   set1.add(33);
   set1.add(13);
   set1.add(54);
   set1.add(75);

   set2.add(15);
   set2.add(26);
   set2.add(26);

   System.out.println("Contents of set set1: ");
   Integer[] s1=(Integer[]) set1.toArray();
   for(int i=0;i<s1.length;i++){
       System.out.print(s1[i]+" ");
   }
   System.out.println("Contents of set set2: ");
   Integer[] s2=(Integer[]) set2.toArray();
   for(int i=0;i<s2.length;i++){
       System.out.print(s2[i]+" ");
   }
   }
   }

public class SLL {

public class Node {

private int data;
private Node next;

public Node() {
data = 0;
next = null;
}

public Node(int newData, Node linkValue) {
data = newData;
next = linkValue;
}

public int getData() {
return data;
}

public Node getLink() {
return next;
}
}// End of Node inner class

private Node head;

public SLL() {
head = null;
}

public void addToStart(int itemData) {
head = new Node(itemData, head);
}

public boolean contains(int item) {
return (find(item) != null);
}


public Node find(int target) {
Node position = head;
int itemAtPosition;
while (position != null) {
itemAtPosition = position.data;
if (itemAtPosition == target) {
return position;
}
position = position.next;
}
return null; // target was not found
}

public void outputList() {
Node position = head;
while (position != null) {
System.out.print(position.data + " ");
position = position.next;
}
System.out.println();
}
}

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
public class MySet extends HashSet{
private SLL[] hashArray;
private int size = 10;

public MySet() {
hashArray = new SLL[size];
}

private int computeHash(int s) {
return s % size;
}

public boolean contains(int item) {
int hash = computeHash(item);
SLL list = hashArray[hash];
if (list.find(item) == null)
return false;
return true;
}

@Override
public boolean add(Object e) {
   // TODO Auto-generated method stub
   super.add(e);
   return false;
}

@Override
public boolean addAll(Collection c) {
   // TODO Auto-generated method stub
   return false;
}

@Override
public void clear() {
   // TODO Auto-generated method stub
  
}

@Override
public boolean contains(Object o) {
   // TODO Auto-generated method stub
   return false;
}

@Override
public boolean containsAll(Collection c) {
   // TODO Auto-generated method stub
   return false;
}

@Override
public boolean isEmpty() {
   // TODO Auto-generated method stub
   return false;
}

@Override
public Iterator iterator() {
   // TODO Auto-generated method stub
   return null;
}

@Override
public boolean remove(Object o) {
   // TODO Auto-generated method stub
   return false;
}

@Override
public boolean removeAll(Collection c) {
   // TODO Auto-generated method stub
   return false;
}

@Override
public boolean retainAll(Collection c) {
   // TODO Auto-generated method stub
   return false;
}

@Override
public int size() {
   // TODO Auto-generated method stub
   return 0;
}

@Override
public Object[] toArray() {
   // TODO Auto-generated method stub
   return null;
}

@Override
public Object[] toArray(Object[] a) {
   // TODO Auto-generated method stub
   return null;
}
}