Concepts tested by this program

Hash Table,
Link List,
hash code, buckets/chaining,
exception handling, read/write files (FileChooser)

A concordance lists every word that occurs in a document in alphabetical order, and for each word it gives the line number of every line in the document where the word occurs.

Write a program that creates a concordance. There will be two ways to create a concordance. The first requires a document to be read from an input file, and the concordance data is written to an output file. The second reads the input from a string and returns an ArrayList of strings that represent the concordance of the string.

Because they are so common, don't include the words "the" or and in your concordance. Also, do not include words that have length less than 3. Strip out all punctuation, except apostrophes that occur in the middle of a word, i.e. lets, wed, etc.

Data Elements ConcordanceDataElement, implements Comparable< ConcordanceDataElement> and consists of a String (the word) and a reference to a LinkedList< Integer> (list of line numbers where word occurs). Follow the Javadoc provided for you.

Data Structure ConcordanceDataStructure, Implements the ConcordanceDataStructureInterface Interface that is provided. You will be implementing a hash table with buckets. It will be an array of linked list of ConcordanceDataElements. The add method will take a word and a line number to be added to the data structure. If the word already exists, the line number will be added to the linked list for this word. If the line number for the word already exists, dont add it again to the linked list. (i.e. if Sarah was on line 5 twice, the first line 5 would be added to the linked list for Sarah, the second one would not). If the word doesnt exist, create a ConcordanceDataElement and add it to the HashTable. Two constructors will be required, one that takes in an integer that is the estimated number of words in the text, the other is used for testing purposes. Look at the provided Javadoc.

Data Manager ConcordanceDataManager Implements the ConcordanceDataManagerInterface interface that is provided. The data manager allows the client (user) to create a concordance file or a concordance list (ArrayList of strings). The input is read (from a file or string) and is added to the data structure through the add method. The add method requires a word and a line number. The line number is incremented every time a newline appears in the file or the string.

GUI driver

  • Do not allow the user to create a concordance file until they have entered an input file and an output file
  • Show the text area only when the option to create from text is chosen.
  • Use a FileChooser for the user to select the input and output files.
  • Inform the user if there is an error with the input file or the output file
  • Use exception handling (try/catch) for the validity of the files.
  • If creating a concordance from text, make sure the user has entered some text in the text area. Inform user if text area is empty.
  • Display the concordance from the text in the text area.
  • Provide a way for the user to clear the text area.

Example of creating a Concordance from an input file see image.

Select an input file and an output file. PrideAndPrejudice.txt was used. Sample of output file: see image.

Example of Creating a Concordance from text: see image.

Using Create Concordance button displays Concordance in text area see image.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.