CSC XXXXXXXXXXAssignment 4: Using Java HashMap 1. Overview For this assignment, you will write a simple but efficient spell-checking program. Your program will first read in a dictionary of about...

1 answer below »
I need to do this assignment


CSC 275 Assignment 4: Using Java HashMap 1. Overview For this assignment, you will write a simple but efficient spell-checking program. Your program will first read in a dictionary of about 25,000 words (provided for you), and then spell check a user-inputted document of words. The goals of this assignment are to:  Gain experience working Java HashMap and HashSet  Gain experience using the Java API. In particular you will find the APIs for ArrayList, HashMap, HashSet and Strings useful. 2. Detailed specifications 2.1 Data structures Your program must maintain the following data structures:  A java HashSet to store words from the dictionary.  A java HashMap that stores misspelled words of a file as keys whose associated value is a list of the file line numbers where the misspelled word appears. Thus the HashMap will have type > .  A java ArrayList that stores each line of the file as a separate element. All spell checking updates to lines of the file will be reflected here. 2.2 Program Flow Loading Dictionary. The program starts by asking the user to enter the name of a dictionary file and then loads each word from the dictionary into the HashSet. A dictionary file on canvas. Processing the file to be spell checked. The user is prompted to enter the name of a file to spell check. The program should parse this file word by word and load the HashMap with each misspelled word mapped to a list of the line numbers where it appears. Any word not appearing in the dictionary is considered a misspelled word. While parsing the file, the Arraylist should be populated with each line of the file as a separate element. At the end of this phase all the misspelled words and the line numbers they appear have been identified. Correction Mode: The user will have a choice to update misspelled words in order of appearance in the file. In correction mode, each misspelled words should be displayed in order of appearance. The misspelled word should be displayed within the current line it appears on. The misspelled word should be surrounded by <>>. For example, the line below should be shown when the user is correcting the word twinkx. Then the user should be asked the following: (1) If the user chooses “line” or “all”, prompt them to enter a replacement word:  If user selected line, all appearances of the misspelled word on the current line should be replaced with the replacement word. If this misspelled word appears on another line, the user should have a choice to replace it again.  If the user selected all, all appearances of the misspelled word in the file should be replaced with the replacement word. The user should not be prompted for this misspelled word again. These updates should be reflected in ArrayList fileLine. (2) If the user chooses “none” the word should not be updated, and the user should not be prompted again for any other appearance of this word. (3) If the user choose something else, they should be re-prompted to enter a valid value Final Results: After the entire file is spell checked, the program should display the corrected contents of the file by printing out the elements of the ArrayList. 2.3 SpellChecker.java A skeleton of the program is provided for you in SpellChecker.java. (1) Constructor: initialize the data structures (2) loadDictionary(String fname): Add words from the dictionary file and to the dictionary HashSet (3) processFile(String fname): Parse the file being spell checked. Call the loadMisspelledWords method on each word not found in the dictionary. (4) loadMisspelledWords(String word, int lineNum). Given a word not in the dictionary and the line number it appears on, this method loads the word and its associated lineNumber into the HashMap. (5) correctionMode(). Your task is to implement this method to run spell check mode as described above. See project 4 slides for high level algorithm. (6) replace( String word, String replace, int lineNo): Replace all occurrences of the given word on line lineNo with the replace. (7) outputResult(): Output the changes by printing out the elements of Arraylist. 2.4 Grading Criteria 1. Program correctness 2. Uses program design principals 3. All methods commented with purpose, assumption, input, output (or in other clear non- wordy format) 4. Used JAVA API methods when available rather than rewriting own logic 5. The program output looks like samples given. (Hint: use constants of SpellChecker.java) 6. Uses the variables, constants, methods and program design in SpellChecker.java (Hint: This implies that you need to read and understand the code given) 3. Sample Run The following shows a sample run on file: twinkx twinkx lottle star how I lottle lamb its a warld of laughter a warld of tears Enter the name of the dictionary : dictionary Enter the name of the file to check : smallex>> lottle star how I Replace in line, all or none? (line, all, none) line Enter replacement twinkle twinkle twinkle > star how I Replace in line, all or none? (line, all, none) all Enter replacement little twinkle twinkle little star how > Replace in line, all or none? (line, all, none) none little lamb > a warld of laughter a Replace in line, all or none? (line, all, none) none little lamb its a > of laughter a Replace in line, all or none? (line, all, none) line Enter replacement world> of tears Replace in line, all or none? (line, all, none) line Enter replacement WOOOOOORRRRRRLLLLLLLDDDDD WOOOOOORRRRRRLLLLLLLDDDDD of > Replace in line, all or none? (line, all, none) none twinkle twinkle little star how I little lamb its a world of laughter a WOOOOOORRRRRRLLLLLLLDDDDD of tears Note that the user is not prompted for each misspelled word > on line 2 since the user choose to replace all in line 1. On the other hand the user is prompted on line 2 and 3 for> since the user chose to replace just on the line 2 the first time. Here is another sample run that shows error checking for user inputs: 4. Submission  Submit your java code.  Also answer the following question: o Separation of concerns: Find an example of its usage o Design for reuse: Find an example of its usage
Answered Same DayDec 03, 2021

Answer To: CSC XXXXXXXXXXAssignment 4: Using Java HashMap 1. Overview For this assignment, you will write a...

Arun Shankar answered on Dec 05 2021
145 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here