Java Program     ************This program must work in hypergrade and pass all the test cases.**********   This program down below does not pass the test cases when I upload it to Hypergrade. I have provided the correct test case as a screenshot too. Please modit it or create a new program so it paases the test cases. Thank you!    import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.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();                     boolean newSentence = true; // Flag to handle sentence separation                     while ((line = fileReader.readLine()) != null) {                         String[] words = line.split("\\s+");                         for (String word : words) {                             if (newSentence) {                                 result.append(word.substring(0, 1).toUpperCase()).append(word.substring(1));                                 newSentence = false;                             } else {                                 result.append(" ").append(word);                             }                             if (word.endsWith(".") || word.endsWith("!") || word.endsWith("?")) {                                 newSentence = true;                                 result.append(" ");                             }                         }                         result.append("\n");                     }                     System.out.println(result.toString().trim()); // Remove trailing newline                     fileReader.close();                 } catch (IOException e) {                     System.out.println("File '" + inputFileName + "' is not found.");                 }             }         } catch (IOException e) {             e.printStackTrace();         }     } }       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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Java Program
 
 
************This program must work in hypergrade and pass all the test cases.**********
 
This program down below does not pass the test cases when I upload it to Hypergrade. I have provided the correct test case as a screenshot too. Please modit it or create a new program so it paases the test cases. Thank you! 
 

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.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();

                    boolean newSentence = true; // Flag to handle sentence separation

                    while ((line = fileReader.readLine()) != null) {
                        String[] words = line.split("\\s+");
                        for (String word : words) {
                            if (newSentence) {
                                result.append(word.substring(0, 1).toUpperCase()).append(word.substring(1));
                                newSentence = false;
                            } else {
                                result.append(" ").append(word);
                            }
                            if (word.endsWith(".") || word.endsWith("!") || word.endsWith("?")) {
                                newSentence = true;
                                result.append(" ");
                            }
                        }
                        result.append("\n");
                    }

                    System.out.println(result.toString().trim()); // Remove trailing newline
                    fileReader.close();
                } catch (IOException e) {
                    System.out.println("File '" + inputFileName + "' is not found.");
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

 

 

 
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
 
 
 
Test Case 1 Failed Show what's missing
Please enter the file name or type QUIT to exit: \n
text1.txt ENTER
StopAndSmell TheRoses.\n
Please enter... 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
StopAndSmell TheRoses.\n
Please enter the file na... 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
ATrueRebel YouAre! EveryoneWas Impressed. You'llDoWellToContinueInTheSameSpirit. \n
PleaseExplainABitMoreInTheWay Of Footnotes. From TheGiven TextIt'sNot ClearWhatAreWeReading About.\n
Please enter the file name or type QUIT to exit: \n
Exception in OUTPUT TOO LONG
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
Transcribed Image Text:Test Case 1 Failed Show what's missing Please enter the file name or type QUIT to exit: \n text1.txt ENTER StopAndSmell TheRoses.\n Please enter... 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 StopAndSmell TheRoses.\n Please enter the file na... 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 ATrueRebel YouAre! EveryoneWas Impressed. You'llDoWellToContinueInTheSameSpirit. \n PleaseExplainABitMoreInTheWay Of Footnotes. From TheGiven TextIt'sNot ClearWhatAreWeReading About.\n Please enter the file name or type QUIT to exit: \n Exception in OUTPUT TOO LONG 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
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
Transcribed Image Text: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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Linux
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education