The Assignment
You do not get a starter file. You must write it completely from scratch.
Your 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 ion the line.
Here is a tiny version of each input that you should test with
until you are sure your code is correct:
tinyDictionary.txt and tinyJumbles.txt and correct output for it
them: tinyCorrectOuput.txt.
tinyDictionary.txt
act cat tac dog god post pots stop spot tops opts rat tar art trap tarp part flog golf frog gorp glossy
tinyJumbles.txt
atc otsp gdo atr arpt grof sylogs
tinyCorrectOuput.txt.
arpt part tarp trap atc act cat tac atr art rat tar gdo dog god grof frog otsp opts post pots spot stop tops sylogs glossy
Here is the correct execution command and output from a sample run of your program YOUR OUTPUT MUST MATCH EXACTLY. Notice the list of jumbles words is sorted vertically and the matching dictionary words that come after are sorted left to right.
java Project8 dictionary.txt jumbles.txt 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
Thank you so much!! And I will rate this!!
Screenshot of the code:




Sample Input File:


Sample Output:

Sample Output File:

Code to copy:
//Import the required packages.
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.TreeSet;
//Define the class CorrectOutput.
public class CorrectOutput
{
//Start the execution of the main()
//method.
public static void main(String[] args)
throws IOException
{
//Get the file names from the command
//line arguements.
String fname1= args[0];
String fname2 = args[1];
//Declare the required variables to
//store lines of two files.
String curr_line1;
String curr_line2;
//Create an array list of strings.
List<String> list_1 = new
ArrayList<String>();
//Create an object of the class buffered
//reader to read a file.
BufferedReader br = new BufferedReader
(new FileReader("D:/files/"+fname1));
//Read a line of the first file.
curr_line1 = br.readLine();
//Create an array list of strings.
List<String> list_2 = new
ArrayList<String>();
//Create an object of the class buffered
//reader to read the files.
BufferedReader br2 = new BufferedReader
(new FileReader("D:/files/"+fname2));
//Read the line of the second file.
curr_line2 = br2.readLine();
//Start the while loop till there is no
//lines left.
while (curr_line1 != null)
{
//Add the current line to the list 1.
list_1.add(curr_line1);
//Read the line of the second file.
curr_line1 = br.readLine();
}
//Start the while loop till there are no
//lines left in the second file.
while (curr_line2 != null)
{
//Add the lines of the second file to
//the list2.
list_2.add(curr_line2);
//Read the line of the second file.
curr_line2 = br2.readLine();
}
//Close both files.
br.close();
br2.close();
//Create an object of the class tree set.
TreeSet<String> tset = new TreeSet<String>();
//Start the for each loop over the list 2.
for(String words : list_2)
{
//Convert the jumbled words into the
//character array.
char[] arrayOfJumble = words.toCharArray();
//Sort the character array of jumbled
//words.
Arrays.sort(arrayOfJumble);
//Create a new string of character array
//of jumbled words.
String sortedJumbleWords = new String
(arrayOfJumble);
//Store each word into the resultant string.
String res = words;
//Traverse over the list 1.
for(String dict_items : list_1)
{
//Convert the items of the dictionary
//to a character array.
char[] arrayOfDictItems =
dict_items.toCharArray();
//Sort the array of dictionary
//elements.
Arrays.sort(arrayOfDictItems);
//Create a new string of sorted
//character array.
String sortedDictItems = new String
(arrayOfDictItems);
//If the sorted jumbled string is equal
//to the sorted dictionary string.
if(sortedJumbleWords.equalsIgnoreCase
(sortedDictItems))
{
//Add the dictionary items to the
//resultant string.
res += " " + dict_items;
}
}
//Display the resultant string.
System.out.println(res);
//Add the resultant string to the tree set.
tset.add(res);
}
//Create an object of the class print writer to
//write to the output file.
PrintWriter outfile = new PrintWriter(new
FileWriter("D:/files/tinyCorrectOutput.txt"));
//Start the for each loop over the tree set.
for(String str: tset)
{
//Write the string retrieved from the tree
//set to the file.
outfile.println(str);
}
//Close the output file.
outfile.close();
}
}
//tinyDictionary.txt:
act
cat
tac
dog
god
post
pots
stop
spot
tops
opts
rat
tar
art
trap
tarp
part
flog
golf
frog
gorp
glossy
//tinyJumbles.txt:
atc
otsp
gdo
atr
arpt
grof
sylogs
The Assignment You do not get a starter file. You must write it completely from scratch....
# DISCUSSION SECTION WORK: # # 1. STUDENTS: download this file, ds4.py, and wordsMany.txt, from # http://www.cs.uiowa.edu/~cremer/courses/cs1210/etc/ds4/ # Save both in the same folder. # # 2. TA (aloud) and STUDENTS: Read the comments from START HERE! (just after these instructions) # to definition of anagramInfo function. Discuss any questions about what the functions should do. # # 3. TA demonstrate running anagramInfo("wordsMany.txt") on this unchanged file, to # see that it behaves reasonably despite having incomplete anagram-testing functions. #...