Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

* * * * Answer in java * * * * File I / O ( Writing ) The purpose of this exercise is to

**** Answer in java ****
File I/O (Writing)
The purpose of this exercise is to provide you with the opportunity to create command-line applications that can create and write to files.
Learning objectives
After completing this exercise, you'll understand:
How to programmatically create and write to text files.
How to read, interpret, and resolve errors related to file I/O.
Evaluation criteria and functional requirements
The project must not have any build errors.
The program writes the expected results to a file.
Paths to files aren't hard-codedin other words, the user must be able to enter the path to the input file.
Your console application works as expected when you run it.
Each file has a main method that allows you to run it as a console application.
The unit tests pass as expected.
Note: Tests are only provided for the FindAndReplace and FizzWriter exercises.
Part One: Create a find and replace program
In this exercise, you'll write a program that finds all occurrences of a user-specified word in a text file and replaces it with another user-specified word. You'll write the text with the replaced word to a different text file.
The program must prompt the user for the following values:
The search word
The word to replace the search word with
The source file
This must be an existing file. If the user enters an invalid source file, the program indicates this to the user and exits.
The destination file
The program creates a copy of the source file with the requested replacements at this location. If the file already exists, it must be overwritten. If the user enters an invalid destination file, the program indicates this to the user and exits.
Note: This is a case-sensitive search. If your search word is Bacon, then you must not replace bacon.
Here's an example of what your application could look like:
What is the search word?
bacon
What is the replacement word?
ham
What is the source file?
[path-to-source-file]
What is the destination file?
[path-to-destination-file]
Examples
Here are some examples that demonstrate the requirements of this exercise. The tests for this exercise test each of these scenarios. These examples use a hypothetical text file with the following contents:
apple Bacon coconut bacon
bread bacon Apple cherry
Multiple occurrences
For the search word bacon and the replacement word ham, the contents of the destination file would be:
apple Bacon coconut ham
bread ham Apple cherry
Remember that the search is case-sensitive, which is why the capitalized Bacon isn't replaced.
Single occurrence
For the search word Apple and the replacement word carrot, the contents of the destination file would be:
apple Bacon coconut bacon
bread bacon carrot cherry
Remember that the search is case-sensitive, which is why it only replaces the capitalized Apple.
No occurrences
For the search word honey and the replacement word ketchup, the contents of the destination file would be the same as the source file:
apple Bacon coconut bacon
bread bacon Apple cherry
Tests
Make sure each application functions as expected by running it before running your unit tests.
You can find the tests for this exercise in the file src/test/java/com/techelevator/FindAndReplaceTests.java. All tests must pass to complete this exercise.
Part Two: Create a FizzWriter program
Create a program that writes out the result of FizzBuzz (1 to 300) to a file:
If the number is divisible by 3, print Fizz.
If the number is divisible by 5, print Buzz.
If the number is divisible by 3 and 5, print FizzBuzz.
Otherwise, print the number.
The program must prompt the user for the following values:
The destination file
If the file already exists, it must be overwritten. If the user enters an invalid destination file, the program indicates this and exits.
The tests for this exercise are in the file src/test/java/com/techelevator/FizzWriterTests.java. All tests must pass to complete this exercise.
File splitter (Challenge)
Create an application that takes a significantly large input file and splits it into smaller file chunks. These types of files were common back when floppy disks were popular and couldn't hold a larger program on their own.
To determine how many files you need to create, ask the user for the maximum amount of lines to appear in each output file.
Sample Input/Output:
Where is the input file (please include the path to the file)?[path-to-file]/input.txt
How many lines of text (max) should there be in the split files? 3
The input file has 50 lines of text.
Each file that is created must have a sequential number assigned to it.
For a 50 line input file "input.txt", this produces 17 output files.
**GENERATING OUTPUT**
Generating input-1.txt
Generating input-2.txt
Generating input-3.txt
Generating input-4.txt
Generating input-5.txt
Generating input-6.txt
Generating input-7.txt
Generating input-8.txt
Generating input-9.txt
Generating input-10.txt
Generating input-12.txt
Generating input-13.txt

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

Database Systems Design Implementation And Management

Authors: Peter Rob, Carlos Coronel

6th International Edition

061921323X, 978-0619213237

More Books

Students also viewed these Databases questions

Question

4. Identify cultural variations in communication style.

Answered: 1 week ago

Question

9. Understand the phenomenon of code switching and interlanguage.

Answered: 1 week ago

Question

8. Explain the difference between translation and interpretation.

Answered: 1 week ago