Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete and run/test the program. Complete the program according to the line comments in the main method. make sure the program compiles and runs without

Complete and run/test the program.

Complete the program according to the line comments in the main method.

make sure the program compiles and runs without any errors, and produces the correct/desired results.

Sample Run (user input in color):

Enter the input file name: input8.txt Enter the output file name: output8.txt

When your program execution is complete, open the output file (using, e.g., NotePad or NotePad++). It should contain a single line:

reading text is to use the Scanner class.In Java, the most convenient mechanism for

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

public class Lab { public static void main(String[] args) throws IOException { // 1. Declare and create a new Scanner variable named keyboard for keyboard input // 2. Declare 3 String variables named inputFileName, outputFileName, and line // 3. Declare a File variable named inputFile // 4. Declare a Scanner variable named fileReader // 5. Declare a PrintWriter variable named fileOutput // 6. Declare 2 int variables named lineLength and middleIndex // 7. Using the keyboard Scanner, get the inputFileName String as user input // 8. Create a new File object with the inputFileName, assign it to the inputFile variable // 9. Create a new Scanner object with the inputFile, assign it to the fileReader variable // 10. Using the fileReader Scanner, get the line String from the input file // HINT: use the Scanner nextLine method // 11. Set the lineLength variable to the line's length // HINT: use the String length method // 12. Set the middleIndex variable to the index of the line's middle character // 13. Reset the line variable to the String resulting from switching the 2 halves of the line // HINT: use the String substring method and the String concatenation operator // 14. Using the keyboard Scanner, get the outputFileName String as user input // 15. Create a new PrintWriter object with the outputFileName, assign it to the fileOutput variable // 16. Using the fileOutput PrintWriter, write the line String to the output file // HINT: use the PrintWriter println method // 17. Close the fileReader Scanner // 18. Close the fileOutput PrintWriter } // end main } // end class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning VB 2008 Databases

Authors: Vidya Vrat Agarwal, James Huddleston

1st Edition

1590599470, 978-1590599471

Students also viewed these Databases questions

Question

=+1 Where are the best places in the world to live (and work)?

Answered: 1 week ago

Question

=+Are you interested in working on global teams?

Answered: 1 week ago

Question

=+Do you want to work from home?

Answered: 1 week ago