JAVA Program ASAP Combine these two program into one so it will the passes the test cases. Converttext.java 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.equalsIgnoreCase("QUIT")) {                 break; // Exit the program             } else {                 String filePath = new File("").getAbsolutePath() + "/" + 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.print(formattedText);                         return; // Exit the program after printing                                             } 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:");                 }             }         }     } }   FileSorting.java import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; public class FileSorting {         private static final String FILENAME = "somefile.txt";         public static void main(String[] args) {         // read integers from input file         Scanner fileReader;         ArrayList numbers = new ArrayList<>();         try         {             fileReader = new Scanner(new File(FILENAME));             while(fileReader.hasNextLine())             {                 numbers.add(Integer.parseInt(fileReader.nextLine().trim()));             }             fileReader.close();         }catch(FileNotFoundException fnfe){             System.out.println("File " + FILENAME + " is not found.");         }         // check whether the file is empty or not         if(numbers.isEmpty())         {             System.out.println("File " + FILENAME + " is empty.");             return;         }                 System.out.println("ORIGINAL LIST: " + numbers);         // sort the arraylist         sort(numbers);                 // print the arraylist         System.out.println("SORTED LIST:   " + numbers);     }         // this method takes an arraylist of integers as parameter and sorts the list in ascending order     private static void sort(ArrayList nums)     {         int i, j, temp;         for(i = 0; i < (nums.size() - 1); i++)         {             for(j = 0; j < (nums.size() - i - 1); j++)             {                 if(nums.get(j) > nums.get(j + 1))                 {                     temp = nums.get(j);                     nums.set(j, nums.get(j + 1));                     nums.set(j + 1, temp);                 }             }         }     } }

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 ASAP

Combine these two program into one so it will the passes the test cases.

Converttext.java

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.equalsIgnoreCase("QUIT")) {
                break; // Exit the program
            } else {
                String filePath = new File("").getAbsolutePath() + "/" + 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.print(formattedText);
                        return; // Exit the program after printing
                       
                    } 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:");
                }
            }
        }
    }
}

 

FileSorting.java

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

public class FileSorting {
   
    private static final String FILENAME = "somefile.txt";
   
    public static void main(String[] args) {
        // read integers from input file
        Scanner fileReader;
        ArrayList<Integer> numbers = new ArrayList<>();
        try
        {
            fileReader = new Scanner(new File(FILENAME));
            while(fileReader.hasNextLine())
            {
                numbers.add(Integer.parseInt(fileReader.nextLine().trim()));
            }
            fileReader.close();
        }catch(FileNotFoundException fnfe){
            System.out.println("File " + FILENAME + " is not found.");
        }
        // check whether the file is empty or not
        if(numbers.isEmpty())
        {
            System.out.println("File " + FILENAME + " is empty.");
            return;
        }
       
        System.out.println("ORIGINAL LIST: " + numbers);
        // sort the arraylist
        sort(numbers);
       
        // print the arraylist
        System.out.println("SORTED LIST:   " + numbers);
    }
   
