Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help me complete the following java programming tasks. I need a correct answer as a reference for me to correct my own tasks. Thank
Please help me complete the following java programming tasks. I need a correct answer as a reference for me to correct my own tasks. Thank you very much.
In this exercise you need to complete these additional features one by one for the extended phone book program. Here are the tasks in the exercise:
Checking for duplicated entry when a new phone number is addedno need to finish
Finding a phone number entry by nameplease finish this part
Delete a phone number entry by nameno need to finish
The second task is finding a phone number by name.
This task is in the findNumberByName method. That means you can use most of the code from the listNumbers method. The only place you need to change is to check the name of the entry before you print, like this:
if entrygetNameequalsname
print the entry...
If the name of the entry is the entered name, you will first print the corresponding entry and then finish the method using a return statement, ie:
return;
Here is a part of the uncompleted java code given in the task. Please finish this part:
import java.util.Scanner;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.nio.charset.Charset;
import java.ioBufferedReader;
import java.ioBufferedWriter;
public class PhoneBook
Find an entry in the phone book by name
public void findNumberByName
Get the name
System.out.printPlease enter the name: ;
String name scanner.next;
Task Finding and printing an entry by name
Get the path of the text file
Use a BufferedReader to read the data one by one
For each data line create a PhoneBookEntry
If the name in the PhoneBookEntry is equal to the input name
print the PhoneBookEntry appropriately and exit the method
Print a message if the name cannot be found
Delete an entry in the phone book by name
public void deleteNumberByName
Get the name
System.out.printPlease enter the name: ;
String name scanner.next;
Prepare an array to store the phone number entries
PhoneBookEntry entries new PhoneBookEntry;
Store the number of entries in the phone book
int numOfEntries ;
In this exercise, each phone number entry is still stored as a separate line. However, the name and the phone number of one entry are separated by a colon, without a space. You can see the format of the phone book from the given phonebook.txt as shown below:
CSO:
FMO:
FO:
HRO:
ITSC:
SAO:
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