This part of the code searches for every word in the text file and saves it to an ArrayList. It searches for the word if its valid of not.
How can I offer a list of similar words when the word that the user inputs is not in the dictionary. Also I want it to prompt the user to accept the word or enter a replacement that gets saved in the dictionary.
package spellChecker.project1; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class SpellChecker { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out .println("Enter the path of the dict txt file(C:/Users/Stalin/Desktop/dictionary.txt):"); String path = scanner.nextLine(); String myFileName = path; int count = -1; int count2 = 0; List<String> words = new ArrayList<String>(); try { FileReader myFile = new FileReader(myFileName); Scanner scanMyFile = new Scanner(myFile); while (scanMyFile.hasNext()) { String line = scanMyFile.next(); // System.out.println(line); words.add(line); count++; //System.out.println(words.get(count)); } scanMyFile.close(); // System.out.println(count + " words"); } catch (FileNotFoundException e) { e.printStackTrace(); } System.out.println("Please enter a word:"); String typeword = scanner.next(); for (int i = 0; i < count; i++) { String word = words.get(i); // System.out.println(word); if (typeword.equals(word)) { System.out.println(typeword + " is a valid word in the dict."); } if (!typeword.equals(word)) { count2++; } if (count == count2) { System.out.println(typeword + " is an invalid word in the dict."); } } } }
thank you guys