help with this project for java dictionarytxt a and as bear

help with this project for java,

dictionary.txt

a
and
as
bear
beef
brunt
century
consumers
corn
cost
drive
driving
drought
expected
feed
government
heat
in
is
milk
nearly
next
of
pork
price
said
some
states
sweltering
that
the
to
united
up
wednesday
worst
year

Program 1 (file I/O, String, method): Develop Typo Detection program v1.0. The program reads text file and find out typos. A dictionary file and the test file will be posted on our course website. Dictionary File (dictionary.txt) Test File (test.txt) The worsst drought in the United States in neearly a century is expected to drive up the price of milk, beef and pork next yeer, the government said Wednesdaay, as consumers bear some of the bruntt of the sweltering heat that is drivng up the cost of feed corrn Depending on your program execution time, you may get bonus points The example of program 1 is as follows. Start Program The worsst drought in the United States in eearly a century is expected to drive up the price of milk, beef and pork next *yeeer, the government said *Wednesdaay*, as consumers bear some of the bruntt of the seltering heat that is drivng up the cost of feed corrn Execution time: 3 seconds (Hint) It is allowed to use java\'s String class to compare two strings. Example of String comparison (compare stringl to string2) String string1 = \"abc\" String string2 = \"def\"; String string2 - \"det\" if (stringl.equals (string2)) // this line wil1 not print because the // java string equals method returns false: ystem.out.printin (\"The two strings are the same.\"

Solution

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

public class TypoExample {

   public static void main(String[] args) {
       // TODO Auto-generated method stub

       Scanner scanner = null;
       try {
           scanner = new Scanner(new File(\"dictionary.txt\"));

           List<String> dictonary = new ArrayList<String>();
           while (scanner.hasNext()) {
               dictonary.add(scanner.next());

           }
           scanner.close();
           scanner = new Scanner(new File(\"test.txt\"));

           Iterator<String> it = null;
           while (scanner.hasNext()) {
               String word = scanner.next();
               it = dictonary.iterator();
               boolean flag = false;
               while (it.hasNext()) {
                   String string1 = it.next();
                   if (string1.contains(word)
                           || string1.equalsIgnoreCase(word)
                           || (word.substring(0, word.length() - 1)
                                   .equalsIgnoreCase(string1) && word
                                   .contains(\",\"))) {
                       // System.out.println(word);

                       flag = true;
                       break;

                   }
               }
               if (flag == false)
                   System.out.print(\" *\" + word + \"*\");
               else
                   System.out.print(\" \" + word);
           }

       } catch (Exception e) {
           // TODO: handle exception
       } finally {
           if (scanner != null)
               scanner.close();

       }

   }

}

dictionary.txt:
a
and
as
bear
beef
brunt
century
consumers
corn
cost
drive
driving
drought
expected
feed
government
heat
in
is
milk
nearly
next
of
pork
price
said
some
states
sweltering
that
the
to
united
up
wednesday
worst
year

test.txt:
The worsst drought in the United States in neearly a century is expected to drive up the price of milk, beef
and pork next yeer, the government said Wednesdaay, as consumers bear some of the bruntt of the sweltering
heat that is driving up the cost of feed corrn.

OUTPUT:

The *worsst* drought in the United States in *neearly* a century is expected to drive up the price of milk, beef and pork next *yeer,* the government said
*Wednesdaay,* as consumers bear some of the *bruntt* of the sweltering heat that is *drivng* up the cost of feed *corrn.*

help with this project for java, dictionary.txt a and as bear beef brunt century consumers corn cost drive driving drought expected feed government heat in is m
help with this project for java, dictionary.txt a and as bear beef brunt century consumers corn cost drive driving drought expected feed government heat in is m
help with this project for java, dictionary.txt a and as bear beef brunt century consumers corn cost drive driving drought expected feed government heat in is m

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site