Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are to write a program name phonedir.java that maintains a list of records c

ID: 670793 • Letter: Y

Question

You are to write a program name phonedir.java that maintains a list of records containing names and phone numbers. The program will prompt the user for a command, execute the command, then prompt the user for another command. The commands must be chosen from the following possibilities:

          a     Show all records

          d     Delete the current record

          f     Change the first name in the current record

          l     Change the last name in the current record

          n    Add a new record

          p    Change the phone number in the current record

         q     Quit

         s     Select a record from the record list to become the current record

The following example illustrates the behavior of each command (user input is in bold)

c:phonedir [enter]
A Program to keep a Phone Directory:

          a     Show all records

          d     Delete the current record

          f     Change the first name in the current record

          l     Change the last name in the current record

          n    Add a new record

          p    Change the phone number in the current record

         q     Quit

         s     Select a record from the record list to become the current record

Enter a command from the list above (q to quit):   f

No current record

           a     Show all records

          d     Delete the current record

          f     Change the first name in the current record

          l     Change the last name in the current record

          n    Add a new record

          p    Change the phone number in the current record

         q     Quit

         s     Select a record from the record list to become the current record

Enter a command from the list above (q to quit): n

Enter first name: Barry

Enter last name: Drake

Enter phone number: 770-591-8071

Current record is: Barry Drake 770-591-8071

           a     Show all records

          d     Delete the current record

          f     Change the first name in the current record

          l     Change the last name in the current record

          n    Add a new record

          p    Change the phone number in the current record

         q     Quit

         s     Select a record from the record list to become the current record

Enter a command from the list above (q to quit): n

Enter first name: Ada

Enter last name: Caswell

Enter phone number: 770-251-3456

Current record is: Ada Caswell 770-251-3456

MENU DISPLAYED AGAIN

Enter a command from the list above (q to quit): a

First Name                Last Name                      Phone Number

-------------                -------------                      ------------------

Ada                           Caswell                           770-251-3456

Barry                         Drake                              770-591-8071

MENU DISPLAYED AGAIN

Enter a command from the list above (q to quit): n

Enter first name: Elwood

Enter last name: Havens

Enter phone number: 404-345-8897

Current record is: Elwood Havens 404-345-8897

MENU DISPLAYED AGAIN

Enter a command from the list above (q to quit): a

First Name                Last Name                      Phone Number

-------------                -------------                      ------------------

Ada                           Caswell                           770-251-3456

Barry                         Drake                              770-591-8071

Elwood                      Havens                            404-345-8897


MENU DISPLAYED AGAIN

Enter a command from the list above (q to quit): f

Enter new first name: Jake

  Current record is: Jake Havens 404-345-8897

MENU DISPLAYED AGAIN

Enter a command from the list above (q to quit): s

Enter first name: Carl

Enter last name: Patton

No matching record found.
  

MENU DISPLAYED AGAIN

Enter a command from the list above (q to quit): s

Enter first name: Barry

Enter last name: Drake

  Current record is: Barry Drake 770-591-8071

MENU DISPLAYED AGAIN

Enter a command from the list above (q to quit): d

Deleted: Barry Drake 770-591-8071

MENU DISPLAYED AGAIN

Enter a command from the list above (q to quit): a

First Name                Last Name                      Phone Number

-------------                -------------                      ------------------

Ada                           Caswell                           770-251-3456

Elwood                      Havens                            404-345-8897

MENU DISPLAYED AGAIN

Enter a command from the list above (q to quit): z

Illegal command

Enter a command from the list above (q to quit): q

The output of your program must match the format illustrated in this example.

Here are some other additional requirements for this program:

You may assume that phone number contains no spaces.

After a deletion, there is no record currently selected

Each record (first name, last name and phone number) must be stored as an object. These objects must be stored in a Linked List.

The Linked List must be kept sorted at all times – based on last name. Sorting is to be achieved when an insertion or modification is done. NO SORTING ROUTINE IS ALLOWED. ALWAYS INSERT A NEW RECORD OR EDITED RECORD INTO ITS' CORRECT PLACE IN THE LINKED LIST.Note: Changing the last name will require resorting.

Use as many generic algorithm as you can.

Explanation / Answer

package phonedir3; //This program maintains a list of records that contains names and phone numbers. //The program prompts the user for a command to execute. //The user is given a list of commands to choose from. // //The "a" is used to show all of the records in the directory. //The "d" deletes a record from the directory. //The "f" will change the first name of a current record in the directory. //The "l" changes the last name of a current record in the directory. //The "n" will add a new record to the directory. //The "p" changes the phone number of the current record in the directory. //The "q" quits the program. //The "s" will select a record from the list to become the current record. import java.util.*; import java.lang.String; import java.lang.Object; public class PhoneDir { private static LinkedList phone; public static void main(String[] args) { //Display commands System.out.println("List of Commands: " + " a - Show 'a'll records " + " d - 'd'elete the current record " + " f - change the 'f'irst name in current record " + " l - change the 'l'ast name in current record " + " n - add a 'n'ew record " + " p - change the 'p'hone number in current record " + " q - 'q'uit " + " s - 's'elect a record from record list "); //Prompt user to enter a command SimpleIO.prompt("Enter a command from the list above: "); String command = (String) SimpleIO.readLine(); //Determine if command is legal. if (command.equalsIgnoreCase("a")) { showAll(); } else if (command.equalsIgnoreCase("d")) { deleteRecord(); } else if (command.equalsIgnoreCase("f")) { changeFirst(); } else if (command.equalsIgnoreCase("l")) { changeLast(); } else if (command.equalsIgnoreCase("n")) { addNew(); } else if (command.equalsIgnoreCase("p")) { changePhone(); } else if (command.equalsIgnoreCase("q")) { quit(); } else if (command.equalsIgnoreCase("s")) { selectRecord(); } else { //Illegal command will display an error message. System.out.println("Illegal command"); } System.out.println(); } //Shows all records in the directory private static void showAll(){ for (int i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote