Question
JAVA eclipse required output on the bottom Please help. Write a program that prompts the user to enter a file name, then opens the file
JAVA eclipse required output on the bottom Please help.
Write a program that prompts the user to enter a file name, then opens the file in text mode and reads names. The file contains one name on each line. The program then compares each name with the name that is at the end of the file in a symmetrical position. For example if the file contains 10 names, the name #1 is compared with name #10, name #2 is compared with name #9, and so on. If you find matches you should print the name and the line numbers where the match was found.
While entering the file name, the program should allow the user to type quit to exit the program.
If the file with a given name does not exist, then display a message and allow the user to re-enter the file name.
The file may contain up to 100 names.
You can use an array or ArrayList object of your choosing, however you can only have one array or ArrayList.
Input validation:
a) If the file does not exist, then you should display a message "File 'somefile.txt' is not found." and allow the user to re-enter the file name.
b) If the file is empty, then display a message "File 'somefile.txt' is empty." and exit the program.
Hints:
a) Perform file name input validation immediately after the user entry and use a while loop .
b) Use one integer variable to count names in the file and another one for counting matches.
d) You can use either a while loop or a for loop to find the matches.
These are the required output at the bottom.
View required output
Test Case 1
Standard Input | Files in the same directory |
---|---|
input1.txt | input2.txt input1.txt input3.txt input4.txt |
Please enter the file name or type QUIT to exit: Match found: 'John' on lines 1 and 8. Match found: 'Illia' on lines 3 and 6. Total of 2 matches found.
Test Case 2
Standard Input | Files in the same directory |
---|---|
input2.txt | input2.txt input1.txt input3.txt input4.txt |
Please enter the file name or type QUIT to exit: Match found: 'John' on lines 1 and 9. Match found: 'Illia' on lines 3 and 7. Total of 2 matches found.
Test Case 3
Standard Input | Files in the same directory |
---|---|
input3.txt | input2.txt input1.txt input3.txt input4.txt |
Please enter the file name or type QUIT to exit: File 'input3.txt' is empty.
Test Case 4
Standard Input | Files in the same directory |
---|---|
input4.txt | input2.txt input1.txt input3.txt input4.txt |
Please enter the file name or type QUIT to exit: Match found: 'John' on lines 1 and 16. Match found: 'Jose' on lines 2 and 15. Match found: 'Illia' on lines 3 and 14. Match found: 'Jannet' on lines 4 and 13. Match found: 'Brian' on lines 5 and 12. Match found: 'Ricky' on lines 6 and 11. Match found: 'Russel' on lines 7 and 10. Match found: 'Miguel' on lines 8 and 9. Total of 8 matches found.
Test Case 5
Standard Input | Files in the same directory |
---|---|
input5.txtENTER input1.txt | input2.txt input1.txt input3.txt input4.txt |
Please enter the file name or type QUIT to exit: File 'input5.txt' is not found. Please re-enter the file name or type QUIT to exit: Match found: 'John' on lines 1 and 8. Match found: 'Illia' on lines 3 and 6. Total of 2 matches found.
Test Case 6
Standard Input | Files in the same directory |
---|---|
qUiT | input2.txt input1.txt input3.txt input4.txt |
Please enter the file name or type QUIT to exit:
Test Case 7
Standard Input | Files in the same directory |
---|---|
input5.txtENTER quit | input2.txt input1.txt input3.txt input4.txt |
Please enter the file name or type QUIT to exit: File 'input5.txt' is not found. Please re-enter the file name or type QUIT to exit:
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