Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a phonebook application. It should use arrays to store information about many phonebook entries. Each entry should consist of a first name (a String),
Write a phonebook application. It should use arrays to store information about many phonebook entries. Each entry should consist of a first name (a String), a last name (a String), and a phone number (a String, assumed to be of the form nnn-nnn-nnnn, such as 212-563-0987). In addition to storing this information, the program should allow users to perform some operations with the data, such as lookup and reverse lookup. The data should be stored in three arrays of Strings: one for the first names, one for the last names, and one for the phone numbers. Give each array a size of MAX_ENTRIES, a constant which should be initialized to 10. Near the beginning of the program, the program should read in the initial database of phonebook entries from a file (whose name should be provided by the user) and store the data in the arrays. The exact number of lines in the file is not known in advance. However, you can assume that the file contains no more than 10 lines, and that each line has the following format: first_name last_name phone_number For example, one line of the file might be: John Doe 234-657-1234 You can assume that there are no two lines in the file with the same combination of first name and last name. For example, you can assume that there will not be two lines with the name John Doe. (However, it is possible for the file to contain the name Jane Doe in addition to John Doe.) After reading in the data and storing it in the arrays, the program should provide the user with a list of options, as described below. Based on the user's response, the program should obtain any a dditional needed information from the user, and perform the requested task. The program should repeatedly do this until the user indicates that they would like to quit the program. The options are: - I (lookup): The program should ask for a first name and a last name. If there is an entry that has that combination of first name and last name, the program should print the information about that entry. (Assume that there are no two entries that share the same combination of first name and last name.) Otherwise, the program should print an error message. - r (reverse lookup): The program should ask for a phone number, and should print the first name and last name of the entry that has that phone number. (If there are multiple entries with the same phone number, then print any of those entries.) If there is no entry that has that phone number, the program should print an error message. - c (change number): This option allows the user to update an entry's phone number. The program should ask for a first name and a last name. If there is an entry with that combination of first name and last name, the program should ask for the new phone number and update the phone number for the appropriate entry. Otherwise, the program should print an error message. - a (add entry): This option allows the user to update an entry's phone number. If there is no room in the arrays for another entry (that is, if the current number of entries is equal to MAX_EN TRIES), the program should print an error message. Otherwise, the program should ask for a first name and a last name. If there already is an entry with this combination of first name and last name, the program should print an error message. Otherwise, the program should ask for a phone number and add the new entry to the arrays. - q (quit): This option allows the user to quit the program. If the user enters any other choice, the program should print an error message. At the end of the program, once the user has decided to quit, the program should print the updated database to a file (whose name should be provided by the user) in the same format as the input file. Please carefully read the sample run below. The program's output is in white, and the user's keyboard input in yellow. This sample run uses a file named entries input.txt, which you can see at this link. (Note that this particular input file contains exactly 8 lines, but the program should be designed to work with an input file that has anywhere between 0 and 10 lines.) At the end, this sample run prints a file named entries_output.txt, which you can see at this link. Note: Do not create multiple Scanners for reading keyboard input. Instead, create one keyboard scanner in the main method, and then pass it to the other methods as needed. CodeLab has issues when you create multiple Scanners for reading keyboard input. Additionally, even without CodeLab, it's good to minimize the number of objects that a program creates. Another note: Do not use Scanner's nextline method to read in a String (such as a file name). Instead, use Scanner's next method. Additional Notes: - entries_input.txt should not be modified - Regarding your code's standard output, CodeLab will ignore case errors and will ignore whitespace (tabs, spaces, newlines) altogether
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