Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab 4: use jumbles.txt [(http://people.cs.pitt.edu/~hoffmant/S18-401/) --> click on daily outline on the right ----> scroll down/click on lab4 -----> scroll down and click on jumbles.txt

Lab 4: use jumbles.txt [(http://people.cs.pitt.edu/~hoffmant/S18-401/) --> click on daily outline on the right ----> scroll down/click on lab4 -----> scroll down and click on jumbles.txt

Also for more information, use the instructions above and read the helpful tools and look at the sample output on the page before clicking on jumbles.txt.

Y O U R L A B # 4 A S S I G N M E N T

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). Your input file is 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 every 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

Make sure to use :

static String canonical( String word )

{ // assume word is "zebra"

char[] letters = word.toCharArray(); // letters: [z][e][b][r][a]

Arrays.sort( letters ); // letters: [a][b][e][r][z]

return new String( letters ); // String allows initialize with char arr

} // END CANONICAL

}

and don't forget to sort the output in abc order (this is where i got lost someone gave me some tip in my last question but, i still don't totally get it need to see it in action. (also I found that someone already posted this question but, the output is totally incorrect since they didn't incorporate a piece of code that sorts it in abc order.

sample output :

image text in transcribed

Command Prompt C:Users tim\Desktop\lab-04>java Lab4 jumbles.txt 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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