ava Proram ASAP There is an extra /n in the program in test case 1-3 and after Please re-enter the file name or type QUIT to exit:\n quitENTER  in test case 4 there needs to be nothing as shown in the screenshot. The text files are located in Hypergrade. Please modify this code below so it passes the test cases. Also I have the correct test case as a screenshot.  import java.io.*; import java.util.Scanner; public class ConvertText {     public static void main(String[] args) throws Exception {         Scanner sc = new Scanner(System.in);         System.out.println("Please enter the file name or type QUIT to exit:");         while (true) {             String input = sc.next();             if (input.compareTo("QUIT") == 0) {                 break;             } else {                 String filePath = new File("").getAbsolutePath();                 filePath = filePath.concat("/");                 filePath = filePath.concat(input);                 File file = new File(filePath);                 if (file.exists() && !file.isDirectory()) {                     BufferedReader br = new BufferedReader(new FileReader(file));                     String st;                     StringBuilder formattedText = new StringBuilder();                     while ((st = br.readLine()) != null) {                         String[] sentences = st.split(" ");                         for (int i = 0; i < sentences.length; i++) {                             StringBuilder sb = new StringBuilder("");                             sb.append(Character.toUpperCase(sentences[i].charAt(0)));                             for (int j = 1; j < sentences[i].length(); j++) {                                 char currentChar = sentences[i].charAt(j);                                 if (currentChar == '!' || currentChar == '.') {                                     sb.append(currentChar);                                     if (j + 1 < sentences[i].length()) {                                         sb.append(" ");                                         sb.append(Character.toUpperCase(sentences[i].charAt(j + 1)));                                         j++;                                     }                                 } else if (Character.isUpperCase(currentChar)) {                                     sb.append(" ");                                     sb.append(Character.toLowerCase(currentChar));                                 } else {                                     sb.append(currentChar);                                 }                             }                             formattedText.append(sb.toString() + "");                         }                         formattedText.append("\n");                     }                     System.out.println(formattedText);                     break;                 } else {                     System.out.println("File '" + input + "' is not found.");                     System.out.println("Please re-enter the file name or type QUIT to exit:");                 }             }         }     } }     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   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 Proram ASAP

There is an extra /n in the program in test case 1-3 and after Please re-enter the file name or type QUIT to exit:\n quitENTER  in test case 4 there needs to be nothing as shown in the screenshot. The text files are located in Hypergrade. Please modify this code below so it passes the test cases. Also I have the correct test case as a screenshot. 

import java.io.*;
import java.util.Scanner;

public class ConvertText {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        System.out.println("Please enter the file name or type QUIT to exit:");
        while (true) {
            String input = sc.next();
            if (input.compareTo("QUIT") == 0) {
                break;
            } else {
                String filePath = new File("").getAbsolutePath();
                filePath = filePath.concat("/");
                filePath = filePath.concat(input);
                File file = new File(filePath);
                if (file.exists() && !file.isDirectory()) {
                    BufferedReader br = new BufferedReader(new FileReader(file));
                    String st;
                    StringBuilder formattedText = new StringBuilder();

                    while ((st = br.readLine()) != null) {
                        String[] sentences = st.split(" ");
                        for (int i = 0; i < sentences.length; i++) {
                            StringBuilder sb = new StringBuilder("");
                            sb.append(Character.toUpperCase(sentences[i].charAt(0)));
                            for (int j = 1; j < sentences[i].length(); j++) {
                                char currentChar = sentences[i].charAt(j);
                                if (currentChar == '!' || currentChar == '.') {
                                    sb.append(currentChar);
                                    if (j + 1 < sentences[i].length()) {
                                        sb.append(" ");
                                        sb.append(Character.toUpperCase(sentences[i].charAt(j + 1)));
                                        j++;
                                    }
                                } else if (Character.isUpperCase(currentChar)) {
                                    sb.append(" ");
                                    sb.append(Character.toLowerCase(currentChar));
                                } else {
                                    sb.append(currentChar);
                                }
                            }
                            formattedText.append(sb.toString() + "");
                        }
                        formattedText.append("\n");
                    }
                    System.out.println(formattedText);
                    break;
                } else {
                    System.out.println("File '" + input + "' is not found.");
                    System.out.println("Please re-enter the file name or type QUIT to exit:");
                }
            }
        }
    }
}

 
 

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
 
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
\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
\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'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
\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 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
File 'quit' is not found.\n
... OUTPUT TOO LONG
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 \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 \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'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 \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 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 File 'quit' is not found.\n ... OUTPUT TOO LONG
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 5 steps with 3 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
  • 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
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage