Write a Java program that does the following. No start file given. (Remember to
ID: 3753753 • Letter: W
Question
Write a Java program that does the following. No start file given. (Remember to put throws Exception after main signature since you are opening a File ) Here is your input file: jumbles.txt
1) Expect the user must to put a filename on the comamnd line like this: C:>java Lab4 jumbles.txt
2) Use that args[0] value as the name of the input file and open it with a BufferedReader
3) Load eveyy line/word of that input file (one word per line) into an ArrayList of String
4) Sort that ArrayList of words
5) With every word of the ArrayList output a single line of output containing the word, a space, the canonical form of the word
Output should look like this:
addej addej ahicryrhe acehhirry alvan aalnv annaab aaabnn baltoc abclot braney abenry celer ceelr couph chopu cukklen cekklnu dica acdi dobeny bdenoy dobol bdloo dufil dfilu dupled ddelpu eslyep eelpsy ettniner eeinnrtt ettorp eoprtt genjal aegjln gluhc cghlu hartox ahortx hoybis bhiosy hucnah achhnu iddec cddei irrpo ioprr kutbec bcektu lappor aloppr lasia aails laurib abilru lubly blluy meefal aeeflm milit iilmt mopsie eimops mycall acllmy nekel eekln nokte eknot noper enopr nwae aenw nyegtr egnrty perrim eimprr preko ekopr pudmy dmpuy pypin inppy rebisc bceirs rodug dgoru rpeoims eimoprs shewo ehosw ardty adrtwy arllc acllrw aldde addelyExplanation / Answer
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; public class Lab4 { public static String canonical(String s) { char arr[] = s.toCharArray(); Arrays.sort(arr); String result = ""; for(int i = 0; i 0) { File file = new File(args[0]); BufferedReader br = new BufferedReader(new FileReader(file)); ArrayList list = new ArrayList(); String line; // read lines while ((line = br.readLine()) != null) { list.add(line); } // sort list list.sort(new Comparator() { @Override public int compare(String o1, String o2) { return o1.compareTo(o2); } }); // print list for(int i = 0; iRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.