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

Program #6 requires you to read an input file line by line and scramble each wor

ID: 3652667 • Letter: P

Question

Program #6 requires you to read an input file line by line and scramble each word on that line. Once those words are scrambled you must print the line out with the words in the original order (but scrambled) to an output file. This proccess repeats for each line of the input file.

With each line from the input file you will also print the original words from that line to the screen but sorted by their length rather than alphabetical order.



/*
PROGRAM #6

ALGORITHM:

For each line in the input file
Split the line into an array of words
For each word
split word into an array of chars
shuffle all the chars randomely (but leave first and last chars alone)
make a new String out of the char array
write that new scrambled word to the output file followed by a space
Write a newline to the outfile
Sort that array of words (original unscrambled) by length - shortest to longest
Print those words to the screen all on a single line in their sorted order

close files
*/

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


public class Program6
{
// This is an instance member of the class and is "global" to all the code
// You don't have to pass it in to the methods of this class. All the code in this file can see this variable

static Random r = new Random( 17 ); // We seed the generator for repeatable results

public static void main (String[] args) throws IOException
{
// GIVEN AS IS . DO NOT MODIFY. IT VERIFIES THAT THE USER PUT A WORD ON THE COMMAND LINE

if (args.length < 2 ) // Failed to enter input file and output file names
{
System.out.println("FATAL CMD LINE ERROR: Must enter a name of input file and name of output file on the command line! ");
System.exit(0);
}

Scanner infile = new Scanner( new FileReader( args[0] ) );
PrintWriter outfile = new PrintWriter( args[1] );

} // END MAIN

} //END CLASS PROGRAM6

Explanation / Answer

Hi, This question is worth at least 4 posts.

Please post the question 4 more times. I will post the answer on all the 4 posts.

You please rate all the 4 posts high.

Below is the output screenshot of the program:

I will provide the source code in the other 4 posts:

====================================================

Output screenshots:

====================================================

File input.txt


===========================================================

File output.txt

===========================================================

Output Screenshot:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote