Java Proram ASAP Please look closely at the circled parts in the failed test case. Improve and adjust the program which is down below with the futher moddifications because it does not pass the test cases in Hypergrade. Please remove /n from the program and for test case 4 after this line: Please re-enter the file name or type QUIT to exit:\n quitENTER there needs to be nothing. Also, I do not need file quit is no found in the program. 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 { // Get the absolute path of the current directory String filePath = new File("").getAbsolutePath(); filePath = filePath.concat("/"); filePath = filePath.concat(input); File file = new File(filePath); if (file.exists() && !file.isDirectory()) { try (BufferedReader br = new BufferedReader(new FileReader(file))) { String st; StringBuilder formattedText = new StringBuilder(); while ((st = br.readLine()) != null) { // Split the input line into sentences using space as the delimiter 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); } catch (IOException e) { e.printStackTrace(); } } else { System.out.println("File '" + input + "' is not found."); System.out.println("Please re-enter the file name or type QUIT to exit:"); } } } } } 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
Java Proram ASAP
Please look closely at the circled parts in the failed test case. Improve and adjust the program which is down below with the futher moddifications because it does not pass the test cases in Hypergrade. Please remove /n from the program and for test case 4 after this line: Please re-enter the file name or type QUIT to exit:\n quitENTER there needs to be nothing. Also, I do not need file quit is no found in the program.
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 {
// Get the absolute path of the current directory
String filePath = new File("").getAbsolutePath();
filePath = filePath.concat("/");
filePath = filePath.concat(input);
File file = new File(filePath);
if (file.exists() && !file.isDirectory()) {
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
String st;
StringBuilder formattedText = new StringBuilder();
while ((st = br.readLine()) != null) {
// Split the input line into sentences using space as the delimiter
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);
} catch (IOException e) {
e.printStackTrace();
}
} else {
System.out.println("File '" + input + "' is not found.");
System.out.println("Please re-enter the file name or type QUIT to exit:");
}
}
}
}
}
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%2F1c791d22-5d01-4fac-adef-f5f80eb1d610%2Fbc7e950d-1886-45aa-ac6a-2ae84defc059%2F55oohkh_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
Stop and smell the roses.\n
\n
Excepti... 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 re-enter the file name or type QUIT to exit: \n
text1.txt ENTER
Stop and smell the roses.\n
\n
Exception in thr... 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
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
Exception in thread "main... 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 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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F1c791d22-5d01-4fac-adef-f5f80eb1d610%2Fbc7e950d-1886-45aa-ac6a-2ae84defc059%2Foxokxoj_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps with 4 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)