Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The Assignment You do not get a starter file. You must write it completely from

ID: 3809563 • Letter: T

Question

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 the dictionary.txt and jumbles.txt I will test with.

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

tinyJumbles.txt

tinyCorrectOuput.txt.

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.

Thank you so much!! And I will rate this!!

Explanation / Answer

import java.io.*;
import java.util.*;

public class Main {
  
//List for Collecting permutations of word
static ArrayList<String> perms;
  
//This method calculates the permutations of the string using recursion and stores in the above list.
static void genPerms(char str[], int ind){
if(ind==str.length-1){
perms.add(String.valueOf(str));
return;
}
for(int i=ind;i<str.length;i++){
char ch = str[i];
str[i] = str[ind];
str[ind] = ch;
genPerms(str, ind+1);
ch = str[i];
str[i] = str[ind];
str[ind] = ch;
}
}
public static void main(String[] args) throws IOException {
//Reading the dictionary into a set
String dict = args[0];
BufferedReader f1 = new BufferedReader(new FileReader(new File(dict)));
String word;
HashSet<String> hs = new HashSet();
while((word = f1.readLine())!=null){
hs.add(word);
}   
  
//Reading the words
String jumbles = args[1];
BufferedReader f2 = new BufferedReader(new FileReader(new File(jumbles)));
  
//List for storing final answer
ArrayList<String> fans = new ArrayList();
  
//Iterating through all the jumble words
while((word = f2.readLine())!=null){
//finding permutations
perms = new ArrayList();
genPerms(word.toCharArray(),0);
String ans = word;
//Storing perms in a List
ArrayList<String> hor = new ArrayList();
for(String x : perms){
if(hs.contains(x)){
hor.add(x);
}
}
//Sorting the list
Collections.sort(hor);
//Calculating the answer
for(String x : hor){
ans = ans+" "+x;
}
fans.add(ans);
}
  
//Sorting the answer vertically
Collections.sort(fans);
for(String x : fans){
System.out.println(x);
}
}
}


OUTPUT :
P:>java Main P:/dict.txt P:/jumbles.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 glossy