Question: Java Do Chapter 10 Exercise 11 , CopyNames : copy peoples names from an input to an output file, correcting how the names are formatted:

Java

Do Chapter 10 Exercise 11, CopyNames: copy peoples names from an input to an output file, correcting how the names are formatted:

You are given a text file containing the names of people. Every name in the file consists of a first name and last name, that is, exactly two words. Unfortunately, the programmer who created the file of names had a strange sense of humor and did not guarantee that each name was on a single line of the file.

Read this file of names and write them to a new text file, one name per line. For example, if the input file contains the lines:

Bob Jones Fred

Charles Ed

Marston

Jeff

Williams

then the output file should be:

Bob Jones

Fred Charles

Ed Marston

Jeff Williams

Hints:

You can use Scanners next method to read a single word, one at a time, from the input file.

You can assume that each name consists of exactly 2 words, and that there are only complete names in the input file.

To write out each complete name, simply read two words at a time as long as hasNext returns true and write those two words, separated by a space, to the output file.

You can ask the user for the input and output file names or read them from program command arguments.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!