Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

WE ARE USING A SMALL DICT FILE LIKE THIS: act cat tac dog god post pots stop spot tops opts rat tar art trap tarp

WE ARE USING A SMALL DICT FILE LIKE THIS: act cat tac dog god post pots stop spot tops opts rat tar art trap tarp part flog golf frog gorp gloss slogs AND A SMALL JUMBLES FILE LIKE THIS: atc sopt gdo atr arpt grof sygols STEP#1 DECLARE AN ARRAYLIST OF STRING NAMED: pairs STEP#2 OPEN A BUFFERED READER NAMED dFile while ( dfile.ready() ) { READ A WORD INTO A STRING NAMED dWord // assume the dWord read in is "stop" .add a single string to pairs list that looks like this: "opst stop" where the first word inside the string is the canonical of the dWord and the word after the space in the middle is the original dWord } SORT YOUR PAIRS LIST USING Colections.sort( pairs ); SEE DEMO CODE LINKED ON COURSE WEBPAGE YOUR pairs ARRAYLIST WILL NOW LOOK LIKE THIS without the quotes of course but they show that each line is a single string with an imbedded space "act act" "act cat" "act tac" "aprt part" "aprt tarp" "aprt trap" "art art" "art rat" "art tar" "dgo dog" "dgo god" "fglo flog" "fglo golf" "fgor frog" "gloss gloss" "gloss slogs" "gopr gorp" "opst opts" "opst post" "opst pots" "opst spot" "opst stop" "opst tops" STEP#3 DECLARE TWO ARRAYLISTS OF STRING NAMED dCanons and dWords STEP#4 LOOP THRU EVERY STRING IN YOUR PAIRS ARRAY. SPLIT THAT STRING INTO THE TWO SEPARATE WORDS AND PUT THE FIRST IN THE dCanons LIST PUT THE 2nd IN THE dWords LIST USE AN ENHANCED FOR LOOP AND ASSIGN EACH STRING INTO A VARIABLE NAMED line { String[] pair = line.split( "\\s+); // you could have used line.split( " " ); // BUT the "\\s+" handles if you accidentlly put two/more spaces in between .add pair[0] to the dCanons list .add pair[1] to the dWords list } NOW YOUR DCANON AND DWORDS LISTS NOW OOK LIKE THIS DCANONS DWORDS [00] act [00]: act [01] act [01]: cat [02] act [02]: tac [03] aprt [03]: part [04] aprt [04]: tarp [05] aprt [05]: trap [06] art [06]: art [07] art [07]: rat [08] art [08]: tar [09] dgo [09]: dog [10] dgo [10]: god [11] fglo [11]: flog [12] fglo [12]: golf [13] fgor [13]: frog [14] gloss [14]: gloss [15] gloss [15]: slogs [16] gopr [16]: gorp [17] opst [17]: opts [18] opst [18]: post [19] opst [19]: pots <-- binarySearch returned this index: 19 [20] opst [20]: spot [21] opst [21]: stop [22] opst [22]: tops STEP #5 READ YOUR JUMBLES FILE INTO AN ARRAYLIST NAMED jWords AND THEN SORT IT STEP#6 USING AN ENHANCED FOR LOOP ASSIGN EVERY WORD FROM YOUR jWords LIST INTO A VAR NAMED jWord FOR (.......) { print jWord and a " " ( NOT a NEWLINE YET) // ASSUME JWORD IS: "sopt" jCanon = toCanonical( jWord ); // CANONICAL WILL BE: "opst" CALL THE BINARY SEARCH METHOD IN THE COLLECTIONS LIBRARY FEED THE BINARYSEARCH TWO VALUES: YOUR dCanons list AND YOUR jCanon word index = Collections.binarySearch( dCanons, jCanon ); IF THE INDEX COMES BACK NEGATIVE IT MEANS NO MATCH FOUND. THERE ARE NO DICT WORDS THAT ARE EQUIVALENT TO THIS JUMBLED WORD. YOU CAN PRINT A NEWLINE. ELSE LETS ASSUME bsearch returns you the number 19 LOOK IN THE LISTS ABOVE YOU CAN SEE THAT BSEARCH BROUGHT YOU AN INDEX THAT IS IN THE MIDDLE OF A CHUNK OF HITS YOU MUST WRITE A LITTLE LOOP OR TWO THAT DOES THE FOLLOWING WALK BACKWARD TILL YOU FIND THE VERY TOPMOST dCanon word that equals jCanon "opst" THEN START LOOPING DOWNWARD PRINTING EACH DICT WORD AT SAME INDEX IN THE OTHER LIST WHEN YOU REACH A jCanons WORD THAT IS NO LONGER equals TO YOUR jCanon word PRINT A NEWLINE. (YOU ARE DONE WITH THI JUMBLED WORD GO BACK UP AN DO THe NEXT ONE) } FINAL OUTPUT IS atc cat tac atr art rat tar gdo dog god grof frog sopt opts post pots spot stop tops sygols 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What are the advantages of using software as a service (SaaS)?

Answered: 1 week ago

Question

LOQ 15-5: Do psychological disorders predict violent behavior?

Answered: 1 week ago

Question

Prepare for a successful job interview.

Answered: 1 week ago

Question

Describe barriers to effective listening.

Answered: 1 week ago

Question

List the guidelines for effective listening.

Answered: 1 week ago