⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spellcheckerdriver.java

📁 拼写检查器
💻 JAVA
字号:
package 拼写检查器;

import java.io.*;
import java.util.*;

public class SpellCheckerDriver {

	protected SpellChecker spellChecker;

	// protected GUI gui;
	protected boolean readingDictionaryName;

	public SpellCheckerDriver() {
		final String DICTIONARY_PROMPT = "\n\nIn the Input line,please "
				+ "enter the name of the name of the dictionary file.";
		spellChecker = new SpellChecker();
		// gui=new GUI(this);
		readingDictionaryName = true;
		System.out.println(DICTIONARY_PROMPT);
	}

	public void processInput(String s) {
		final String DOCUMENT_PROMPT = "\n\nPlease enter the name of the document file.";
		final String ALL_CORRECT = "\n\nAll the words are spelled correctly.";
		final String MISSPELLED = "\n\nThe following words are possibly misspelled: ";
		final String CLOSE_WINDOW_PROMPT = "\n\nThe execution of the project is complete. Please close "
				+ "this window when you are ready.";
		LinkedList misspelled;
		if (readingDictionaryName) {
			if (dictionaryFilewasRead(s)) {
				System.out.println(DOCUMENT_PROMPT);
				readingDictionaryName = false;
			}
		} else {
			if (documentFilewasRead(s)) {
				misspelled = spellChecker.compare();
				if (misspelled == null)
					System.out.println(ALL_CORRECT);
				else
					System.out.println(MISSPELLED + misspelled);
				System.out.println(CLOSE_WINDOW_PROMPT);
				// gui.freeze();
			}
		}
	}

	public boolean dictionaryFilewasRead(String s) {
		final Object IO_EXCEPTION_MESSAGE = "null";
		final String DICTIONARY_HAVING = "Here are the contents of the dictionary file: ";
		final String NO_DICTIONARY_FILE_FOUND_MESSAGE = "The dictionary file was not found.\n\n";
		String word;
		boolean success = false;
		try {
			BufferedReader dictionaryReader = new BufferedReader(
					new FileReader(s));
			success = true;
			while ((word = dictionaryReader.readLine()) != null)
				spellChecker.addToDictionary(word);
		} catch (FileNotFoundException e) {
			System.out.println(NO_DICTIONARY_FILE_FOUND_MESSAGE
					+ DICTIONARY_HAVING);
		} catch (IOException e) {
			System.out.println(IO_EXCEPTION_MESSAGE);
		}
		return success;
	}

	public boolean documentFilewasRead(String s) {
		final Object IO_EXCEPTION_MESSAGE = null;
		final String DOCUMENT_PROMPT = "\n\nPlease enter the name of the document file.";
		final String DOCUMENT_HAVING = "Here are the contents of the dictionary file: ";
		final String NO_DOCUMENT_FILE_FOUND_MESSAGE = "The dictionary file was not found.\n\n";
		String word;
		boolean success = false;
		try {
			BufferedReader dictionaryReader = new BufferedReader(
					new FileReader(s));
			success = true;
			while ((word = dictionaryReader.readLine()) != null)
				spellChecker.addToWordSet(word);
		} catch (FileNotFoundException e) {
			System.out.println(NO_DOCUMENT_FILE_FOUND_MESSAGE + DOCUMENT_PROMPT);
		} catch (IOException e) {
			System.out.println(IO_EXCEPTION_MESSAGE);
		}
		return success;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -