Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Collapse.java, write a method called collapseSpaces that accepts two parameters: (1) an input file Scanner and (2) an output file PrintStream. The method should

In Collapse.java, write a method called collapseSpaces that accepts two parameters: (1) an input file Scanner and (2) an output file PrintStream. The method should read the contents of the file and output it with all its tokens separated by single spaces, collapsing any sequences of multiple spaces into single spaces. For example, consider the following text:

 many spaces on this line!

If this text were a line in the file, the same line should be output as follows:

many spaces on this line!

Your main method should prompt the user for input and output filenames, then pass the appropriate Scanner and PrintStream to collapseSpaces method. If the output file already exists, print a message and end program without calling the collapseSpaces method.

Hints:

Your input and output files should be different files (filenames) to avoid overwriting files

Your method should work with input files that have multiple lines. Use a line-based approach. Keep the line breaks the same.

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

Statistical And Scientific Database Management International Working Conference Ssdbm Rome Italy June 21 23 1988 Proceedings Lncs 339

Authors: Maurizio Rafanelli ,John C. Klensin ,Per Svensson

1st Edition

354050575X, 978-3540505754

More Books

Students also viewed these Databases questions

Question

1. What are your creative strengths?

Answered: 1 week ago

Question

What metaphors might describe how we work together?

Answered: 1 week ago