JAVA PPROGRAM   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. Grading guide: 1. Functionality: Does the program work and perform basic functionality as per requirements? (Need to be able to compile and run the program with some input and some output): 40% 2. Correctness: Does the program properly count matches? - 10% 3. Input Validation: Is the user input validated against requirements? - 10% 4. Output Formatting: Is the output formatted according to the requirements: 10% 5. Edge Cases: Does the program work without errors for ALL values of input (missing file, empty file, odd or even number of lines, very large file, etc.) - 10%   Input1.tzt Michael Joshua Cassandra Joseph William Cassandra Matthew Michael Input2.txt Michael Joshua Cassandra Joseph James William Cassandra Matthew Michael Input3.txt Input3.txt is empty Input4.txt Michael Joshua Cassandra Joseph William Matthew James Steven Steven James Matthew William Joseph Cassandra Joshua Michael Test Case 1     Please enter the file name or type QUIT to exit:\n input1.txtENTER Match found: 'Michael' on lines 1 and 8.\n Match found: 'Cassandra' on lines 3 and 6.\n Total of 2 matches found.\n   Test Case 2     Please enter the file name or type QUIT to exit:\n input2.txtENTER Match found: 'Michael' on lines 1 and 9.\n Match found: 'Cassandra' on lines 3 and 7.\n Total of 2 matches found.\n   Test Case 3     Please enter the file name or type QUIT to exit:\n input3.txtENTER File 'input3.txt' is empty.\n   Test Case 4     Please enter the file name or type QUIT to exit:\n input4.txtENTER Match found: 'Michael' on lines 1 and 16.\n Match found: 'Joshua' on lines 2 and 15.\n Match found: 'Cassandra' on lines 3 and 14.\n Match found: 'Joseph' on lines 4 and 13.\n Match found: 'William' on lines 5 and 12.\n Match found: 'Matthew' on lines 6 and 11.\n Match found: 'James' on lines 7 and 10.\n Match found: 'Steven' on lines 8 and 9.\n Total of 8 matches found.\n   Test Case 5     Please enter the file name or type QUIT to exit:\n input5.txtENTER File 'input5.txt' is not found.\n Please re-enter the file name or type QUIT to exit:\n input1.txtENTER Match found: 'Michael' on lines 1 and 8.\n Match found: 'Cassandra' on lines 3 and 6.\n Total of 2 matches found.\n   Test Case 6     Please enter the file name or type QUIT to exit:\n qUiTENTER   Test Case 7     Please enter the file name or type QUIT to exit:\n input5.txtENTER File 'input5.txt' is not found.\n Please re-enter the file name or type QUIT to exit:\n quitENTER

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
JAVA PPROGRAM
 
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.
Grading guide:
1. Functionality: Does the program work and perform basic functionality as per requirements? (Need to be able to compile and run the program with some input and some output): 40%
2. Correctness: Does the program properly count matches? - 10%
3. Input Validation: Is the user input validated against requirements? - 10%
4. Output Formatting: Is the output formatted according to the requirements: 10%
5. Edge Cases: Does the program work without errors for ALL values of input (missing file, empty file, odd or even number of lines, very large file, etc.) - 10%
 

Input1.tzt

Michael
Joshua
Cassandra
Joseph
William
Cassandra
Matthew
Michael

Input2.txt

Michael
Joshua
Cassandra
Joseph
James
William
Cassandra
Matthew
Michael

Input3.txt

Input3.txt is empty

Input4.txt
Michael
Joshua
Cassandra
Joseph
William
Matthew
James
Steven
Steven
James
Matthew
William
Joseph
Cassandra
Joshua
Michael

Test Case 1

 
 
Please enter the file name or type QUIT to exit:\n
input1.txtENTER
Match found: 'Michael' on lines 1 and 8.\n
Match found: 'Cassandra' on lines 3 and 6.\n
Total of 2 matches found.\n
 

Test Case 2

 
 
Please enter the file name or type QUIT to exit:\n
input2.txtENTER
Match found: 'Michael' on lines 1 and 9.\n
Match found: 'Cassandra' on lines 3 and 7.\n
Total of 2 matches found.\n
 

Test Case 3

 
 
Please enter the file name or type QUIT to exit:\n
input3.txtENTER
File 'input3.txt' is empty.\n
 

Test Case 4

 
 
Please enter the file name or type QUIT to exit:\n
input4.txtENTER
Match found: 'Michael' on lines 1 and 16.\n
Match found: 'Joshua' on lines 2 and 15.\n
Match found: 'Cassandra' on lines 3 and 14.\n
Match found: 'Joseph' on lines 4 and 13.\n
Match found: 'William' on lines 5 and 12.\n
Match found: 'Matthew' on lines 6 and 11.\n
Match found: 'James' on lines 7 and 10.\n
Match found: 'Steven' on lines 8 and 9.\n
Total of 8 matches found.\n
 

Test Case 5

 
 
Please enter the file name or type QUIT to exit:\n
input5.txtENTER
File 'input5.txt' is not found.\n
Please re-enter the file name or type QUIT to exit:\n
input1.txtENTER
Match found: 'Michael' on lines 1 and 8.\n
Match found: 'Cassandra' on lines 3 and 6.\n
Total of 2 matches found.\n
 

Test Case 6

 
 
Please enter the file name or type QUIT to exit:\n
qUiTENTER
 

Test Case 7

 
 
Please enter the file name or type QUIT to exit:\n
input5.txtENTER
File 'input5.txt' is not found.\n
Please re-enter the file name or type QUIT to exit:\n
quitENTER
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education