Create a program that reads a list of names from a source file and writes those names to a CSV file.
Need help with this assignment?Get an original answer from a qualified tutor — from $10/page.
Get it written →Name your class LoopsFiles
Create a program that reads a list of names from a source file and writes those names to a CSV file.
The source file name and target CSV file name should be requested from the user
The source file can have a variable number of names so your program should be dynamic enough to read as many names as needed
When writing your CSV file, the first row (header row) should be “Number, Name”.
The final CSV should have the header row and a row with the sequential number, name read.
The program should display an error message if the source file doesn’t exist.
If the destination file exists the program should warn the user and prompt the user if they want to overwrite the existing file (Y/N).
The user should be prompted until they enter Y for yes to overwrite, or enter a unique name after answering N for the overwrite prompt.
Submit your single .java file
Source file example:
John
Peter
Jane
Mary
Evelyn
Daniel
New CSV File example:
Number, Name
1,John
2,Peter
3,Jane
4,Mary
5,Evelyn
6,Daniel
Example Scenario 1 – Normal run:
Enter source file name: source.txt
Enter destination file name: destination.csv
Your file is ready!
Example Scenario 2 – File doesn’t exist:
Enter source file name: source.txt
Enter destination file name: destination.csv
Source file doesn’t exist!
Example Scenario 3 – Target file already exists (overwrite):
Enter source file name: source.txt
Enter destination file name: destination.csv
Target file already exists. Overwrite existing file? (Y/N): N
Enter destination file name: destination.csv
Target file already exists. Overwrite existing file? (Y/N): N
Enter destination file name: destination.csv
Target file already exists. Overwrite existing file? (Y/N): N
Enter destination file name: destination.csv
Target file already exists. Overwrite existing file? (Y/N): Y
Your file is ready!
Example Scenario 4 – Target file already exists (new name given):
Enter source file name: source.txt
Enter destination file name: destination.csv
Target file already exists. Overwrite existing file? (Y/N): N
Enter destination file name: destination.csv
Target file already exists. Overwrite existing file? (Y/N): N
Enter destination file name: destination2.csv
Your file is ready!
Get a plagiarism-free answer to this question
Send us your instructions and we’ll match you with the best writer in your subject.
- 100% human-written, zero AI
- Turnitin report included
- Confidential — we never share your data
- Free revisions & refunds