    // this method takes an arraylist of integers as parameter and sorts the list in ascending order
    private static void sort(ArrayList<Integer> nums)
    {
        int i, j, temp;
        for(i = 0; i < (nums.size() - 1); i++)
        {
            for(j = 0; j < (nums.size() - i - 1); j++)
            {
                if(nums.get(j) > nums.get(j + 1))
                {
                    temp = nums.get(j);
                    nums.set(j, nums.get(j + 1));
                    nums.set(j + 1, temp);
                }
            }
        }
    }
}

 

 

 

 
 
 
input2x2.csv
-67, -11
-27, -70
input1.csv
10
input10x10.csv
56,-19, 21, -51, 45, 96,-46
-27, 29,-58,85,8, 71,34
50,51,40,50, 100, -82, -87
-47,-24,-27,-32,-25, 46,88
-47,95,-41, -75, 85,-16,43
-78,0,94,-77,-69, 78, -25
-80,-31,-95, 82, -86,-32, -22
68,-52,-4,-68, 10,-14,-89
26, 33,-59,-51,-48,-34,-52
-47,-24,80, 16, 80,-66,-42
inputo.csv
input2x2.csv - Edited
Transcribed Image Text:input2x2.csv -67, -11 -27, -70 input1.csv 10 input10x10.csv 56,-19, 21, -51, 45, 96,-46 -27, 29,-58,85,8, 71,34 50,51,40,50, 100, -82, -87 -47,-24,-27,-32,-25, 46,88 -47,95,-41, -75, 85,-16,43 -78,0,94,-77,-69, 78, -25 -80,-31,-95, 82, -86,-32, -22 68,-52,-4,-68, 10,-14,-89 26, 33,-59,-51,-48,-34,-52 -47,-24,80, 16, 80,-66,-42 inputo.csv input2x2.csv - Edited
Q
Test Case 5 Failed Show what's missing
Test Case 6 Failed
Test Case 1
Show what's missing
Failed
Test Case 2
Test Case 7 Failed Show what's missing
Please enter the file name or type QUIT to exit: \n
input1.csv ENTER
10 \n
Failed
Show what's missing
Test Case 3 Failed
Show what's missing
Please enter the file name or type QUIT to exit: \n
input2x2.csv ENTER
-67,-11\n
-70,-27\n
Show what's missing
Please enter the file name or type QUIT to exit: \n
input10x10 .csv ENTER
-51,-46, -21, -19, 45,56,96 \n
-58,-27,8,29,34,71,85 \n
-87,-82, 40, 50, 50, 51, 100 \n
-47,-32,-27, -25,-24, 46,88 \n
-75,-47,-41,-16, 43, 85,95 \n
-78,-77,-69, -25,0, 78,94 \n
-95,-86, -80,-32,-31, -22, 82 \n
-89,-68, -52,-14,-4, 10, 68 \n
-59,-52,-51,-48,-34, 26, 33 \n
-66,-47,-42,-24, 16, 80, 80 \n
Please enter the file name or type QUIT to exit: \n
input2.csv ENTER
Test Case 4 Failed Show what's missing
File input2.csv is not found.\n
Please re-enter the file name or type QUIT to exit: \n
input1.csv ENTER
10\n
Please enter the file name or type QUIT to exit: \n
input0.csv ENTER
File input0.csv is empty.\n
Ask one question at (O)Remot...
Please enter the file name or type QUIT to exit: \n
quit ENTER
Please enter the file name or type QUIT to exit: \n
input2.csv ENTER
File input2.csv is not found.\n
Please re-enter the file name or type QUIT to exit: \n
QUIT ENTER
Screen Shot 2023-12-11 at 4.21.43 PM
V
50
G
Search
Transcribed Image Text:Q Test Case 5 Failed Show what's missing Test Case 6 Failed Test Case 1 Show what's missing Failed Test Case 2 Test Case 7 Failed Show what's missing Please enter the file name or type QUIT to exit: \n input1.csv ENTER 10 \n Failed Show what's missing Test Case 3 Failed Show what's missing Please enter the file name or type QUIT to exit: \n input2x2.csv ENTER -67,-11\n -70,-27\n Show what's missing Please enter the file name or type QUIT to exit: \n input10x10 .csv ENTER -51,-46, -21, -19, 45,56,96 \n -58,-27,8,29,34,71,85 \n -87,-82, 40, 50, 50, 51, 100 \n -47,-32,-27, -25,-24, 46,88 \n -75,-47,-41,-16, 43, 85,95 \n -78,-77,-69, -25,0, 78,94 \n -95,-86, -80,-32,-31, -22, 82 \n -89,-68, -52,-14,-4, 10, 68 \n -59,-52,-51,-48,-34, 26, 33 \n -66,-47,-42,-24, 16, 80, 80 \n Please enter the file name or type QUIT to exit: \n input2.csv ENTER Test Case 4 Failed Show what's missing File input2.csv is not found.\n Please re-enter the file name or type QUIT to exit: \n input1.csv ENTER 10\n Please enter the file name or type QUIT to exit: \n input0.csv ENTER File input0.csv is empty.\n Ask one question at (O)Remot... Please enter the file name or type QUIT to exit: \n quit ENTER Please enter the file name or type QUIT to exit: \n input2.csv ENTER File input2.csv is not found.\n Please re-enter the file name or type QUIT to exit: \n QUIT ENTER Screen Shot 2023-12-11 at 4.21.43 PM V 50 G Search
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Files and Directory
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