I have to make a java code that takes jumbled words from an input file called jumbles.txt and sorts them in alpabetical order
1. Expect the user must to put a filename on the command 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
expected output:
addej addej
ahicryrge acehhirry
alvan aalnv
etc.
here is the file words:
addej
ahicryrhe
alvan
annaab
baltoc
braney
celer
couph
cukklen
dica
dobeny
dobol
dufil
dupled
eslyep
ettniner
ettorp
genjal
gluhc
hartox
hoybis
hucnah
iddec
irrpo
kutbec
lappor
lasia
laurib
lubly
meefal
milit
mopsie
mycall
nekel
nokte
noper
nwae
nyegtr
perrim
preko
pudmy
pypin
rebisc
rodug
rpeoims
shewo
wardty
warllc
yaldde
copy to code:
Jumbled.java file is :
package normalClasses;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
public class Jumbled {
public static void main(String[] args) throws IOException {
//check the length of arguments
if (args.length < 1 )
{
//if arguments are not there show error
System.out.println("\nInput file missing in argument\n\n");
System.exit(0);
}
//define array list of words
ArrayList<String> words = new ArrayList<>();
//buffer reader for file read
BufferedReader infile = new BufferedReader( new FileReader(args[0]) );
//while not end of file
while ( infile.ready() )
{
//add string to arraylist
words.add(infile.readLine());
}
//sort the array
Collections.sort(words);
//now loop through list
for(int i=0;i<words.size();i++){
//get the word at index
String inString = words.get(i);
//convert string to char array
char tempArray[] = inString.toCharArray();
//sort char array
Arrays.sort(tempArray);
//create string from char array
String reverseString = new String(tempArray);
//show string and canonical from
System.out.println(inString+" "+reverseString);
}
infile.close();
}
}
jumbled.txt
output:
make sure jumbled.txt file is in the same folder where class file is there.
I have to make a java code that takes jumbled words from an input file called...
I need help writing this code for java class. Starter file: Project3.java and input file: dictionary.txt Project#3 is an extension of the concepts and tasks of Lab#3. You will again read the dictionary file and resize the array as needed to store the words. Project#3 will require you to update a frequency counter of word lengths every time a word is read from the dictionary into the wordList. When your program is finished this histogram array will contain the following:...
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 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...
create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the method, check if the...
I've been assigned to create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the...
java Write a program called Copy that accepts the names of an input file and an output file on the command line and copies the contents of the input file to the output file, for example, csc$ java Copy infile.txt outfile.txt
java Program Write a program called Copy that accepts the names of an input file and an output file on the command line and copies the contents of the input file to the output file, for example, csc$ java Copy infile.txt outfile.txt
Execute your program like this: C:\> java Lab4 10000ints.txt 172822words.txt Be sure to put the ints filename before the words filename. The starter file will be expecting them in that order. Lab#4's main method is completely written. Do not modify main. Just fill in the methods. Main will load a large arrays of int, and then load a large array of Strings. As usual the read loops for each file will be calling a resize method as needed. Once the...
QUESTION The ReadFile class opens and reads a text file. The WriteFile class opens and writes to a file. Compile and run these programs. There are several ways to read/write text files. The examples shown here are just one way of achieving this. Look at the API for the BufferedReader class. The readline() method is a simple way to read the text file line by line. It returns null when the end of the file has been reached. https://docs.oracle.com/javase/8/docs/api/java/io/BufferedReader.html Look...
Ask the user for the name of a file and a word. Using the FileStats class, show how many lines the file has and how many lines contain the text. Standard Input Files in the same directory romeo-and-juliet.txt the romeo-and-juliet.txt Required Output Enter a filename\n romeo-and-juliet.txt has 5268 lines\n Enter some text\n 1137 line(s) contain "the"\n Your Program's Output Enter a filename\n romeo-and-juliet.txt has 5268 lines\n Enter some text\n 553 line(s) contain "the"\n (Your output is too short.) My...
composed the following java code to read a string from a text file but receiving compiling errors. The text file is MyNumData.txt. Included the original java script that generated the output file. Shown also in the required output results after running the java program. I can't seem to search for the string and output the results. Any assistance will be greatly appreciated. import java.io.BufferedReader; import java.io.FileReader; import java.util.ArrayList; public class Main { public static void main(String[] args) { System.out.print("Enter the...