Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CopyNames : copy peoples names from an input to an output file, correcting how the names are formatted: You are given a text file containing

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

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_2

Step: 3

blur-text-image_3

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

Repairing And Querying Databases Under Aggregate Constraints

Authors: Sergio Flesca ,Filippo Furfaro ,Francesco Parisi

2011th Edition

146141640X, 978-1461416401

More Books

Students also viewed these Databases questions

Question

Which diagnostic test is most commonly used to confirm PROM?

Answered: 1 week ago

Question

What is the hallmark clinical feature of a molar pregnancy?

Answered: 1 week ago