Java Program ************This program must work in hypergrade and pass all the test cases.********** Please modify this program down below because it does not pass all the test cases. I have provided the failed test cases and the correct test case as a screenshot. import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; // Import InputStreamReader public class WordSeparator { public static void main(String[] args) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { String inputFileName; while (true) { System.out.print("Please enter the file name or type QUIT to exit:\n"); inputFileName = reader.readLine(); if (inputFileName.equalsIgnoreCase("QUIT")) { break; } try { BufferedReader fileReader = new BufferedReader(new FileReader(inputFileName)); String line; StringBuilder result = new StringBuilder(); while ((line = fileReader.readLine()) != null) { result.append(convertSentence(line)).append("\n"); } System.out.println(result.toString()); fileReader.close(); } catch (IOException e) { System.out.println("File '" + inputFileName + "' is not found."); } } } catch (IOException e) { e.printStackTrace(); } } private static String convertSentence(String sentence) { StringBuilder result = new StringBuilder(); boolean capitalizeNext = true; for (char c : sentence.toCharArray()) { if (c == '.' || c == '!' || c == '?') { result.append(c).append(" "); capitalizeNext = true; } else if (Character.isLetter(c)) { if (capitalizeNext) { result.append(Character.toUpperCase(c)); capitalizeNext = false; } else { result.append(Character.toLowerCase(c)); } } else { result.append(c); } } return result.toString(); } } Chapter 9. PC #14. Word Separator (modified *** Read carefully ***) Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it line by line. While entering the file name, the program should allow the user to type quit to exit the program. If the file with a given name does not exist, then display a message and allow the user to re-enter the file name. The file can contain one or more sentences. The program should accept as input each sentence in which all the words are run together, but the first character of each word is uppercase. Convert sentences to strings in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string StopAndSmellTheRoses.” would be converted to “Stop and smell the roses.” Sentences are separated by periods ('.'), exclamation marks ('!'), or question marks ('?'). Ensure that there is one space character in between sentences. text1.txt StopAndSmellTheRoses. text2.txt ATrueRebelYouAre!EveryoneWasImpressed.You'llDoWellToContinueInTheSameSpirit. PleaseExplainABitMoreInTheWayOfFootnotes.FromTheGivenTextIt'sNotClearWhatAreWeReadingAbout. Test Case 1 Please enter the file name or type QUIT to exit:\n text1.txtENTER Stop and smell the roses.\n Test Case 2 Please enter the file name or type QUIT to exit:\n txt1.txtENTER File 'txt1.txt' is not found.\n Please re-enter the file name or type QUIT to exit:\n text1.txtENTER Stop and smell the roses.\n Test Case 3 Please enter the file name or type QUIT to exit:\n text2.txtENTER A true rebel you are! Everyone was impressed. You'll do well to continue in the same spirit.\n Please explain a bit more in the way of footnotes. From the given text it's not clear what are we reading about.\n Test Case 4 Please enter the file name or type QUIT to exit:\n somefile.txtENTER File 'somefile.txt' is not found.\n Please re-enter the file name or type QUIT to exit:\n anotherbadfile.txtENTER File 'anotherbadfile.txt' is not found.\n Please re-enter the file name or type QUIT to exit:\n quitENTER
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader; // Import InputStreamReader
public class WordSeparator {
public static void main(String[] args) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
String inputFileName;
while (true) {
System.out.print("Please enter the file name or type QUIT to exit:\n");
inputFileName = reader.readLine();
if (inputFileName.equalsIgnoreCase("QUIT")) {
break;
}
try {
BufferedReader fileReader = new BufferedReader(new FileReader(inputFileName));
String line;
StringBuilder result = new StringBuilder();
while ((line = fileReader.readLine()) != null) {
result.append(convertSentence(line)).append("\n");
}
System.out.println(result.toString());
fileReader.close();
} catch (IOException e) {
System.out.println("File '" + inputFileName + "' is not found.");
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
private static String convertSentence(String sentence) {
StringBuilder result = new StringBuilder();
boolean capitalizeNext = true;
for (char c : sentence.toCharArray()) {
if (c == '.' || c == '!' || c == '?') {
result.append(c).append(" ");
capitalizeNext = true;
} else if (Character.isLetter(c)) {
if (capitalizeNext) {
result.append(Character.toUpperCase(c));
capitalizeNext = false;
} else {
result.append(Character.toLowerCase(c));
}
} else {
result.append(c);
}
}
return result.toString();
}
}
PleaseExplainABitMoreInTheWayOfFootnotes.FromTheGivenTextIt'sNotClearWhatAreWeReadingAbout.
Test Case 1
text1.txtENTER
Stop and smell the roses.\n
Test Case 2
txt1.txtENTER
File 'txt1.txt' is not found.\n
Please re-enter the file name or type QUIT to exit:\n
text1.txtENTER
Stop and smell the roses.\n
Test Case 3
text2.txtENTER
A true rebel you are! Everyone was impressed. You'll do well to continue in the same spirit.\n
Please explain a bit more in the way of footnotes. From the given text it's not clear what are we reading about.\n
Test Case 4
somefile.txtENTER
File 'somefile.txt' is not found.\n
Please re-enter the file name or type QUIT to exit:\n
anotherbadfile.txtENTER
File 'anotherbadfile.txt' is not found.\n
Please re-enter the file name or type QUIT to exit:\n
quitENTER
![Test Case 1
Please enter the file name or type QUIT to exit: \n
text1.txt ENTER
Stop and smell the roses. \n
Test Case 2
Please enter the file name or type QUIT to exit: \n
txt1.txt ENTER
File 'txt1.txt' is not found. \n
Please re-enter the file name or type QUIT to exit: \n
text1.txt ENTER
Stop and smell the roses.\n
Test Case 3
Please enter the file name or type QUIT to exit: \n
text2.txt ENTER
A true rebel you are! Everyone was impressed. You'll do well to continue in the same spirit.\n
Please explain a bit more in the way of footnotes. From the given text it's not clear what are we reading about.\n
Test Case 4
Please enter the file name or type QUIT to exit: \n
somefile.txt ENTER
File 'somefile.txt' is not found.\n
Please re-enter the file name or type QUIT to exit: \n
anotherbadfile.txt ENTER
File 'anotherbadfile.txt' is not found. \n
Please re-enter the file name or type QUIT to exit: \n
quit ENTER](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F46d7d6d4-4d71-4d38-aab6-f8d30c635b34%2Fc4fb9e66-46e6-45c4-9241-2ea535678d48%2Fkcp194f_processed.png&w=3840&q=75)
![Test Case 1 Failed Show what's missing
Please enter the file name or type QUIT to exit: \n
text1.txt ENTER
Stopandsmelltheroses. \n
\n
Please ent... OUTPUT TOO LONG
Test Case 2 Failed Show what's missing
Please enter the file name or type QUIT to exit: \n
txt1.txt ENTER
File txt1.txt' is not found.\n
Please enter the file name or type QUIT to exit: \n
text1.txt ENTER
Stopandsmelltheroses. \n
Please enter the file OUTPUT TOO LONG
Test Case 3 Failed Show what's missing
Please enter the file name or type QUIT to exit: \n
text2.txt ENTER
Atruerebelyouare! Everyonewasimpressed. You'lldowelltocontinueinthesamespirit. \n|
Pleaseexplainabitmoreinthewayoffootnotes.
Please enter the file name or type QUIT to exit: \n
Exceptio... OUTPUT TOO LONG
Fromthegiventextit'snotclearwhatarewereadingabout. \n|
Test Case 4 Failed Show what's missing
Please enter the file name or type QUIT to exit: \n
somefile.txt ENTER
File 'somefile.txt' is not found.\n
Please enter the file name or type QUIT to exit: \n
anotherbadfile.txt ENTER
File 'anotherbadfile.txt' is not found. \n
Please enter the file name or type QUIT to exit: \n
quit ENTER](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F46d7d6d4-4d71-4d38-aab6-f8d30c635b34%2Fc4fb9e66-46e6-45c4-9241-2ea535678d48%2Fyb12gam_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 4 steps with 2 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)