Question: I need help with removing duplicate permutations in java. It is very important that there is no usage of SETS or any other implementation of

I need help with removing duplicate permutations in java. It is very important that there is no usage of SETS or any other implementation of SETS!

What I have so far.

package permutation;

import java.io.*; // needed for File, FileReader, and BufferedReader classes import java.util.ArrayList; import java.util.Iterator; import java.util.Scanner;

/** * * @author kevin */

public class permutationsconsole { private static ArrayList createDictionary() throws FileNotFoundException { FileReader dictionary = new FileReader("wordsEn.txt"); BufferedReader reader = new BufferedReader(dictionary); ArrayList words = new ArrayList<>(); String line = null; // to store each of the values and place them in the arraylist try { while((line = reader.readLine()) != null) // as long as reader can find the next word, keep iterating. { words.add(line); } } catch (IOException ex) { ex.printStackTrace(); } return words; // this will return the list of valid english words from the text file } private static ArrayList filterEnglishWords(ArrayList l) throws FileNotFoundException { ArrayList valid = createDictionary(); l.retainAll(valid); return l; // this needs to be corrected } private ArrayList removeDuplicateWords(ArrayList words) { // I need help implementing this method } private void writeListToFile(ArrayList data) throws IOException { FileWriter writer = new FileWriter("/yourpath/to/output.txt", true); for (String str : data) { writer.write(str); writer.write(" "); }

writer.close();

} private void writeStringToFile(String data) throws IOException { FileWriter writer = new FileWriter("/yourpath/to/output.txt", true); // this needs to be corrected as well. writer.write(data); writer.write(" "); writer.close(); } public static void main(String args[]) throws FileNotFoundException { File output = new File("perms.dat"); // file that will hold the permutations ArrayList dictionary = createDictionary(); // the ArrayList that is returned by this method is stored in a new ArrayList. Scanner kbd = new Scanner(System.in); boolean isDone = false; do { System.out.println("Type in a word and this program will calculate its permutations."); String word = kbd.nextLine(); for(int i = 0; i < 1; i++) { permutationscalculator pc = new permutationscalculator(word); } System.out.println("Would you like to continue?(y/n)"); char quit = kbd.nextLine().charAt(0); if(quit == 'y') { isDone = true; } else { isDone = false; } }while(isDone == true); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!