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

A set (collection of elements without duplication) as a mathematical model is de

ID: 3813057 • Letter: A

Question

A set (collection of elements without duplication) as a mathematical model is defined by the java interface below. Implement the mathematical model Set of integers as a class that implements the below interface. You must implement this structure as a linked list of elements kept in the increasing sequence. You must implement "isMember", "add", and “intersection” methods using recursive algorithms. Others can be implemented as you wish.

public interface Set

{ public boolean isEmpty();          // Is the set empty?

public void makeEmpty();          // Make this set empty.

public boolean isMember(int x); // Is x a member of this set?

public void add(int x); // Insert an element x in this set.

public void remove(int y);          // Delete an element y from this set.

public void union(Set other, Set result); // result = "this" UNION other

public void intersection (Set other, Set result); // result = "this" INTERSECTION other

public void difference (Set other, Set result); // result = "this" - other

public String toString(); // Overridden toString method that returns the set description as

                                                    // a String.

public boolean equals(Object other); // Overridden equals method to check equality of two sets.

}

makeEmpty creates an empty set.

isEmpty returns true if the set is empty, false otherwise.

isMember returns true if x is in the given set, false otherwise.

add inserts an element in the set (without duplication).

remove deletes an element from the set.

A union B is the set of all elements either in A or in B or both.

A intersection B is the set of all elements that are in both, A and B.

A difference B is the set of all elements in A but not in B.

toString returns the description of the set as a String.

equals returns true if the two sets are identical (same elements), false otherwise.

To test your implementation, write the test program to do the following. As always, all input is read from the input file and all output is produced in the output file. Prompt the user to acquire the names of input and output files.

Create an array of N sets, N is the first data in the input file. // S[0] through S[N-1]

Read commands from the input file, and execute them. After each command, output what was done (like, inserted element xxx in set n) and produce the output relevant to that command. Make sure that your output is self-explanatory and paper conserving. That means, do not output the elements of the set one per line, but output many elements on the same line.

The commands are specified in the following format:

A x n                      // Insert the integer x in set S[n]

R x n                      // Delete (Remove) x from S[n]

U n1 n2 n3           // S[n3] = S[n1] union S[n2]

N n1 n2 n3           // S[n3] = S[n1] intersection S[n2]

D n1 n2 n3           // S[n3] = S[n1] difference S[n2]

B x n                      // Does x belong in set S[n] ?

O n                         // Output the set S[n]

E n                          // Is set S[n] empty?

Q n1 n2                 // Are two sets S[n1] and S[n2] equal?

Tester Class:

import java.io.FileReader;
import java.io.PrintWriter;
import java.util.Scanner;
import javax.swing.JOptionPane;

public class SetOfIntegersTester {

public static void main(String[] args) throws Exception {

String inf = JOptionPane.showInputDialog("Input file?");
// Input file is src/
FileReader inFile = new FileReader(inf);
Scanner in = new Scanner(inFile);
String outf = JOptionPane.showInputDialog("Output file?");
PrintWriter outFile = new PrintWriter(outf);

while (in.hasNextLine()) {


String line = in.nextLine();
String[] split = line.split("\s+");

  
  
outFile.println(line + " ");
}
outFile.close();
}
}

Here is what i have so far:

//SetOfIntegers Class

import java.util.LinkedList;

public class SetOfIntegers implements Set {

    private Node first;

    public SetOfIntegers() {
        LinkedList list = new LinkedList();
        list.add(first);
    }

    @Override
    public boolean isEmpty() {
        return first == null;
    }

    @Override
    public void makeEmpty() {
        first = null;
    }

    @Override
    public boolean isMember(int x) {
      
    }

    public int getSize(){
        int count = 0;
        Node p = first;
        while(p!=null){
            count++;
            p = p.next;
        }
        return count;
    }
  
    @Override       //Need to make this recursive
    public void add(int x) {
        Node q = new Node(x);
        q.next = first;
        first = q;
    }

    @Override
    public void remove(int y) {
        if(isEmpty())
            return;
        first = first.next;
    }

    @Override
    public void union(SetOfIntegers other1, SetOfIntegers other2, SetOfIntegers result) {
      
    }

    @Override
    public void intersection(SetOfIntegers other1, SetOfIntegers other2, SetOfIntegers result) {
        SetOfIntegers set1 = new SetOfIntegers();
        if(other1.isEmpty()||other2.isEmpty()){
            set1 = other1;
        }for(int i = 0; i < set1.getSize(); i++){
            if()
        }
      
    }

    @Override
    public void difference(SetOfIntegers other1, SetOfIntegers other2, SetOfIntegers result) {

    }

