JAVA PROGRAM ASAP Please MODIFY THIS program ASAP BECAUSE  it does not pass all the test caseswhen I upload it to hypergrade. I have provided the correct test cases as a screenshot as well as the failed test cases. It says 0 out of 4 passed. The program must pass the test case when uploaded to Hypergrade.  Files data are down below: text1.txt StopAndSmellTheRoses.   text2.txt ATrueRebelYouAre!EveryoneWasImpressed.You'llDoWellToContinueInTheSameSpirit. PleaseExplainABitMoreInTheWayOfFootnotes.FromTheGivenTextIt'sNotClearWhatAreWeReadingAbout.   import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.Scanner; class Main {     // Driver code     public static void main(String[] args) {         // scanner object used to take user input         Scanner sc = new Scanner(System.in);         // loop iterates until user enters "quit" or "QUIT"         while (true) {             System.out.print("Please enter the file name or type QUIT to exit:\n");             String fileName = sc.nextLine();             if (fileName.equalsIgnoreCase("QUIT")) {                 break;             }             try {                 // open file in read mode                 BufferedReader reader = new BufferedReader(new FileReader(fileName));                 String line;                 StringBuilder result = new StringBuilder();                 // for each line                 while ((line = reader.readLine()) != null) {                     String formattedSentence = formatSentence(line);                     result.append(formattedSentence).append("\n");                 }                 System.out.println(result.toString());                 reader.close();             } catch (IOException e) {                 System.out.println("File '" + fileName + "' is not found.");             }         }     }     // creating a method     public static String formatSentence(String sentence) {         StringBuilder formatted = new StringBuilder();         int i=0;         for (char c : sentence.toCharArray()) {             if (Character.isLetter(c)) {                 if (Character.isUpperCase(c)) {                     if(i != 0){                         formatted.append(" ");                     }                     if(i == 0){                         formatted.append(Character.toUpperCase(c));                     }                     else{                         formatted.append(Character.toLowerCase(c));                     }                 } else {                     formatted.append(Character.toLowerCase(c));                 }             } else if (c == '.' || c == '!' || c == '?') {                 formatted.append(c).append(" ");                 i = -1;             }             else{                 formatted.append(c);             }             i++;         }         return formatted.toString();     } }      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

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

Please MODIFY THIS program ASAP BECAUSE  it does not pass all the test caseswhen I upload it to hypergrade. I have provided the correct test cases as a screenshot as well as the failed test cases. It says 0 out of 4 passed. The program must pass the test case when uploaded to Hypergrade. 

Files data are down below:

text1.txt
StopAndSmellTheRoses.
 
text2.txt
ATrueRebelYouAre!EveryoneWasImpressed.You'llDoWellToContinueInTheSameSpirit.
PleaseExplainABitMoreInTheWayOfFootnotes.FromTheGivenTextIt'sNotClearWhatAreWeReadingAbout.

 

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

class Main {
    // Driver code
    public static void main(String[] args) {
        // scanner object used to take user input
        Scanner sc = new Scanner(System.in);
        // loop iterates until user enters "quit" or "QUIT"
        while (true) {
            System.out.print("Please enter the file name or type QUIT to exit:\n");
            String fileName = sc.nextLine();

            if (fileName.equalsIgnoreCase("QUIT")) {
                break;
            }

            try {
                // open file in read mode
                BufferedReader reader = new BufferedReader(new FileReader(fileName));
                String line;
                StringBuilder result = new StringBuilder();
                // for each line
                while ((line = reader.readLine()) != null) {
                    String formattedSentence = formatSentence(line);
                    result.append(formattedSentence).append("\n");
                }
                System.out.println(result.toString());
                reader.close();
            } catch (IOException e) {
                System.out.println("File '" + fileName + "' is not found.");
            }
        }
    }
    // creating a method
    public static String formatSentence(String sentence) {
        StringBuilder formatted = new StringBuilder();
        int i=0;
        for (char c : sentence.toCharArray()) {
            if (Character.isLetter(c)) {
                if (Character.isUpperCase(c)) {
                    if(i != 0){
                        formatted.append(" ");
                    }
                    if(i == 0){
                        formatted.append(Character.toUpperCase(c));
                    }
                    else{
                        formatted.append(Character.toLowerCase(c));
                    }
                } else {
                    formatted.append(Character.toLowerCase(c));
                }
            } else if (c == '.' || c == '!' || c == '?') {
                formatted.append(c).append(" ");
                i = -1;
            }
            else{
                formatted.append(c);
            }
            i++;
        }

        return formatted.toString();
    }

 
 
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
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'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 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
Test Case 1
Failed
Test Case 2
Please enter the file name or type QUIT to exit: \n
text1.txt ENTER
Stop And Smell The Roses.\n
\n
Please OUTPUT TOO LONG
Failed
Show what's missing
Test Case 3 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
Stop And Smell The Roses.\n
\n
Please enter the fi... OUTPUT TOO LONG
Show what's missing
Please enter the file name or type QUIT to exit: \n
text2.txt ENTER
ATrue Rebel You Are! Everyone Was Impressed. You'll Do Well To Continue In The Same Spirit.\n
Please Explain ABit More In The Way Of Footnotes. From The Given Text It's Not Clear What Are We Reading About.\n
\n
Please enter the file name or
Test Case 4 Failed Show what's missing
OUTPUT TOO LONG
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 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'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 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 Test Case 1 Failed Test Case 2 Please enter the file name or type QUIT to exit: \n text1.txt ENTER Stop And Smell The Roses.\n \n Please OUTPUT TOO LONG Failed Show what's missing Test Case 3 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 Stop And Smell The Roses.\n \n Please enter the fi... OUTPUT TOO LONG Show what's missing Please enter the file name or type QUIT to exit: \n text2.txt ENTER ATrue Rebel You Are! Everyone Was Impressed. You'll Do Well To Continue In The Same Spirit.\n Please Explain ABit More In The Way Of Footnotes. From The Given Text It's Not Clear What Are We Reading About.\n \n Please enter the file name or Test Case 4 Failed Show what's missing OUTPUT TOO LONG 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
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Unreferenced Objects
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