Create a phonebook application that stores name/number pairs, looks up by name o
ID: 3635351 • Letter: C
Question
Create a phonebook application that stores name/number pairs, looks up by name or number, and provide persistent storage of data.This assignment will provide experience with:
• Classes
• Methods
• Arrays
• string
• file I/O
Design the class Phonebook and create a UML diagram.
public class Phonebook {
//data fields
private String[] names;
private int[] phoneNumbers;
// constructors
…
//methods
…
}
Methods
Design methods to implement the following functionalty:
• input names and phone numbers provided by a user;
• input names and phone numbers written from a file;
• look up a name by a number;
• look up a number by a name;
• look up a number by a partial name (e.g., “Jo”);
• output information in pairs (name, number) to a screen;
• output information in pairs (name, number) to a file.
Create a test program to check all the methods.
Explanation / Answer
view source print? 01 /*This program simulates a phonebook. 02 * 03 * 04 * 05 */ 06 07 import java.util.Scanner; 08 09 class PhoneEntry 10 { 11 String lastName; 12 String firstName; 13 String phone; 14 15 PhoneEntry(String lastName, String firstName, String p) 16 { 17 this.lastName = lastName; 18 this.firstName = firstName; 19 phone = p; 20 } 21 22 } 23 24 25 26 class PhoneBook 27 { 28 PhoneEntry[] phoneBook; 29 PhoneBook() 30 { 31 phoneBook = new PhoneEntry[5]; 32 phoneBook[0] = new PhoneEntry( 33 "Smith", "John", "(418)665-1223"); 34 phoneBook[1] = new PhoneEntry( 35 "Smith", "Grace", "(860)399-3044"); 36 phoneBook[2] = new PhoneEntry( 37 "Delgado", "David", "(815)439-9271"); 38 phoneBook[3] = new PhoneEntry( 39 "Delgado", "Jesse", "(312)223-1937"); 40 phoneBook[4] = new PhoneEntry( 41 "Soong", "Connie", "(913)883-2874"); 42 } 43 44 45 46 47 PhoneEntry search(String targetLastName, String targetFirstName) 48 { 49 for (int j = 0; jRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.