    @Override
    public String toString() {
        Node p = first;
        String out = " ";
        while(p!=null){
            out = out + p.data + " ";
            p = p.next;
        }
        return out;
    }

    @Override
    public boolean equals(Object other) {

    }

}

//Node Class

public class Node {

    public int data;
    public Node next = null;

    public Node(int data) {
        this.data = data;
    }
}

//Input File

10           // This is the number of Sets in the array of Sets
E   0
A   24   0
A   423   0
A   76   0
A   12   0
A   8   0
A   64   0
O   0
E   0
B   76   0
R   76   0
R   68   0
B   24   0
B   12   0
B   76   0
A   111   0
O   0
A   76   1
A   55   1
A   12   1
A   43   1
A   876   1
A   98   1
A   64   1
A   34   1
O   1
B   111   1
B   76   1
U   0   1   2
O   2
N   0   1   3
O   3
D   0   1   4
O   4
U   3   4   5
Q   5   0
Q   1   2
D   0   5   6
E   6
O   0
O   1
O   2
O   3
O   4
O   5
O   6

Explanation / Answer

public category Entry within the Entry, this may be a key worth for your hash table.
non-public String word;
//The count of what percentage times the word seems.
non-public int count;
/**
* creator that makes associate object given a word.
*
* @param word The word to line within the .
*/
public Entry(String word)
/**
* Returns the word of this .
*
* @return The word of this .
*/
public String getWord() come this.word;
}
/**
* Returns the count of what percentage times this word seems within the document.
*
* @return the word count.
*/
public int getCount() come this.count;
}
/**
* will increase the count of the word during this by one.
*
*/
public void incrementCount()
@Override
public String toString() should implement this method!!!!
int hashValue;
if(type ==1)come back hashValue %7;
}
// secondary hash perform
hashValue = str.hashCode();
come seven - (hashValue the troubles 7);
}
}---------------------------------------------------
----------- category SIMPLELIST
public category SimpleList the interior array.
non-public static final int INITIAL_CAPACITY = 10;
//Internal array of Entry objects.
public Entry[] entries;
//Size of the List
non-public int size;
/**
* creator creates associate empty with default initial capability.
*
*/
public SimpleList()
/**
* This technique adds a brand new to the tip of the list. The list also will be resized once necessary.
*
* @param e The entry to feature to the tip of the list.
*/
public void add(Entry e) to envision if we want to size the list
if (this.size == this.entries.length)
this.entries[this.size] = e;
this.size++;
}
/**
* This perform finds the within the list whose word matches the given . The perform
* returns the index of wherever the Entry may be found, or -1 if the wasn't found.
*
* @param word The word whose you would like to seek out.
*
* @return Returns the index of wherever the was found, -1 otherwise.
*/
public int find(String word) zero ; i &lt; this.size ; i++)
}
return -1;
}
/**
* This technique returns the at the given index.
*
* @param index The index of the to come. should be a positive worth between zero to
* size()-1 comprehensive.
* @return The at the given index.
*/
public Entry getEntry(int index) come this.entries[index];
}
/**
* This technique returns the amount of entries within the list.
*
* @return the amount of entries within the list.
*/
public int size() come this.size;
}
/**
* This technique can produce a brand new list double the dimensions of the previous, and duplicate all values from the previous list
* to the new list.
*/
non-public void resize() {
Entry[] newList = new Entry[this.entries.length * 2];
for (int i = zero ; i &lt; this.size ; i++)
this.entries = newList;
}

public String toString() {
String result = "";
String formatter = "%-20s%-1d";
for (int i = zero ; i &lt; this.size ; i++)
  
public SimpleList generateSimpleList()range
obj.add(new Entry(numbers.get(i)));
}
come obj;
}
  
non-public SimpleList generateHashTable()variety
Entry entry = new Entry(numbers.get(i));
// get hash code
int hash = entry.hashCode(numbers.get(i), 1);
  
if(obj.getEntry(hash)!= null)
else
}
come obj;
}
  
// main perform
public static void main(String args[])scan file
JFileChooser jfchooser = new JFileChooser();
ArrayList&lt;String&gt; list = new ArrayList&lt;&gt;();
jfchooser.showOpenDialog(null);
int result = jfchooser.showOpenDialog(null);
if( result == JFileChooser.APPROVE_OPTION)metallic element = new FileReader()
FileReader atomic number 87 = null;
JOptionPane.showMessageDialog(null, "Select File");
File file = jfchooser.getSelectedFile();
atomic number 87 = new FileReader(file);
int num = 1;
whereas (num != -1)
}catch(FileNotFoundException ex)catch(IOException ex)
}
// making object
HashTable obj = new HashTable(list);
obj.generateSimpleList();
obj.generateHashTable();
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote