Does Fred Know Nick Is Junes Babies Father

Lab 9: Sets in the Java Drove Framework For this week's lab,...

Lab 9: Sets in the Coffee Drove Framework

For this week's lab, you will apply two of the classes in the Java Drove Framework:HashSet andTreeSet. Yous volition use these classes to implement a spell checker.

Fix Methods

this lab, you will need to use some of the methods that are defined in the Set interface. Recall that if set up is a Set, then the following methods are defined:

  • gear up.size() -- Returns the number of items in the set.
  • set.add(item) -- Adds the item to the gear up, if it is not already there.
  • set up.contains(item) -- Cheque whether the set contains the item.
  • set.isEmpty() -- Check whether the set is empty.

You will also need to exist able to traverse a gear up, using either an iterator or a for-each loop.

Reading a Lexicon

The file words.txt (in the lawmaking directory) contains a listing of English language words, with one discussion on each line. You will look upward words in this list to bank check whether they are correctly spelled. To make the list easy to use, you tin can store the words in a fix. Since there is no demand to have the words stored in order, you lot tin can use aHashSet for maximum efficiency.

Use a Scanner to read the file. You can create scanner,filein, for reading from a file with a argument such every bit:

                     filein = new Scanner

(new File("/classes/s09/cs225/words.txt"));

and that a file tin can be processed, token by token, in a loop such as:

while (filein.hasNext()) {

     String tk = filein.side by side();

     procedure(tk); // do something with the token

}

(For the wordlist file, a token is simply a discussion.)

Start your main program by reading the words from words.txt and storing them in aHashSet<String>. For the purposes of this program,convert all words to lower case before putting them in the set up. To make sure that you lot've read all the words, check the size of the set. (It should exist 72875.) You lot could likewise employ the contains method to cheque for the presence of some mutual give-and-take in the prepare.

Checking the Words in a File

Once you accept the list of words in a set, information technology's piece of cake to read the words from a file and check whether each word is in the fix. Start past letting the user select a file. You lot tin can either let the user type the name of the file or yous tin use the following method:

        /**

         * Lets the user select an input file using a standard file

         * selection dialog box. If the user cancels the dialog

         * without selecting a file, the return value is null.

         */

        static File getInputFileNameFromUser() {

           JFileChooser fileDialog = new JFileChooser();

           fileDialog.setDialogTitle("Select File for Input");

           int option = fileDialog.showOpenDialog(cypher);

           if (option != JFileChooser.APPROVE_OPTION)

              return null;

           else

              return fileDialog.getSelectedFile();

        }

Use a Scanner to read the words from the selected file. In order to skip over any non-letter of the alphabet characters in the file, you can use the following command just after creating the scanner (where in is the variable proper noun for the scanner):

in.useDelimiter("[^a-zA-Z]+");

(In this statement, "[^a-zA-Z]+" is a regular expression that matches any sequence of one or more than non-letter characters. This essentially makes the scanner treat any non-letter of the alphabet the manner it would commonly treat a space.)

You tin then go through the file, read each word (converting information technology to lower case) and cheque whether the fix contains the discussion. At this point, only print out any give-and-take that you find that is not in the dictionary.

Providing a List of Possible Correct Spellings

A spell checker shouldn't just tell you what words are misspelled -- information technology should also requite you a listing of possible correct spellings for that discussion. Write method

static TreeSet corrections(String badWord, HashSet lexicon)

that creates and returns aTreeSet<Cord> containing variations onbadWord that are contained in the dictionary. In your main program, when y'all observe a give-and-take that is non in the set of legal words, pass that word to this method (along with the set up). Have the return value and output any words that it contains; these are the suggested correct spellings of the misspelled word. Here, for case, is part of the output from a sample program when it was run with the HTML source of this folio every bit input:

html: (no suggestions)

cpsc: (no suggestions)

hashset: hash set

treeset: tree set

cvs: cs, vs

isempty: is empty

href: ref

txt: tat, tet, text, tit, tot, tut

filein: file in

pre: are, ere, ire, ore, pare, pee, per, pie, poe, pore, prep, pres,

      prey, pro, pry, pure, pyre, re

hasnext: has adjacent

wordlist: word list

getinputfilenamefromuser: (no suggestions)

jfilechooser: (no suggestions)

filedialog: file dialog

setdialogtitle: (no suggestions)

int: ant, dint, hint, in, ina, inc, ind, ink, inn, ins, inti, into,

     it, lint, mint, nit, pint, tint

Note that the plan was written so that it volition not output the same misspelled word more than once. (This is done past keeping a set up of misspelled words that have been output.) If thecorrections() method returns an empty set, the program outputs the bulletin "(no suggestions)". Since the corrections are stored in a tree set, they are automatically printed out in alphabetical order with no repeats.

The possible corrections that the program considers are as follows:

• Delete any 1 of the letters from the misspelled word.

• Change whatsoever letter in the misspelled word to any other letter.

• Insert any letter at any point in the misspelled word.

• Swap any two neighboring characters in the misspelled word.

