Programming Assignment Unit 5 Java
Programming Assignment Unit 5 Java
My code is initiated by calling important classes and packages for file handling, scanning, and
collections. thhe (SpellChecker) class contains the main method where the spell checking
functionality is implemented. The main method first calls the (readDictionary) method, passing the
filename "words.txt", to read the words from the dictionary file and store them in a HashSet called
(dictionary).
It then prompts the user to select an input file using the getInputFileNameFromUser method, which
opens a file selection dialog and returns the selected file.
The selected file is then read using a Scanner, and non-letter characters are skipped by setting the
delimiter with in.useDelimiter("[^a-zA-Z]+");. This ensures that only words consisting of letters are
considered.
Each word from the input file is converted to lowercase and checked against the dictionary HashSet. If
the word is not found in the dictionary, it is added to the misspelledWords set.
My Java Code:
>>>import java.io.File;
>>>import java.io.FileNotFoundException;
>>>import java.util.HashSet;
>>>import java.util.Scanner;
>>>import java.util.Set;
>>>import java.util.TreeSet;
>>>import javax.swing.JFileChooser;
>>> if (dictionary.isEmpty()) {
>>> return;
>>> }
>>> File inputFile = getInputFileNameFromUser();
>>> return;
>>> }
>>> try {
>>> fileScanner.useDelimiter("[^a-zA-Z]+");
>>> if (!dictionary.contains(word)) {
>>> misspelledWords.add(word);
>>> }
>>> }
>>> fileScanner.close();
>>> return;
>>> }
>>> if (corrections.isEmpty()) {
>>> } else {
>>> }
>>> System.out.println();
>>> }
>>> }
>>> }
>>> try {
>>> dictionary.add(word);
>>> }
>>> fileScanner.close();
>>> }
>>> }
>>> corrections.add(deleted);
>>> }
>>> if (dictionary.contains(changed)) {
>>> corrections.add(changed);
>>> }
>>> if (dictionary.contains(inserted)) {
>>> corrections.add(inserted);
>>> }
>>> if (dictionary.contains(swapped)) {
>>> corrections.add(swapped);
>>> }
>>> if (dictionary.contains(withSpace)) {
>>> corrections.add(withSpace);
>>> }
>>> }
>>> }
>>> }
>>> }
>>> }
>>> public static File getInputFileNameFromUser() {
>>> } else {
>>> }
>>> }
>>>}