Answered step by step
Verified Expert Solution
Link Copied!

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 added(no need to finish)
Finding a phone number entry by name(please finish this part)
Delete a phone number entry by name(no need to finish)
Here is a part of the uncompleted java code given in the task. Please finish this part:
// Find an entry in the phone book by name
public void findNumberByName(){
// Get the name
System.out.print("Please enter the name: ");
String name = scanner.next();
//
// Task 2- 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.print("Please enter the name: ");
String name = scanner.next();
// Prepare an array to store the phone number entries
PhoneBookEntry[] entries = new PhoneBookEntry[100];
// Store the number of entries in the phone book
int numOfEntries =0;
//
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:2358-6333
FMO:2358-6421
FO:2358-6418
HRO:2358-6580
ITSC:2358-6188
SAO:2358-0842
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 (entry.getName().equals(name)){
...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, i.e.:
return;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions