Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
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
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
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
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
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
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
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
input5.txtENTER
File 'input5.txt' is not found.\n
Please re-enter the file name or type QUIT to exit:\n
quitENTER
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images
Knowledge Booster
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
- C++ Create a program that reads a file containing a list of songs and prints the songs to the screen one at a time. After each song is printed, except for the last song, the program asks the user to press enter for more. After the last song, the program should say that this was the last song and quit. If there were no songs in the file to begin with, the program should say that there are no songs to show and quit. The program should begin by asking the user for the name of the input file. Each song consists of a title, artist, and year. In the file, each song is given on three consecutive lines. Create this program using a class Song.arrow_forwardPython A Personal Fitness Tracker is a wearable device that tracks your physical activity, caloriesburned, heart rate, sleeping patterns, and so on. One common physical activity that most ofthese devices track is the number of steps you take each day. The file contains the number of steps a person has taken each day for a year.(Create a random step.txt file) Write a program that reads the file, then displays the average number of steps taken for each month.arrow_forwardYou are working for a lumber company, and your employer would like a program that calculatesthe cost of lumber for an order. The company sells pine, fir, cedar, maple, and oak lumber.Lumber is priced by board feet. One board foot equals one square foot that is one inch thick. Theprice per board foot is given in the following table: (image 1) The lumber is sold in different dimensions (specified in inches of width and height, and feet oflength) that need to be converted to board feet. For example, a 2 x 4 x 8 piece is 2 inches wide, 4inches high, and 8 feet long, and is equivalent to 5.333 board feet (2 * 4 * 8 = 64, which whendivided by 12 = 5.333 board feet). An entry from the user will be in the form of a letter and fourinteger numbers. The integers are the number of pieces, width, height, and length. The letter willbe one of P, F, C, M, O (corresponding to the five kinds of wood) or T, meaning total. When theletter is T, there are no integers following it on the line. The program…arrow_forward
- A file object’s writelines method automatically writes a newline ('\n') after writing each list item to the file.True or Falsearrow_forwardThe Apgar Medical group keeps a patient file for each doctor in the office. Each record contains the patient's first and last name, home address, and birth year. The records are sorted in ascending birth year order. Write a program so that display a count of the number of patients born each year John Hanson, 23 Elm, 1927Mary Locust, 476 Maple, 1950Susan Monroe, 512 Peachtree, 1957Carol Fortune, 2819 Locust, 1960James Fortune, 2819 Locust, 1963Lawrence Fish, 12 Elm, 1968Janice Weiss, 234 Birch, 1971Henry Garza, 199 Second, 1973Kimberly Swanson, 310 Appletree, 1980Louis Claude, 2716 Third, 1981Jill Fox, 12 Oak, 1985Opal Reynolds, 78 County Line, 1987Francis Dumas, 67 Fourth, 1992Madison Conroy, 23 Fifth, 1996Daniel Moy, 100 Sunset, 1987arrow_forwardWord Puzzle GameIn this assignment is only for individual. You are going to decode the scrambled word into correct orderin this game. One round of play is as follows:1. Computer reads a text file named words.txt2. Computer randomly picks one word in the file and randomly scrambles characters in the wordmany times to hide the word3. Computer displays the scrambled word to user with indexes and gives the user options to1. Swap two letters in word based on index given2. Solve the puzzle directly3. Quit the game4. If a player chooses to swap letters, the computer reads two indexes and swaps the letters. Thegame resume to step 3 with the newly guessed word. If the resulted word after swapping is thesecret word, the game is over.5. If a user chooses to solve directly, computer prompts the user to enter the guessed word. If it’scorrect, the game is over, otherwise goes to step 3.6. After game is over, display how many times the player has tried to solve the puzzle.The following is sample…arrow_forward
- Write a code segment that searches a Grid object for a negative integer. The loop should terminate at the first instance of a negative integer in the grid, and the variables row and column should be set to the position of that integer. Otherwise, the variables row and column should equal the number of rows and columns in the grid. *Pythonarrow_forwardPROGRAM NEEDS TO MATCH EXAMPLE PHOTO Write a program ( lab6.cpp ) that gives and takes advice on program writing. The program starts by writing a piece of advice to the screen and asking the user to type in a different piece of advice. The program then ends. The next person to run the program receives the advice given by the person who last ran the program. The advice is kept in a file, and the contents of the file change after each run of the program. You can use your editor to enter the initial piece of advice in the file so that the first person who runs the program receives some advice. Allow the user to type in advice of any length so that it can be any number of lines long. The user is told to end his or her advice by pressing the Return key two times. Your program can then test to see that it has reached the end of the input by checking to see when it reads two consecutive occurrences of the character ‘\n’. Hints:- You need to look at each character as it is read to see if it is…arrow_forwardThe function print_last_line in python takes one parameter, fname, the name of a text file. The function should open the file for reading, read the lines of the file until it reaches the end, print out the last line in the file, report the number of lines contained in the file, and close the file. Hint: Use a for loop to iterate over the lines and accumulate the count. For example: Test Result print_last_line("wordlist1.txt") maudlin The file has 5 lines.arrow_forward
- I needed the FiveOnly program in Java just like the Programming Challenge #13 in the Starting Out With Java (7th Edition) textbook. It was part of Chapter 4. Thank you so much!arrow_forwardJAVA PROGRAM Chapter 4. Homework Assignment (read instructions carefully) Write a program that asks the user for the name of a file. The program should read all the numbers from the given file and display the total and average of all numbers in the following format (three decimal digits): Total: nnnnn.nnn Average: nnnnn.nnn Class name: FileTotalAndAverage double_input1.txt double_input2.txt Test Case 1 Please enter the file name: \ndouble_input1.txtENTERTotal: -5,748.583\nAverage: -57.486\n Test Case 2 Please enter the file name: \ndouble_input2.txtENTERTotal: 112,546.485\nAverage: 56.273\n Test Case 3 Please enter the file name: \ndouble_input3.txtENTERFile 'double_input3.txt' does not exist.\nPlease enter the file name again: \ndouble_input1.txtENTERTotal: -5,748.583\nAverage: -57.486\narrow_forwardThis Python Lab 9 Lab: Write a file copying program. The program asks for the name of the file to copy from (source file) and the name of the file to copy to (destination file). The program opens the source file for reading and the destination file for writing. As the program reads each line from the source file and it writes the line to the destination file. When every line from the source file has been written to the destination file, it close both files and print “Copy is successful.” In the sample run, “add.py” is the source file and “add-copy.py” is the destination file. Note that both “add-copy.py” is identical to “add.py” because “add-copy.py” is a copy of “add.py”. Sample run: Enter file to copy from: add.py Enter file to copy to : add-copy.py Copy is successful. Source file: add.py print("This program adds two numbers") a = int(input("Enter first number: ")) b = int(input("Enter second number: ")) print(f"{a} + {b} = {a+b}") Destination file:…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education