Answered You can hire a professional tutor to get the answer.
7 : Compare output ~ Some Random F 1 1 @ Name . Ext Input SomeOther Random F 1 1 @ Name . Ext Homework 6 - 2 Input File . Ext What is the name of
I'm creating this java program and need help to resolve an error. Here is the requirement for the program:
- In a class named ReadAndEditFile.java, use the following prompt to get the fileName of the input file from the User: "What is the name of your file?"
- If the File doesn't exist, do not crash, but instead display "File Not Found " + fileName and repeatedly prompt until the user has entered a valid file name.
- If the File exists, read from the File.
- Capitalize the first letter in the file and capitalize the 1st letter after every period and correct the spacing by removing any duplicate spaces so that there is only 1 space between words.
- Write the modified output to a file named HomeworkOutput6-2.txt
Here's the code I have:
java.io.File; java.io.IOException; java.nio.file.Files; java.nio.file.Paths; java.util.Scanner; java.util.regex.Matcher; java.util.regex.Pattern; java.util.stream.Collectors; java.util.stream.Stream;public { public main([] args) throws IOException { Scanner scanner = Scanner(System.in); File file = ; boolean createOutputFile = ; () { System.out.println(); fileName = scanner.nextLine(); file = File(fileName); (file.exists()) { /** * read all files lines and convert to stream */ Stream<> lines = Files.lines(file.toPath()); data = lines.collect(Collectors.joining()); /** * split all lines with dot(.) */ [] sepratedData = data.split(); test = ; ( seprateString : sepratedData) { /** * trim() will remove all space at begin and end of string, */ seprateString = seprateString.trim(); /** * convert first character to UpperCase */ (!seprateString.isEmpty()) { seprateString = Character.toUpperCase(seprateString.charAt()) + seprateString.substring(); test += seprateString + +; createOutputFile = ; } } /** * remove more than one space to single space */ (createOutputFile) { test = filter(test, , ); Files.write(Paths.get(), test.getBytes()); lines.close(); } ; } { System.out.println( + fileName); } } } public filter( scan, regex, replace) { StringBuffer sb = StringBuffer(); Pattern pt = Pattern.compile(regex); Matcher m = pt.matcher(scan); (m.find()) { m.appendReplacement(sb, replace); } m.appendTail(sb); sb.toString(); }}This is the error message(unit test 2) I'm getting:
7 : Compare output ~Some Random F 1 1 @ Name . ExtInputSomeOther Random F 1 1 @ Name . ExtHomework 6 - 2 Input File . ExtWhat is the name of your file ?!File Not Found Some Random F i l @ Name . ExtYour outputWhat is the name of your file ?"File Not Found Someother Random F 1 1 @ Name . ExtWhat is the name of your file ?"2 : Unit test ~0 / 30Your outputFile Not Found Correct Output For 6 - 2 . ExtFailure ! ! ! !!