Question: write a java program :write it as a java program : Introduction In this project, you will be designing and implementing a custom dictionary to

write a java program :write it as a java program :Introduction

In this project, you will be designing and implementing a custom dictionary to check the spelling of word. A custom dictionary allows you to supplement the dictionary with additional new words.

Your task

Your task is to design and implement an algorithm for a simple spell checker. The spell checker should work as follows: ask the user to enter a statement/ line. Process each word separately and checks its spelling against a custom dictionary data structure of words to determine if it is a valid English. Any words that are not found in the dictionary will be printed on the screen. User can add this word to the custom dictionary.

Consider the following sample output

Welcome to spell check enter:

To print the dictionary

Check the spelling of a sentence

Quit

Enter a choice: 1

A the as mat sat I my cat yours rat fat you in out me for we from bag will week day saturday sunday monday tuesday wednesday friday next

1. To print the dictionary

2. Check the spelling of a sentence

3. Quit

Enter a choice: 2

Please enter your sentence:

I will attand a conference next week

attand does not exist in the dictionary, add to the dictionary ( Y for Yes N for No): N

conference does not exist in the dictionary, add to the dictionary ( Y for Yes N for No): Y

conference has been added to the dictionary

1. To print the dictionary

2. Check the spelling of a sentence

3. Quit

Enter a choice: 1

A the as mat sat I my cat yours rat fat you in out me for we from bag will week day saturday sunday monday tuesday wednesday friday next conference

1. To print the dictionary

2. Check the spelling of a sentence

3. Quit

Enter a choice: 3

Thanks, Have a good day

Hints:

Take a look first at the format of the list of words in the dictionary.txt documents. (They will be available from the class webpage). You will have to parse the input. The punctuation is already separated from the words, so you do not have to worry about that. You will have to read one word at a time and add it to your data structure. Your program should accept the upper/lower cases letters

You have the freedom to select the data structures and algorithms that you consider to be more efficient for this task. Of course, you will have to justify your decisions.

How to read from a file:

For every word, you should store a list of documents where it occurs, in order to allow for efficient searches and Boolean operators later on.

Here is a simple example that opens a file, reads a text file and stores the information in an array data structure.

importjava.io.File;

importjava.util.Scanner;

importjava.io.FileNotFoundException;

//This class demonstrates reading a text file and storing them into an array

public class ReadFileIntoArray {

public static void main(String[] args) {

inti = 0;

try {

String[] words = new String[5000]; //Assuming the input file has max size of 5000 words

Scanner input = new Scanner(System.in); //Scanner object for keyboard input

System.out.print( "Enter the filename: " ); // Prompt the user for a file name

String fileName = input.nextLine(); // get a file name from the user

//If the full path is not given, then, the file must be on the same folder as the source java file.

//Otherwise, the user must give the full path

File inputFile = new File(fileName ); // create a File object

//Another Scanner object for file input

Scanner fileInput = new Scanner(inputFile);

while (fileInput.hasNext()) //Read from file as long as you have strings

{

words[i] = fileInput.next(); //Read a single string and store it in the array

i++;

}

//Verify that you have the words stored in the array

for (i = 0; i

System.out.print(words[i] + " ");

} catch (FileNotFoundException e) {

System.out.println(e.getMessage());

}

}

}

If you want, you can cut and paste this program and run it exactly as it is. That is about all there is to opening and reading files in Java.

You also need to record the total time of your program. This time should include the time to read the key words, create the hash table, read the text file, and record all the statistics. It is suggested that you start a timer as one of the first things you do in the program and stop it immediately before printing out the statistics. The following is a little sample code that shows how you can time events. You need to use the Date class to do it so you may want to check out the documentation on this method at the Java API web site. Do not worry about the Thread.sleep() method in the program - you do not (and should not) be using this function. It only appears here to simulate some kind of work being done.

importjava.util.*;

class Timer {

public static void main(String[] args) {

try {

// start the timer

Date timeStart = new Date();

/* .

.

Do the actual program work here

..

..

*/

// stop the timer

Date timeEnd = new Date();

// calculate the total time and print the result

longtotalTime = timeEnd.getTime() - timeStart.getTime();

System.out.println("Total Time: " + totalTime);

} catch(InterruptedException e) { }

}

}

Again, you can copy and run this code exactly as it appears to see what the output is.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!