Java Program ASAP   ************This program must work in hypergrade and pass all the test cases.**********   Please give me a 100% working code. I have provided the code instructions below. Fix the program below with the following modifications : in Stopandsmelltheroses.  the s needs to be Capital, a smaller case, s maller case r smaller case in the sentence and with spaces. The same applies to   Atruerebelyouare!Everyone was impressed.You'lldowellto continue in the same spirit. Pleaseexplainabitmoreinthewayoffootnotes.Fromthegiventextit'snotclearwhatarewereadingabout. and  Pleaseexplainabitmoreinthewayoffootnotes.Fromthegiventextit'snotclearwhatarewereadingabout. needs to be in another line and with spaces.     import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.regex.Pattern; import java.util.regex.Matcher; public class WordSeparator {     public static void main(String[] args) {         try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {             String inputFileName;             boolean fileNotFound;             System.out.print("Please enter the file name or type QUIT to exit:\n");             do {                 fileNotFound = false; // Reset fileNotFound flag for each iteration                 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;                     while ((line = fileReader.readLine()) != null) {                         // Use a modified regular expression to split the input into words and punctuation                         Pattern pattern = Pattern.compile("([A-Z][a-z]*|\\p{Punct})");                         Matcher matcher = pattern.matcher(line);                         while (matcher.find()) {                             String token = matcher.group();                             if (newSentence && !token.equals(".")) {                                 token = token.substring(0, 1).toLowerCase() + token.substring(1);                                 result.append(token);                                 newSentence = false;                             } else {                                 if (token.equals(".") || token.equals("!") || token.equals("?")) {                                     newSentence = true;                                     result.append(token);                                 } else {                                     result.append(" ").append(token);                                 }                             }                         }                     }                     System.out.println(result.toString().trim()); // Remove trailing newline                     fileReader.close();                     break;                 } catch (IOException e) {                     fileNotFound = true;                     System.out.println("File '" + inputFileName + "' is not found.");                     System.out.print("Please re-enter the file name or type QUIT to exit:\n");                 }             } while (true);         } catch (IOException e) {             e.printStackTrace();         }     } }       Code instructions down below: 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.

Programming with Microsoft Visual Basic 2017
8th Edition
ISBN:9781337102124
Author:Diane Zak
Publisher:Diane Zak
Chapter9: Sequential Access Files And Menus
Section: Chapter Questions
Problem 11E
icon
Related questions
Question
Java Program ASAP
 
************This program must work in hypergrade and pass all the test cases.**********
 
Please give me a 100% working code. I have provided the code instructions below. Fix the program below with the following modifications : in Stopandsmelltheroses.  the s needs to be Capital, a smaller case, s maller case r smaller case in the sentence and with spaces. The same applies to  
Atruerebelyouare!Everyone was impressed.You'lldowellto continue in the same spirit.
Pleaseexplainabitmoreinthewayoffootnotes.Fromthegiventextit'snotclearwhatarewereadingabout. and 
Pleaseexplainabitmoreinthewayoffootnotes.Fromthegiventextit'snotclearwhatarewereadingabout. needs to be in another line and with spaces.
 

 

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class WordSeparator {
    public static void main(String[] args) {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            String inputFileName;
            boolean fileNotFound;
            System.out.print("Please enter the file name or type QUIT to exit:\n");
            do {
                fileNotFound = false; // Reset fileNotFound flag for each iteration
                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;

                    while ((line = fileReader.readLine()) != null) {
                        // Use a modified regular expression to split the input into words and punctuation
                        Pattern pattern = Pattern.compile("([A-Z][a-z]*|\\p{Punct})");
                        Matcher matcher = pattern.matcher(line);

                        while (matcher.find()) {
                            String token = matcher.group();

                            if (newSentence && !token.equals(".")) {
                                token = token.substring(0, 1).toLowerCase() + token.substring(1);
                                result.append(token);
                                newSentence = false;
                            } else {
                                if (token.equals(".") || token.equals("!") || token.equals("?")) {
                                    newSentence = true;
                                    result.append(token);
                                } else {
                                    result.append(" ").append(token);
                                }
                            }
                        }
                    }

                    System.out.println(result.toString().trim()); // Remove trailing newline

                    fileReader.close();
                    break;
                } catch (IOException e) {
                    fileNotFound = true;
                    System.out.println("File '" + inputFileName + "' is not found.");
                    System.out.print("Please re-enter the file name or type QUIT to exit:\n");
                }
            } while (true);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

 
 

 

Code instructions down below:
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 Failed Show what's missing
Please enter the file name or type QUIT to exit: \n
text1.txt ENTER
stop And Smell The Roses.\n
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 re-enter the file name or type QUIT to exit: \n
text1.txt ENTER
stop And Smell The Roses.\n
Test Case 3 Failed Show what's missing
Please enter the file name or type QUIT to exit: \n
text2.txt ENTER
a True Rebel You Are! everyone Was Impressed. you Do Well To Continue In The Same Spirit.please Explain A Bit More In The Way Of Footnotes.from The Given Text It Not Clear What Are We Reading About.\n
Test Case 4 Passed!
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 Failed Show what's missing Please enter the file name or type QUIT to exit: \n text1.txt ENTER stop And Smell The Roses.\n 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 re-enter the file name or type QUIT to exit: \n text1.txt ENTER stop And Smell The Roses.\n Test Case 3 Failed Show what's missing Please enter the file name or type QUIT to exit: \n text2.txt ENTER a True Rebel You Are! everyone Was Impressed. you Do Well To Continue In The Same Spirit.please Explain A Bit More In The Way Of Footnotes.from The Given Text It Not Clear What Are We Reading About.\n Test Case 4 Passed! 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
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
steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
Program on Numbers
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT