Question: Please help me write this program in java. The program should take two command args: a dictionary file and a jumbles file. For each jumbled
Please help me write this program in java. The program should take two command args: a dictionary file and a jumbles file. For each jumbled word you must find all the matching dictionary words and print them after the jumbled word on the line. Below is an example output. Below is also a pseudo code for the program.
addej jaded ahicryrhe hierarchy alvan naval annaab banana baltoc cobalt braney nearby celer creel couph pouch cukklen knuckle dica acid cadi caid dobeny beyond dobol blood dufil fluid dupled puddle eslyep sleepy ettniner renitent ettorp potter genjal jangle gluhc gulch hartox thorax hoybis boyish hucnah haunch iddec diced irrpo prior kutbec bucket lappor poplar lasia alias laurib burial lubly bully meefal female milit limit mopsie impose mycall calmly nekel kneel nokte token noper prone nwae anew wane wean nyegtr gentry perrim primer preko poker pudmy dumpy pypin nippy rebisc scribe rodug gourd rpeoims imposer promise semipro shewo howes whose wardty tawdry warllc yaldde deadly
verify that args.length is at least 2. if not exit with an error message that you must put the dictionary & jumbles file on command line define 3 ArrayList named dictionary, jumbles and answerKey read the dictionary file into the dictionary list and read the jumbles file into the jumbles list use a buffered reader sort both lists using Collections.sort( yourarraylist ); STEP#1 BUILD THE ANSWER KEY for each dictionary word dWord // i.e dWord = "spot" String dCanon = toCanon( dWord ); // dCanon = " opst" (canonical copy ofthe dictionary word) int index = bsearch( answerKey, dCanon ); // search the answerKey list for a string that .startsWith( dCanon ); if there is such a string in answerKey go to that string and tack on: " " + spot // answerKey.set( index, answerKey.get(index) + " " + dWord ); if there is no such string in the answerKey your search should have returned a negative index to tell you where it belongs convert that negative index like you did in a prev. project insert a new string into the answerKey: opst + " " + spot // answerKey.add(index, dWord + " " + dCanon ); end for each word in dictioanry list YOU NOW HAVE AN ANSWER KEY BUILT. STEP #2 PRINT EACH JUMBLES WORD DOWN THE LEFT SIDE OF THE SCREEN FOLLOWED BY ANY DICTIONARY WORDS THAT MATCH for each jumbled word jWord in the jumbles list // i.e. jWord = "sopt" System.out.print( jWord + " " ); String jCanon = toCanon( jWord ); // jCanon = "opst" (canonical version of the jumbled word) int index = bsearch( answerKey, jCanon ); // search the answerKey list for a string that .startsWith( jCanon ); if there is such a string in answerKey println that string but only print the part of the string after the first word inside the string if there is no such string in the answerKey just do System.out.println(); end for each jWord in the jumbles list YOU MUST WRITE A BSEARCH METHOD you must write a bsearch like you wrote for a recent project you must change one line. Do not test for .equals() Test for .startsWith() i.e. if (answerKey.get(mid).startsWith( canonPrefix ) ) return mid; YOU NEED a toCanon() method that makes a copy of a String but with its letters sorted alphabetically static string toCanon( String s ) { char[] letters = s.toCharArray(); // letters -> [z][e][b][r][a] Arrays.sort( letters ); // letters -> [a][b][e][r][z] return new String( letters ); // "aberz" } YOU MUST WRITE A BSEARCH METHOD
You must write a bsearch like you wrote for a recent project, but you must change one line. Do not test for .equals(). instead test for .startsWith().
if (answerKey.get(i).startsWith( canonPrefix ) ) return mid
YOU NEED a toCanon() method that makes a copy of a String but with its letters sorted alphabetically
static string toCanon( String s ) { char[] letters = s.toCharArray(); // letters -> [z][e][b][r][a] Arrays.sort( letters ); // letters -> [a][b][e][r][z] return new String( letters ); // "aberz" } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
