Question: Please fix the following two files from the same question. Please only change the FIXME portions. Thanks! HERE ARE INSTRUCTIONS You will be building an

Please fix the following two files from the same question. Please only change the FIXME portions. Thanks!

HERE ARE INSTRUCTIONS

You will be building an ArrayList to represent a phone book.

(1) Complete the following two files

PhoneBookEntry.java - Class definition

PhoneBook.java - Contains main() method

(2) Complete the PhoneBookEntry class per the following specifications:

Private fields

String name

String phoneNumber

Constructor with name and phoneNumber as parameters (in that order)

Public member methods

getName() - Accessor

getPhoneNumber() - Accessor

setPhoneNumber(String number) - Mutator

printPhoneBookEntry()

(3) Complete the PhoneBook class per the following specifications:

Private field

ArrayList list

Default constructor.

Public member methods

getEntry(String name)

addEntry(String name, String number)

removeEntry(String name)

editEntry(String name, String number)

lookUpPhoneNumber(String name)

printBook()

(4) In main() method

prompt the user for three phone book entries and add them to the list.

Call the proper method to look up the phone number for Roxanne Hughes.

Call the proper method to update Roxanne Hughes' phone number.

Call the proper method to remove the entry of Juan Alberto Jr.

Output the list again.

____________________________________________________________________________

public class PhoneBookEntry { /*FIXME(1) Define two fields: name and phoneNumber. Both fields are of String type*/ /*FIXME(2) Define a consructor that takes two argument: name, phoneNumber. Parameters are name followed by phone number. */ /*FIXME(3) Define a getter method for the name field*/ /*FIXME(4) Define a getter method for the phoneNumber field*/ /*FIXME(5) Define a setter method for the phoneNumber field*/ public void printPhoneBookEntry() { System.out.println("Name: " + name); System.out.println("Phone Number: " + phoneNumber); } }

_________________________________________________________________________

import java.util.ArrayList; import java.util.Scanner;

public class PhoneBook { /*FIXME(1) Define one field: list, which is an ArrayList of PhoneBookEntry*/ public PhoneBook() { list = new ArrayList(); } /*This method searches list for the PhoneBookEntry with a given name value. Note that this is an exhaustive search which is a very bad practice. We will improve this method in the future after we learn sorting and search algorithms*/ public PhoneBookEntry getEntry(String name) { PhoneBookEntry entry = null; for(int i = 0; i < list.size(); i++) { if(list.get(i).getName().equals(name)) { entry = list.get(i); } } return entry; } public void addEntry(String name, String number) { /*FIXME(2) Complete this method by creating an object of PhoneBookEntry and add it to list*/ } public void removeEntry(String name) { PhoneBookEntry entry = getEntry(name); if(entry != null) { list.remove(entry); System.out.println("Entry has been removed"); } else System.out.println("Entry cannot be found"); } /*FIXME(3) Complete editEntry method. This method searches for the entry with a given name value. If the entry can be found in list, update the phone number of the entry to number and print out Entry has been updated. If the entry cannot be found in list, print out Entry cannot be found*/ public void editEntry(String name, String number) { } /*FIXME(4) Complete lookUpPhoneNumber method. This method searches for the entry with a given name value. If the entry can be found in list, get the phone number of the entry and return the phone number. If the entry cannot be found in list, return null*/ public String lookUpPhoneNumber(String name) { String number = null; return number; } public void printBook() { System.out.println(" Phone Book"); /*FIXME(5) Complete this method to print all the entries in list.*/ } public static void main(String[] args) { final int NUM_ENTRIES = 3; PhoneBook pb = new PhoneBook(); Scanner scnr = new Scanner(System.in); for(int i = 0; i < NUM_ENTRIES; i++) { System.out.println("Entry " + (i + 1) + ":"); System.out.println("Enter name: "); String name = scnr.nextLine(); System.out.println("Enter phone number: "); String number = scnr.nextLine(); pb.addEntry(name, number); } pb.printBook(); String number = pb.lookUpPhoneNumber("Roxanne Hughes"); if(number == null) System.out.println("There is no record for Roxanne Hughes"); else System.out.println("Phone number is " + number); /*FIXME(6) Call proper method to update Roxanne Hughes' phone number to 443-555-1234.*/ /*FIXME(7) Call proper method to remove the entry of "Juan Alberto Jr."*/ System.out.println(""); pb.printBook(); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!