• Insert a space at any point in the misspelled word (and cheque that both of the words that are produced are in the dictionary)

For amalgam the possible corrections, you will have to brand extensive utilize of substrings. If w is a string, and thenwestward.substring(0,i) is the string consisting of the outset i characters in w (not including the graphic symbol in position i, which would be character numberi+i). Andw.substring(i) consists of the characters of westward from position i through the end of the cord. For example, ifch is a character, so yous can change thei-th character of westward to ch with the statement:

Cord s = w.substring(0,i) + ch + w.substring(i+i);

Too, you will notice it convenient to use afor loop in which the loop control variable is achar:

for (char ch = 'a'; ch <= 'z'; ch++) { ...

Respond & Caption

Verified Solved by verified expert

Rated Helpful

entesq

consectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentes

ce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum exercise

rem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar torto

,ur laoreet. Nam risus ante, dapibus a molestie consx

Unlock full admission to Form Hero

Explore over 16 million step-past-step answers from our library

Subscribe to view respond

Step-past-footstep caption

a. Fusce dui lec

dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortorconloneclac, dictumrisus sumiametiur licetgrand ipsum dolo,dictum vitae odio. Donec aliquet. Lorem ipsum dolorsua molestie consequat, ultrices ac magna. Fusce dui lectufng elit. Nia pulvinar tortor nesuac, dictusuec facconsectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque daconsectetur achiliad ipslestie consequat, ultrices air conditioning magna. Fusce dui lectus, congue vel laoreet ac, dictum vitatrimolestie consequat, ultrices air-conditioning magna. Fusce dui lectus,sutrices ac magna. Fusce dui lectus, congue vel laoreet air conditioning, dictum vitaitur laoreeusce dui lectus, congue vel laoreet air-conditioning, dsuinia pulvinar tortor nec facyard ipsat, ultrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetuuFusce dui lectus, congue vel laoreet air conditioning, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet,tring elit. Nam lacinia pulvinar tortor nec facilisis. Pellsucongue vel laoreet air conditioning, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consecteturair conditioning,lestie consequat, ucea molestie consequctum vitae odio. Donec aliquet. Lorem ipsum dac,dictum vimolestie consequa molestie conseqonecfacilisis. Pellentesque dapibusiaDonec al0s ante, dapibusicitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magac,ur laoreet. Nam risus ante, dapibus auac, dictum vitae odio. Donec afinia pulvinar tortor nec facair conditioning,ipsum dentm ipsum dolor sit ametonecdue south a molestie consequat, ultrac,ipsum dusceFusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit down apulv, consectetur adipiscing elit. Nam lacinia pulvinar tortac,dictum half dozenur laoreet. Nam risus ante, dapibus a molestie consec aliquet. Lorem ipsum dolor0congue vel fifty ametipsumec aliquet. Lorem ipsumuscfacilisis. Pellentesque dapibus esuet, consectetur adipiscing elit. Nam lacinia pulinia pulvinar tortor nem ipsumiaor nec facilisis. Pellentesque dapibamet1000 ipsumugrand risus ante, dapibus a molestie consequat, ultrior nelametinia ponectesque dapor neamet, consectetur adipiscing elit. Nam ametongue velipsum dolorto. Donec aliquet. Lorem ipsum dolo,sum dolor sit down amet, consectetur adipiscing elsuitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magnicDiallen0entesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie conse0cing elit. Nam lacinia pulvinar tortor nec facilisfctum vitae odio. Donec aliquet. Lorem ipsum dolor sit down amet, cuitur laoreet. Nam risus dues, dapibus a molestie consequat, ultrtrictum vitae odio. Donec aliicDac,onguecefficituriafficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna.usus ante, dapibus a molestie consequat, ultrices ac magna. Fusce duitris dues, dapibus a molestie consequat, ultrices ac magna. Fusce dui 500ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit aicDac,onguecefficituriafficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna.uac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit down amet, consectetur atriusce dui lectus, congue vel laoreet air conditioning, dictum vitae odio. Washedac,ongueceair conditioning, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit ametufficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui lectus, conguetrinec facilisis. Pellentesque dapibus efficitur laoreeticDiallenfentesque dapibus efficitur laoreet. Nam risus ante, dapibus a molestie conse0rem ipfs a molestieac,amet, consectetur adipiscifs a molestieair conditioning,fficitur laoreet. Nam risus dues, dapibus a molestie consequat, ultricf, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consecteuitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrtring elit. Nam lacinia pulvinaor neo. Donec aliquet. Lorem ipsu

, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit down amet, consectetur adipiscing elit. Nam lacin

words.PNG

sum do

SelectFile.PNG Otpt.PNG

Student reviews

75% (28 ratings)

handevandood.blogspot.com

Source: https://www.coursehero.com/tutors-problems/Java-Programming/21112512-Lab-9-Sets-in-the-Java-Collection-Framework-For-this-weeks-lab-you/

0 Response to "Does Fred Know Nick Is Junes Babies Father"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel