can someone help me modify my program? 1. Modify the program so that it asks the
ID: 3550379 • Letter: C
Question
can someone help me modify my program?
1. Modify the program so that it asks the user for the person to look up:
Name? Violet Smith
The number is (312) 223-1937
Name? James Barclay
The number is (418) 665-1223
Name? Scott Eccles
Name not found
Name? quit
good-bye
2. Modify the PhoneEntry class so that it contains firstName, lastName, and phone#.
Last Name? Smith
First Name? Violet
The number is: (312) 223-1937
Last Name? Smith
First Name?
John Smith: (812) 339-4916
Violet Smith: (312) 223-1937
Willoughby Smith: (312) 992-8761
Last Name? quit
good-bye
3. Modify the program program so that it can deal with an array that has null in some cells. Now alter the program so that the user has a choice of 3 actions
-Search for a name
-Add a new name and ph num. to the array
-Delete a name (and ph num.) from the array
This is the program that I created now I just have to modify it.
import java.util.Scanner;
import java.lang.*;
import java.io.*;
import java.text.*;
import java.lang.Math.*;
import java.text.DecimalFormat;
import java.lang.String;
public class PhoneBookTester
{
public static void main (String[] args)
{
String inData;
Scanner scan = new Scanner (System.in);
PhoneBook pb = new PhoneBook();
System.out.println("Enter the data:");
inData = scan.nextLine();
if ( entry != null )
System.out.println( entry.name +
": " + entry.phone );
else
System.out.println("Name not found");
}
}
class PhoneEntry
{
String name; // name of a person
String phone; // their phone number
PhoneEntry( String n, String p )
{
name = n; phone = p;
}
}
class PhoneBook
{
PhoneEntry[] phoneBook;
PhoneBook() // constructor
{
phoneBook = new PhoneEntry[ 5 ] ;
phoneBook[0] = new PhoneEntry(
"James Barclay", "(418)665-1223");
phoneBook[1] = new PhoneEntry(
"Grace Dunbar", "(860)399-3044");
phoneBook[2] = new PhoneEntry(
"Paul Kratides", "(815)439-9271");
phoneBook[3] = new PhoneEntry(
"Violet Smith", "(312)223-1937");
phoneBook[4] = new PhoneEntry(
"John Wood", "(913)883-2874");
}
PhoneEntry search( String targetName )
{
for (int j=0; j<phoneBook.length; j++)
{
if ( phoneBook[ j ].
name.equals( targetName))
return phoneBook[ j ];
}
return null;
}
}
Explanation / Answer
Youre full code is here,
Its a link to google doc where the code is. Hope it helps.
https://drive.google.com/file/d/0B1PCWH2ykvSBMmtGb2hLZWtMR2c/edit?usp=sharing
Regards
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.