Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Note:****The menu should contain the following options: Capitalize all words Low

ID: 3788060 • Letter: N

Question

Note:****The menu should contain the following options:

Capitalize all words

Lowercase all words

Sample Session

This is an example run of the program. The input and output files are shown after the code.

Please enter the input data file name:

input.txt

Please enter the output data file name:

Output.txt

Choose an option:

Capitalize all words

Lowercase all words

A

Process another file?

Y

Please enter the input data file name:

input.txt

Please enter the output data file name: output2.txt Choose an option:

Capitalize all words

Lowercase all words

B

Process another file? n

Process finished with exit code 0

Output from session

Input file:

line One linE two

Line Three

Output file for option A:

LINE ONE

LINE TWO

LINE THREE

Output file for option B:

line one line two line three

Problem Statement mplement the following flow chart in Java. Sart Request data file Request output yes no Process data 1 of 2 no

Explanation / Answer

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;


public class FileProcessor {

   public static void readFileAndTakeAction(String input, String output, int action)
   {
       BufferedWriter bw = null;
       FileWriter fw = null;
       try(BufferedReader br = new BufferedReader(new FileReader(input))) {
           fw = new FileWriter(output);
           bw = new BufferedWriter(fw);
       for(String line; (line = br.readLine()) != null; ) {
           if (action == 2) // To lower
           {
               bw.write(line.toLowerCase());
               System.out.println(line.toLowerCase());
           }
           else // to upper
           {
               bw.write(line.toUpperCase());
               System.out.println(line.toUpperCase());
           }
       }
       } catch (FileNotFoundException e) {
           System.out.println("File not found");
           e.printStackTrace();
       } catch (IOException e) {
           e.printStackTrace();
       }
   }
  
   public static void main(String[] args)
   {
       Scanner sc = new Scanner(System.in);
       while(true)
       {
           System.out.print("Please enter the input data file name: ");
           String input = sc.nextLine();
          
           System.out.print("Please enter the output data file name: ");
           String output = sc.nextLine();
          
           System.out.println("Choose an option: ");
           System.out.println("A Capitalize all words");
           System.out.println("B Lowercase all words");
           String actionString = sc.nextLine();
           int action = 0;;
           if (actionString.equals("A"))
           {
               action = 1;
           }
           else
           {
               action = 2;
           }
           readFileAndTakeAction(input, output, action);
          
           System.out.println("Process another file?");
           String choice = sc.nextLine();
          
           if (choice.equals("Y"))
           {
               continue;
           }
           else
           {
               break;
           }
       }
       System.out.println("Processing finished with exit code 0");
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote