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

i need help writing a class from the information below ConcordanceDataStructure

ID: 3804731 • Letter: I

Question

i need help writing a class from the information below

ConcordanceDataStructure

Constructor for testing purposes The string will be "Testing" and the int will be the size of the hash table. This is used only for testing.

Parameters:

test - the string "Testing"

size - the size of the hash table

ConcordanceDataStructure

This constructor takes in an integer which represents the estimated number of words in the text. Determine the size of the table by using a loading factor of 1.5 and a 4K+3 prime. Example if you estimated 500 words, 500/1.5 = 333. The next 4K+3 prime over 333 is 347. So you would make the table a length of 347.

Parameters:

num - the estimated number of words in the text

getTableSize

Returns the size of the ConcordanceDataStructure (number of indexes in the array)

Specified by:

getTableSize in interface ConcordanceDataStructureInterface

add

Use the hashcode of the ConcordanceDataElement to see if it is in the hashtable. If the word does not exist in the hashtable - Add the ConcordanceDataElement to the hashtable. Put the line number in the linked list If the word already exists in the hashtable 1. add the line number to the end of the linked list in the ConcordanceDataElement (if the line number is not currently there).

Specified by:

add in interface ConcordanceDataStructureInterface

Parameters:

term - the word to be added/updated with a line number.

lineNum - the line number where the word is found

showAll

Description copied from interface: ConcordanceDataStructureInterface

Display the words in Alphabetical Order followed by a :, followed by the line numbers in numerical order, followed by a newline here's an example: after: 129, 175 agree: 185 agreed: 37 all: 24, 93, 112, 175, 203 always: 90, 128

Specified by:

showAll in interface ConcordanceDataStructureInterface

Returns:

an ArrayList of Strings. Each string has one word, followed by a :, followed by the line numbers in numerical order, followed by a newline.

getWords

Returns an ArrayList of the words at this index [0] of the ArrayList holds the first word in the "bucket" (index) [1] of the ArrayList holds the next word in the "bucket", etc. This is used for testing

Specified by:

getWords in interface ConcordanceDataStructureInterface

Parameters:

index - location within the hash table

Returns:

an Arraylist of the words at this index

getPageNumbers

Returns an ArrayList of the Linked list of page numbers for each word at this index [0] of the ArrayList holds the LinkedList of page numbers for the first word in the "bucket" (index) [1] of the ArrayList holds the LinkedList of page numbers for next word in the "bucket", etc. This is used for testing

Specified by:

getPageNumbers in interface ConcordanceDataStructureInterface

Parameters:

index - location within the hash table

Returns:

an ArrayList of the Linked list of page numbers for each word at this index

Constructor Detail

Explanation / Answer

Answer:

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;


public class ConcordanceDataStructure implements ConcordanceDataStructureInterface {

        private static final int DEFAULT_SIZE = 257;
        LinkedList<ConcordanceDataElement>[] table;
        private LinkedList<ConcordanceDataElement> dummy = new LinkedList<ConcordanceDataElement>();

        public ConcordanceDataStructure(){
             

                table = (LinkedList<ConcordanceDataElement>[]) Array.newInstance(dummy.getClass(), DEFAULT_SIZE);

                for (int i = 0; i < DEFAULT_SIZE; i++){

                        table[i] = createNewLinkedList();
                }

                    }



        private LinkedList<ConcordanceDataElement> createNewLinkedList() {

                LinkedList<ConcordanceDataElement> list = new LinkedList<ConcordanceDataElement>();

                return list;
        }


      

        @Override
        public void add(String word, int lineNum) {

                ConcordanceDataElement dataElement = new ConcordanceDataElement(word);
                dataElement.addPage(lineNum);


                int index = Math.abs(dataElement.hashCode()) % table.length;
              
                LinkedList<ConcordanceDataElement> row = table[index];
                if(!row.contains(dataElement)){
                        row.add(dataElement);
                }
                else{
                        for (int i = 0; i < row.size(); i++){
                                ConcordanceDataElement oldElement = row.get(i);
                                if( oldElement.equals(dataElement)){

                                        if (!oldElement.getList().contains(lineNum)){
                                                oldElement.addPage(lineNum);
                                        }

                                        break;
                                }

                        }

                }

        }






        @Override
        public ArrayList<String> showAll() {


            
                ArrayList<String> showArray = new ArrayList<String>();

                for (int i = 0; i < table.length; i++){
                        LinkedList<ConcordanceDataElement> row = table[i];
                        for (int a = 0; a < row.size(); a++){
                                showArray.add(row.get(a).toString());
                        }
                }
                Collections.sort(showArray);              
                return showArray ;
        }



public static void main(String [ ] args){

        ConcordanceDataElement element1a = new ConcordanceDataElement("zebra");

        ConcordanceDataElement element2 = new ConcordanceDataElement("jocker");
        ConcordanceDataElement element3 = new ConcordanceDataElement("about");
     

     

        ConcordanceDataStructure structure1 = new ConcordanceDataStructure();
     
        structure1.add(element1a.getWord(),12);
        structure1.add("zebra",16);
        structure1.add("zebra",12);
        structure1.add(element3.getWord(), 23);
        structure1.add(element2.getWord(), 44);
        structure1.add("jocker",12);
     
        System.out.println(structure1.showAll());
     
}

}