Answered step by step
Verified Expert Solution
Question
1 Approved Answer
* * * * Answer in java * * * * File I / O ( Writing ) The purpose of this exercise is to
Answer in java
File IO Writing
The purpose of this exercise is to provide you with the opportunity to create commandline 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 IO
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 hardcodedin 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 userspecified word in a text file and replaces it with another userspecified 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 casesensitive 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?
pathtosourcefile
What is the destination file?
pathtodestinationfile
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 casesensitive 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 casesensitive 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 srctestjavacomtechelevatorFindAndReplaceTestsjava. All tests must pass to complete this exercise.
Part Two: Create a FizzWriter program
Create a program that writes out the result of FizzBuzz to to a file:
If the number is divisible by print Fizz.
If the number is divisible by print Buzz.
If the number is divisible by and 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 srctestjavacomtechelevatorFizzWriterTestsjava. 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 InputOutput:
Where is the input file please include the path to the filepathtofileinputtxt
How many lines of text max should there be in the split files?
The input file has lines of text.
Each file that is created must have a sequential number assigned to it
For a line input file "input.txt this produces output files.
GENERATING OUTPUT
Generating inputtxt
Generating inputtxt
Generating inputtxt
Generating inputtxt
Generating inputtxt
Generating inputtxt
Generating inputtxt
Generating inputtxt
Generating inputtxt
Generating inputtxt
Generating inputtxt
Generating inputtxt
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started