In this programming project you will be required to design, develop, test and do
ID: 3625436 • Letter: I
Question
In this programming project you will be required to design, develop, test and document a Java application that takes in four arguments from the command line, reads data from an input file, processes the data, and then writes the processed data to an output file. There are five arguments you need to enter at the command line are as follow:
The specific functional requirements for this project are the following:
- The application should be run from the command line using command line arguments to provide the input filename, output filename, letter to be counted in each line, word to be replaced, and the word to replace with.
- The application should display an appropriate error message if the user forgets to enter any of the five arguments or if the input file is not found.
- The application should open the file and read each line in it.
- For each line read, the application should determine the total number of words and characters in the line (including whitespace characters), determine the number of times the character in the third argument appears in the line, replace all occurrences of the string given in the fourth argument with the string given in the fifth argument, and reverse the order of the characters in the line.
- You need to call methods to perform the counting of words and characters, determine the number of occurrences of the given character, replacing strings in a line, and reversing each line.
- The output file should contain the same number of lines as the input file with the following content for each line:
The application should close any open files before exiting.
Sample input.txt:
.ohcyTbeW ni redloF tnemngissA eht ni 4jorp timbus ot deen uoY
.emit eno ylno 4jorp timbuS
.emit no 4jorp timbuS
!kcul doog
If you run the following command after successfully compiling the .java file(s):
>java Project4 input.txt output.txt o 3 4
The output.txt should be created and contain the following:
You need to submit proj4 in the Assignment Folder in WebTycho. ---> 62 characters, 11 words, "o" occurred 5 times.
Submit proj4 only one time. ---> 27 characters, 5 words, "o" occurred 3 times.
Submit proj4 on time. ---> 21 characters, 4 words, "o" occurred 2 times.
good luck! ---> 10 characters, 2 words, "o" occurred 2 times.
Explanation / Answer
please rate - thanks
import java.io.*;
import java.util.*;
import java.lang.Character.*;
public class commandin
{public static int numOfTutors;
public static void main(String[] args)throws FileNotFoundException
{Scanner input=new Scanner(new File(args[0]));
PrintStream output=new PrintStream(new File(args[1]));
char ch=args[2].charAt(0);
String replace=args[3];
String with=args[4];
int words,charc,i;
char c;
String in;
while(input.hasNextLine())
{in=input.nextLine();
words=countwords(in);
charc=countchars(in,ch);
in=replaceit(in,replace,with);
in=reverse(in);
output.println(in+" ---> "+in.length()+" characters, "+words+" words, ""+ch+"" occured "+ charc+" times");
}
input.close();
output.close();
}
public static String reverse(String n)
{int i;
String out="";
char temp;
for(i=n.length()-1;i>=0;i--)
out=out+n.charAt(i);
return out;
}
public static int countwords(String in)
{int n=0,i;
for(i=0;i<in.length();i++)
if(Character.isWhitespace(in.charAt(i)))
n++;
return n+1;
}
public static int countchars(String in, char c)
{int n=0,i;
for(i=0;i<in.length();i++)
if(in.charAt(i)==c)
n++;
return n;
}
public static String replaceit(String in,String replace,String with)
{
String out = in.replaceAll(replace, with);
return out;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.