banner



How Much Is Laundry Service At Sheraton Dubrovnik

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

Lab 9: Sets in the Java Collection Framework

For this week'south lab, you lot will use 2 of the classes in the Java Collection Framework:HashSet andTreeSet. You lot will use these classes to implement a spell checker.

Set Methods

this lab, y'all volition demand to use some of the methods that are defined in the Set interface. Think that if set is a Set, then the post-obit methods are defined:

  • set.size() -- Returns the number of items in the set.
  • set.add together(detail) -- Adds the item to the set, if information technology is not already there.
  • set.contains(item) -- Check whether the set contains the particular.
  • ready.isEmpty() -- Check whether the set is empty.

You will also demand to be able to traverse a fix, using either an iterator or a for-each loop.

Reading a Dictionary

The file words.txt (in the lawmaking directory) contains a list of English words, with one discussion on each line. You will wait upwards words in this listing to bank check whether they are correctly spelled. To make the list easy to utilise, you can store the words in a set up. Since at that place is no need to accept the words stored in order, yous tin use aHashSet for maximum efficiency.

Utilise a Scanner to read the file. You lot tin 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 can be processed, token by token, in a loop such equally:

while (filein.hasNext()) {

     String tk = filein.next();

     procedure(tk); // practise 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 fix. To brand sure that you've read all the words, check the size of the ready. (It should be 72875.) You could too employ the contains method to bank check for the presence of some common word in the prepare.

Checking the Words in a File

Once you lot take the listing of words in a ready, information technology's easy to read the words from a file and bank check whether each give-and-take is in the prepare. Outset by letting the user select a file. You can either let the user type the proper noun of the file or yous tin use the following method:

        /**

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

         * choice 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(nil);

           if (selection != JFileChooser.APPROVE_OPTION)

              render goose egg;

           else

              return fileDialog.getSelectedFile();

        }

Use a Scanner to read the words from the selected file. In lodge to skip over any non-alphabetic character characters in the file, you tin can use the following command just after creating the scanner (where in is the variable name for the scanner):

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

(In this statement, "[^a-zA-Z]+" is a regular expression that matches whatsoever sequence of one or more not-letter characters. This essentially makes the scanner care for whatsoever not-letter the mode it would ordinarily care for a space.)

You lot can then go through the file, read each discussion (converting it to lower instance) and check whether the set contains the discussion. At this point, but print out whatever word that you find that is not in the dictionary.

Providing a Listing of Possible Right Spellings

A spell checker shouldn't but tell you what words are misspelled -- it should likewise give you lot a listing of possible correct spellings for that word. Write method

static TreeSet corrections(String badWord, HashSet dictionary)

that creates and returns aTreeSet<Cord> containing variations onbadWord that are contained in the lexicon. In your primary program, when you discover a word that is not in the set up of legal words, laissez passer that word to this method (forth with the fix). Take the return value and output any words that information technology contains; these are the suggested correct spellings of the misspelled word. Here, for example, is part of the output from a sample program when information technology was run with the HTML source of this folio every bit input:

html: (no suggestions)

cpsc: (no suggestions)

hashset: hash prepare

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,

      casualty, pro, pry, pure, pyre, re

hasnext: has next

wordlist: give-and-take 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 program was written so that information technology will not output the same misspelled discussion more than than once. (This is washed by keeping a set of misspelled words that have been output.) If thecorrections() method returns an empty set, the program outputs the message "(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 one of the messages from the misspelled word.

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

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

• Swap whatsoever ii neighboring characters in the misspelled give-and-take.

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

For amalgam the possible corrections, yous will have to make extensive use of substrings. If w is a string, thenw.substring(0,i) is the cord consisting of the start i characters in w (non including the character in position i, which would exist character numberi+ane). Andwest.substring(i) consists of the characters of w from position i through the end of the string. For example, ifch is a grapheme, so you can modify thei-thursday graphic symbol of w to ch with the argument:

String due south = due west.substring(0,i) + ch + w.substring(i+1);

Also, you volition find it convenient to use afor loop in which the loop control variable is achar:

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

Answer & Explanation

Verified Solved past verified skillful

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 do

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

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

Unlock full access to Form Hero

Explore over 16 one thousand thousand step-by-stride answers from our library

Subscribe to view reply

Footstep-by-stride explanation

a. Fusce dui lec

dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortorconfiftyonecfiftyair-conditioning, dictumrisus sumiametiur licetm ipsum dolo,dictum vitae odio. Donec aliquet. Lorem ipsum dolorsua molestie consequat, ultrices air-conditioning magna. Fusce dui lectufng elit. Nia pulvinar tortor nesuac, dictusuec facconsectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque daconsectetur ak ipslestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet air conditioning, dictum vitatrimolestie consequat, ultrices ac magna. Fusce dui lectus,sutrices ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitaitur laoreeusce dui lectus, congue vel laoreet ac, dsuinia pulvinar tortor nec facone thousand ipsat, ultrices ac magna. Fusce dui lectus, congue vel laoreet air conditioning, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit down 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 ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consecteturac,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 dentthou ipsum dolor sit ametonecsouth a molestie consequat, ultrac,ipsum dusceFusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit apulv, consectetur adipiscing elit. Nam lacinia pulvinar tortac,dictum half-dozenur laoreet. Nam risus ante, dapibus a molestie consec aliquet. Lorem ipsum dolor0congue vel l ametipsumec aliquet. Lorem ipsumuscfacilisis. Pellentesque dapibus esuet, consectetur adipiscing elit. Nam lacinia pulinia pulvinar tortor nem ipsumiaor nec facilisis. Pellentesque dapibametm ipsumum risus ante, dapibus a molestie consequat, ultrior ne50ametinia 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 amet, cuitur laoreet. Nam risus dues, dapibus a molestie consequat, ultrtrictum vitae odio. Donec aliicDair-conditioning,onguecefficituriafficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna.usus ante, dapibus a molestie consequat, ultrices air conditioning magna. Fusce duitris ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui l0ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit down aicDair conditioning,onguecefficituriafficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna.uac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur atriusce dui lectus, congue vel laoreet air conditioning, dictum vitae odio. Doneac,ongueceac, 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 ante, 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 amet, consectetur adipiscing elit. Nam lacin

words.PNG

sum practise

SelectFile.PNG Otpt.PNG

Pupil reviews

76% (29 ratings)

How Much Is Laundry Service At Sheraton Dubrovnik,

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

Posted by: yonyoublicut.blogspot.com

0 Response to "How Much Is Laundry Service At Sheraton Dubrovnik"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel