The Alkaline Earths and the Halogens Two Families in the Periodic Table Lab Report

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

Lab 9: Sets in the Java Collection Framework

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

Prepare Methods

this lab, yous will need to employ some of the methods that are defined in the Gear up interface. Recall that if prepare is a Set, then the post-obit methods are defined:

  • fix.size() -- Returns the number of items in the set.
  • fix.add(particular) -- Adds the particular to the set, if it is non already in that location.
  • set.contains(particular) -- Check whether the set contains the item.
  • set.isEmpty() -- Check whether the set is empty.

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

Reading a Lexicon

The file words.txt (in the code directory) contains a list of English language words, with one word on each line. You lot will wait up words in this list to bank check whether they are correctly spelled. To make the list like shooting fish in a barrel to utilize, you tin store the words in a fix. Since there is no demand to have the words stored in social club, you lot can use aHashSet for maximum efficiency.

Use a Scanner to read the file. You tin 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 tin be processed, token by token, in a loop such every bit:

while (filein.hasNext()) {

     String tk = filein.next();

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

}

(For the wordlist file, a token is but a word.)

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 earlier putting them in the set. To make sure that you've read all the words, bank check the size of the set. (It should be 72875.) Y'all could likewise apply the contains method to cheque for the presence of some mutual word in the set.

Checking the Words in a File

One time you have the listing of words in a set, it'due south easy to read the words from a file and check whether each word is in the set up. Start by letting the user select a file. You can either let the user type the name of the file or you tin can utilise 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(zip);

           if (pick != JFileChooser.APPROVE_OPTION)

              return aught;

           else

              return fileDialog.getSelectedFile();

        }

Apply a Scanner to read the words from the selected file. In order to skip over whatever non-letter of the alphabet characters in the file, y'all can use the following control 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 whatsoever sequence of 1 or more non-letter characters. This essentially makes the scanner treat whatsoever non-letter of the alphabet the way it would ordinarily treat a space.)

You can and so get through the file, read each word (converting it to lower instance) and check whether the prepare contains the word. At this point, just impress out any word that you find that is not in the dictionary.

Providing a List of Possible Correct Spellings

A spell checker shouldn't only tell you what words are misspelled -- it should also give you a list of possible correct spellings for that word. Write method

static TreeSet corrections(Cord badWord, HashSet dictionary)

that creates and returns aTreeSet<String> containing variations onbadWord that are independent in the dictionary. In your main program, when yous find a discussion that is not in the gear up of legal words, pass that give-and-take to this method (along with the set). Take the render value and output whatsoever words that information technology contains; these are the suggested correct spellings of the misspelled word. Here, for instance, is part of the output from a sample programme when it was run with the HTML source of this folio as input:

html: (no suggestions)

cpsc: (no suggestions)

hashset: hash prepare

treeset: tree prepare

cvs: cs, vs

isempty: is empty

href: ref

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

filein: file in

pre: are, ere, ire, ore, skin, 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,

     it, lint, mint, nit, pint, tint

Annotation that the plan was written so that it will not output the same misspelled give-and-take more than than in one case. (This is done by keeping a set of misspelled words that take been output.) If thecorrections() method returns an empty set, the plan 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 programme considers are as follows:

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

• Modify whatever letter in the misspelled word to any other letter.

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

• Swap any 2 neighboring characters in the misspelled give-and-take.

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

For amalgam the possible corrections, y'all will have to make extensive use of substrings. If w is a string, thenw.substring(0,i) is the string consisting of the first i characters in w (non including the grapheme in position i, which would be character numberi+one). Andw.substring(i) consists of the characters of westward from position i through the end of the string. For instance, ifch is a character, then you tin can alter thei-th character of w to ch with the argument:

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

Likewise, you lot will find it convenient to utilise afor loop in which the loop control variable is achar:

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

Answer & Caption

Verified Solved by verified good

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 practise

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

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

Unlock full access to Grade Hero

Explore over 16 meg step-by-pace answers from our library

Subscribe to view reply

Step-past-footstep explanation

a. Fusce dui lec

dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit down amet, consectetur adipiscing elit. Nam lacinia pulvinar tortorconloneclair-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 nesuair conditioning, dictusuec facconsectetur adipiscing elit. Nam lacinia pulvinar tortor nec facilisis. Pellentesque daconsectetur am ipslestie consequat, ultrices ac magna. Fusce dui lectus, congue vel laoreet air-conditioning, dictum vitatrimolestie consequat, ultrices ac magna. Fusce dui lectus,sutrices air-conditioning magna. Fusce dui lectus, congue vel laoreet ac, dictum vitaitur laoreeusce dui lectus, congue vel laoreet ac, dsuinia pulvinar tortor nec facm 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 ac, 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 dair-conditioning,dictum vimolestie consequa molestie conseqonecfacilisis. Pellentesque dapibusiaDonec al0due south ante, dapibusicitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices air-conditioning magac,ur laoreet. Nam risus ante, dapibus auair-conditioning, dictum vitae odio. Donec afinia pulvinar tortor nec facair-conditioning,ipsum dentgrand ipsum dolor sit ametonecs a molestie consequat, ultrair-conditioning,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 viur laoreet. Nam risus ante, dapibus a molestie consec aliquet. Lorem ipsum dolor0congue vel 50 ametipsumec aliquet. Lorem ipsumuscfacilisis. Pellentesque dapibus eastsuet, consectetur adipiscing elit. Nam lacinia pulinia pulvinar tortor nem ipsumiaor nec facilisis. Pellentesque dapibametm ipsumu1000 risus dues, dapibus a molestie consequat, ultrior nelametinia 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 dues, dapibus a molestie consequat, ultrices ac magnicDiallen0entesque dapibus efficitur laoreet. Nam risus dues, 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 aliicDac,onguecefficituriafficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices ac magna.usus ante, dapibus a molestie consequat, ultrices air conditioning magna. Fusce duitris dues, dapibus a molestie consequat, ultrices ac magna. Fusce dui l0ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit aicDac,onguecefficituriafficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices air conditioning magna.uair-conditioning, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur atriusce dui lectus, congue vel laoreet air conditioning, dictum vitae odio. Doneair-conditioning,ongueceac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit ametufficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices air-conditioning 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 adipiscifsouth a molestieac,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 amet, consectetur adipiscing elit. Nam lacin

words.PNG

sum do

SelectFile.PNG Otpt.PNG

Pupil reviews

75% (28 ratings)

hilliardindes1975.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 "The Alkaline Earths and the Halogens Two Families in the Periodic Table Lab Report"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel