How To Repair Taros Items Mu
Lab 9: Sets in the Java Drove Framework For this week's lab,...
Lab 9: Sets in the Coffee Collection Framework
For this week's lab, you lot volition use 2 of the classes in the Java Drove Framework:HashSet andTreeSet. You volition apply these classes to implement a spell checker.
Gear up Methods
this lab, you will demand to use some of the methods that are defined in the Gear up interface. Recall that if ready is a Set, and then the following methods are defined:
- set.size() -- Returns the number of items in the set.
- set.add(item) -- Adds the item to the set, if information technology is not already there.
- set.contains(item) -- Check whether the set contains the detail.
- set.isEmpty() -- Check whether the prepare is empty.
You will besides 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 list of English words, with one give-and-take on each line. You will look upward words in this list to cheque whether they are correctly spelled. To make the list like shooting fish in a barrel to utilise, yous can shop the words in a prepare. Since in that location is no need to have the words stored in order, you tin apply 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 equally:
filein = new Scanner
(new File("/classes/s09/cs225/words.txt"));
and that a file can be processed, token by token, in a loop such as:
while (filein.hasNext()) {
String tk = filein.next();
process(tk); // do something with the token
}
(For the wordlist file, a token is simply a word.)
Outset your main programme past reading the words from words.txt and storing them in aHashSet<String>. For the purposes of this program,convert all words to lower example before putting them in the set. To make sure that y'all've read all the words, check the size of the ready. (It should be 72875.) Y'all could also use the contains method to check for the presence of some common word in the set.
Checking the Words in a File
Once you have the list of words in a set up, information technology's piece of cake to read the words from a file and check whether each word is in the set up. Showtime by letting the user select a file. You tin can either allow the user type the proper noun of the file or y'all tin use the post-obit method:
/**
* Lets the user select an input file using a standard file
* option dialog box. If the user cancels the dialog
* without selecting a file, the render value is nada.
*/
static File getInputFileNameFromUser() {
JFileChooser fileDialog = new JFileChooser();
fileDialog.setDialogTitle("Select File for Input");
int pick = fileDialog.showOpenDialog(null);
if (pick != JFileChooser.APPROVE_OPTION)
return null;
else
render fileDialog.getSelectedFile();
}
Utilize a Scanner to read the words from the selected file. In order to skip over any non-letter characters in the file, you 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 any sequence of ane or more non-letter characters. This essentially makes the scanner treat whatsoever not-letter the way information technology would unremarkably treat a infinite.)
You can then go through the file, read each word (converting information technology to lower case) and check whether the set contains the word. At this point, but print out any word that y'all find that is not in the dictionary.
Providing a List of Possible Right Spellings
A spell checker shouldn't just tell you what words are misspelled -- information technology should too give you a list of possible correct spellings for that discussion. Write method
static TreeSet corrections(String badWord, HashSet dictionary)
that creates and returns aTreeSet<String> containing variations onbadWord that are independent in the dictionary. In your main program, when you find a word that is non in the set of legal words, pass that word to this method (along with the set). Have the return value and output whatsoever words that it contains; these are the suggested correct spellings of the misspelled word. Hither, for example, is office of the output from a sample programme when it was run with the HTML source of this page as input:
html: (no suggestions)
cpsc: (no suggestions)
hashset: hash fix
treeset: tree fix
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,
it, lint, mint, nit, pint, tint
Note that the plan was written then that it will not output the aforementioned misspelled discussion more than once. (This is done by keeping a set 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 social club with no repeats.
The possible corrections that the program considers are every bit follows:
• Delete whatsoever one of the messages from the misspelled word.
• Change whatever letter in the misspelled word to any other letter.
• Insert any alphabetic character at any point in the misspelled give-and-take.
• Bandy any 2 neighboring characters in the misspelled give-and-take.
• Insert a space at any point in the misspelled word (and check that both of the words that are produced are in the dictionary)
For constructing the possible corrections, yous volition have to make extensive use of substrings. If due west is a cord, thenwest.substring(0,i) is the string consisting of the beginning i characters in w (not including the character in position i, which would be character numberi+1). Anddue west.substring(i) consists of the characters of westward from position i through the end of the string. For case, ifch is a character, then you can alter thei-thursday character of w to ch with the statement:
String s = w.substring(0,i) + ch + w.substring(i+one);
Too, you lot 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
Solved past verified expert
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 total access to Course Hero
Explore over 16 million footstep-by-pace answers from our library
Subscribe to view respond
Step-by-step explanation
a. Fusce dui lec
dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam lacinia pulvinar tortorconlonec50ac, dictumrisus sumiametiur licet1000 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 ac magna. Fusce dui lectus, congue vel laoreet ac, dictum vitatrimolestie consequat, ultrices air conditioning magna. Fusce dui lectus,sutrices air-conditioning magna. Fusce dui lectus, congue vel laoreet air conditioning, dictum vitaitur laoreeusce dui lectus, congue vel laoreet air conditioning, dsuinia pulvinar tortor nec facm ipsat, ultrices air conditioning magna. Fusce dui lectus, congue vel laoreet air conditioning, 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 down amet, consecteturac,lestie consequat, ucea molestie consequctum vitae odio. Donec aliquet. Lorem ipsum dair-conditioning,dictum half dozenmolestie consequa molestie conseqonecfacilisis. Pellentesque dapibusiaDonec al0s ante, dapibusicitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices air conditioning magac,ur laoreet. Nam risus ante, dapibus auac, dictum vitae odio. Donec afinia pulvinar tortor nec facair conditioning,ipsum dentm ipsum dolor sit ametonecs a molestie consequat, ultrac,ipsum dusceFusce dui lectus, congue vel laoreet air-conditioning, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit down apulv, consectetur adipiscing elit. Nam lacinia pulvinar tortac,dictum viur 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 nethou 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 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 aliicDac,onguecefficituriafficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices air conditioning magna.usus dues, dapibus a molestie consequat, ultrices air-conditioning magna. Fusce duitridue south ante, dapibus a molestie consequat, ultrices ac magna. Fusce dui 500ac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit aicDair conditioning,onguecefficituriafficitur laoreet. Nam risus ante, dapibus a molestie consequat, ultrices air-conditioning magna.uac, dictum vitae odio. Donec aliquet. Lorem ipsum dolor sit amet, consectetur atriusce dui lectus, congue vel laoreet air-conditioning, dictum vitae odio. Washedac,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 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
sum practice
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: lunasearly1971.blogspot.com

0 Response to "How To Repair Taros Items Mu"
Post a Comment