Pages for Baby Bedding Sets Facebook in Karachi

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

Lab 9: Sets in the Coffee Collection Framework

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

Ready Methods

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

  • set.size() -- Returns the number of items in the prepare.
  • set.add(detail) -- Adds the item to the set, if information technology is not already at that place.
  • ready.contains(item) -- Check whether the set contains the item.
  • fix.isEmpty() -- Cheque whether the set is empty.

You volition also need to be able to traverse a set, using either an iterator or a for-each loop.

Reading a Dictionary

The file words.txt (in the code directory) contains a listing of English words, with one discussion on each line. You volition look up words in this list to check whether they are correctly spelled. To make the listing easy to apply, yous tin store the words in a prepare. Since there is no demand to accept the words stored in lodge, you can use aHashSet for maximum efficiency.

Utilize a Scanner to read the file. You can create scanner,filein, for reading from a file with a statement such as:

                     filein = new Scanner

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

and that a file can be processed, token by token, in a loop such every bit:

while (filein.hasNext()) {

     String tk = filein.next();

     process(tk); // practise something with the token

}

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

Commencement your chief program by reading the words from words.txt and storing them in aHashSet<Cord>. For the purposes of this program,catechumen all words to lower case before putting them in the set. To brand certain that y'all've read all the words, check the size of the prepare. (It should be 72875.) You lot could also utilise the contains method to bank check for the presence of some common discussion in the set.

Checking the Words in a File

Once y'all take the list of words in a set, information technology's easy to read the words from a file and check whether each word is in the set. Start past letting the user select a file. Yous can either let the user type the name of the file or y'all can employ 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 zip.

         */

        static File getInputFileNameFromUser() {

           JFileChooser fileDialog = new JFileChooser();

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

           int selection = fileDialog.showOpenDialog(null);

           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-alphabetic character characters in the file, you lot can apply 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 any sequence of i or more non-letter characters. This essentially makes the scanner care for whatsoever non-alphabetic character the fashion information technology would ordinarily care for a space.)

Yous can then go through the file, read each word (converting it to lower case) and check whether the fix contains the word. At this bespeak, merely print out any word that y'all find that is non in the lexicon.

Providing a List of Possible Right Spellings

A spell checker shouldn't just tell y'all what words are misspelled -- information technology should besides give you a list of possible correct spellings for that give-and-take. Write method

static TreeSet corrections(Cord badWord, HashSet lexicon)

that creates and returns aTreeSet<Cord> containing variations onbadWord that are contained in the dictionary. In your chief programme, when you find a word that is not in the set of legal words, pass that word to this method (forth with the set). Take the return value and output whatsoever words that it contains; these are the suggested right spellings of the misspelled word. Here, for example, is role of the output from a sample program when it was run with the HTML source of this folio as 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 next

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,

     information technology, lint, mint, nit, pint, tint

Annotation that the program was written then that information technology volition not output the aforementioned misspelled word more in one case. (This is done past keeping a set of misspelled words that accept been output.) If thecorrections() method returns an empty ready, the programme outputs the message "(no suggestions)". Since the corrections are stored in a tree set, they are automatically printed out in alphabetical club with no repeats.

The possible corrections that the plan considers are as follows:

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

• Modify any letter of the alphabet in the misspelled word to any other letter.

• Insert any letter of the alphabet at any indicate in the misspelled discussion.

• Swap any ii neighboring characters in the misspelled word.

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

For constructing the possible corrections, you will accept to make extensive use of substrings. If w is a string, thenw.substring(0,i) is the cord consisting of the first i characters in w (non including the grapheme in position i, which would be graphic symbol numberi+1). Anddue west.substring(i) consists of the characters of w from position i through the cease of the string. For example, ifch is a graphic symbol, then you can change thei-thursday graphic symbol of due west to ch with the statement:

String southward = westward.substring(0,i) + ch + w.substring(i+1);

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

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

Reply & Explanation

Verified Solved by verified adept

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 consten

Unlock full access to Grade Hero

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

Subscribe to view answer

Step-by-step explanation

a. Fusce dui lec

dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit down amet, consectetur adipiscing elit. Nam lacinia pulvinar tortorconlonecfiftyac, 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 am 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 ac, dictum vitaitur laoreeusce dui lectus, congue vel laoreet ac, dsuinia pulvinar tortor nec fack ipsat, ultrices air conditioning magna. Fusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetuuFusce dui lectus, congue vel laoreet ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit down amet,tring elit. Nam lacinia pulvinar tortor nec facilisis. Pellsucongue vel laoreet air conditioning, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit down 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 magazineac,ur laoreet. Nam risus dues, dapibus auac, dictum vitae odio. Donec afinia pulvinar tortor nec facac,ipsum dentthou ipsum dolor sit down ametonecs a molestie consequat, ultrac,ipsum dusceFusce dui lectus, congue vel laoreet air-conditioning, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit apulv, consectetur adipiscing elit. Nam lacinia pulvinar tortac,dictum 6ur laoreet. Nam risus dues, 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 nethousand ipsumiaor nec facilisis. Pellentesque dapibamet1000 ipsumuchiliad 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 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 ante, dapibus a molestie consequat, ultrtrictum vitae odio. Donec aliicDair conditioning,onguecefficituriafficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices air conditioning 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 aicDac,onguecefficituriafficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna.uair conditioning, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur atriusce dui lectus, congue vel laoreet ac, dictum vitae odio. Doneair-conditioning,ongueceac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit down 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 molestieac,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 exercise

SelectFile.PNG Otpt.PNG

Student reviews

75% (28 ratings)

bryanlovid1967.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 "Pages for Baby Bedding Sets Facebook in Karachi"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel