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

write pseudocode to design a phone contact list program. Your program includes a

ID: 3835102 • Letter: W

Question

write pseudocode to design a phone contact list program. Your program includes a Graphical User Interface that allows user to add new contacts, update existing contacts, search specific contact from the contact list, sort the contact list in ascending or descending order, delete an old contact. Your program should also provide help screen, an exit button to close the program and displays error messages for any exceptions.

Write a data text file with a list of phone number (10 digits with dashes, 555-555-5555)

Read text file to retrieve contact info (phone number, first name, last name)

Read the file into memory (hint: parallel arrays)

Individual contact info can also be entered from the keypad

Process: (open/read the file, display the menu, close file)

Maintain the phone list by ADD, UPDATE, DELETE, INQUIRE/SEARCH, SORTING

When each item on the menu is done, redisplay the menu

Output: (per each navigation menu item)

Design a GUI screen that include

Keypad with numbers

Navigation menu

Add New Contact ( textbox for first name, last name, textbox for phone number)

Update Contact (search by phone number to display name and phone OR search by name to display name and phone number)

Delete Contact from List (change name to blank)

Inquire: enter phone name or name

List: Sort list either ascending or descending order by first name or last name

Help

Save phone list

Exit

Define a CONTACT class

Fields (phone number, first name, last name)

Set & get method

Constructor

Methods (add, update, delete, save, sort, display the list etc. )

Object: personal contact list Or company phone directory (inheritance)

Public class PersonalContact extends Contact { }

Add:

Enter phone number (phone number: range 1-999)

If not found – display message

If name is blank, enter name (first and last)

If name NOT blank, save contact info, display confirm message

Change:

Enter phone number

If not found – display message

IF found – display name and ask for new name

If name is blank, ask for new name

Delete:

Enter phone number

If not found – display message

If found – display name and confirm delete

                  If confirm is yes – blank out name

                  If confirm is no – return to menu

If name is blank, display message

Inquire:

Enter phone number

If found – display name

If not found – display message

If found and name is blank – display message

Sort:

Question: sort ascending, descending or return to menu

If return to menu, then return to menu

If ascending- sort phone number ascending

If descending - sort phone number in descending order

After sort, display phone list

Help:

Display menu option and a one description of the function

Save:

Write phone list back to file

Exit:

If file is open, save phone list, close file

Terminate program

Error:

If a menu selection is made that is not displayed (1-9)

Issue message and display the help screen

This is my project and i need a Pseudocode of this program

Explanation / Answer

the code is given below :

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.IOException;
import java.util.Observer;
import java.util.Observable;

/**   An object of this class allows interaction between the program and the
*   human user.
*/
public class ContactBookGUI extends JFrame implements Observer
{
/** Constructor
*
*   @param controller the controller which performs operations in
*       response to user gestures on this GUI
*   @param ContactBook the ContactBook this GUI displays
*/

public ContactBookGUI(final ContactBookController controller,
                   ContactBook ContactBook)
{
       this.controller = controller;
      
// Create and add file menu
  
JMenuBar menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("File");
newItem = new JMenuItem("New", 'N');
fileMenu.add(newItem);
openItem = new JMenuItem("Open...", 'O');
fileMenu.add(openItem);
fileMenu.addSeparator();
saveItem = new JMenuItem("Save", 'S');
fileMenu.add(saveItem);
saveAsItem = new JMenuItem("Save As...");
fileMenu.add(saveAsItem);
fileMenu.addSeparator();
printItem = new JMenuItem("Print", 'P');
fileMenu.add(printItem);
fileMenu.addSeparator();
quitItem = new JMenuItem("Quit", 'Q');
fileMenu.add(quitItem);
menuBar.add(fileMenu);
setJMenuBar(menuBar);
  
       // The displayed list of names gets its information from the
       // Contact book
      
       nameListModel = new NameListModel();
              
       // The nameListModel and saveItem objects must exist before this is done;
       // but this must be done before the nameList is created
      
       setContactBook(ContactBook);  
      
// Create and add components for the main window
  
nameList = new JList(nameListModel);
JScrollPane listPane = new JScrollPane(nameList);
nameList.setVisibleRowCount(10);
listPane.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(10, 10, 10, 10),
BorderFactory.createLineBorder(Color.gray, 1)));
getContentPane().add(listPane, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel();
addButton = new JButton(" Add ");
buttonPanel.add(addButton);
editButton = new JButton(" Edit ");
buttonPanel.add(editButton);
deleteButton = new JButton(" Delete ");
buttonPanel.add(deleteButton);
sortByNameButton = new JButton("Sort by name");
buttonPanel.add(sortByNameButton);
sortByZipButton = new JButton("Sort by ZIP ");
buttonPanel.add(sortByZipButton);
buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 10, 10, 10));
  
getContentPane().add(buttonPanel, BorderLayout.SOUTH);
  
// Add the action listeners for the buttons, menu items, and close box,
// and for double-clicking the list
  
addButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
   controller.doAdd(ContactBookGUI.this);
   int index = getContactBook().getNumberOfPersons() - 1;
   // This will ensure that the person just added is visible in list
   nameList.ensureIndexIsVisible(index);
}
});
  
editButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
               int index = nameList.getSelectedIndex();
               if (index < 0)
                   reportError("You must select a person");
               else
                   controller.doEdit(ContactBookGUI.this, index);
}
});
  
deleteButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
   int index = nameList.getSelectedIndex();
                if (index < 0)
                   reportError("You must select a person");
               else
    controller.doDelete(ContactBookGUI.this, index);
}
});
  
sortByNameButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
   controller.doSortByName(ContactBookGUI.this);
}
});
  
sortByZipButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
               controller.doSortByZip(ContactBookGUI.this);
}
});
  
newItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
               try
               {
                   if (getContactBook().getChangedSinceLastSave())
                       controller.doOfferSaveChanges(ContactBookGUI.this);
              
                   controller.doNew(ContactBookGUI.this);
               }
   catch(IOException exception)
   {
       reportError("Problem writing the file: " +
                   exception);
   }
   catch(InterruptedException exception)
   {
       // Thrown if user cancels a save or a file dialog - can be ignored
   }
               catch(SecurityException exception)
               {
                   // Thrown if security manager disallows the operation -
                   // will always happen in an applet
                  
                   reportError("Operation disallowed: " + exception);
               }
}
});
  
openItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
               try
               {
                   if (getContactBook().getChangedSinceLastSave())
                       controller.doOfferSaveChanges(ContactBookGUI.this);
              
       controller.doOpen(ContactBookGUI.this);
   }
   catch(IOException exception)
   {
       reportError("Problem reading or writing the file: " +
                   exception);
   }
   catch(InterruptedException exception)
   {
       // Thrown if user cancels a save or a file dialog - can be ignored
   }
               catch(SecurityException exception)
               {
                   // Thrown if security manager disallows the operation -
                   // will always happen in an applet
                  
                   reportError("Operation disallowed: " + exception);
               }
   catch(Exception exception)
   {
       // Any other case means the file did not contain an
       // Contact book

       reportError("This file did not contain an Contact book");
   }  
}
});
  
saveItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
   try
   {
       controller.doSave(ContactBookGUI.this);
   }
    catch(IOException exception)
   {
       reportError("Problem writing the file: " +
                   exception);
   }
   catch(InterruptedException exception)
   {
       // Thrown if user cancels a file dialog - can be ignored
   }
               catch(SecurityException exception)
               {
                   // Thrown if security manager disallows the operation -
                   // will always happen in an applet
                  
                   reportError("Operation disallowed: " + exception);
               }
}
});
  
saveAsItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
   try
   {
       controller.doSaveAs(ContactBookGUI.this);
   }
    catch(IOException exception)
   {
       reportError("Problem writing the file: " +
                   exception);
   }
   catch(InterruptedException exception)
   {
       // Thrown if user cancels a file dialog - can be ignored
   }
               catch(SecurityException exception)
               {
                   // Thrown if security manager disallows the operation -
                   // will always happen in an applet
                  
                   reportError("Operation disallowed: " + exception);
               }
}
});
  
printItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
               controller.doPrint(ContactBookGUI.this);
           }
});
  
quitItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
               ContactBookApplication.quitApplication();
           }
});
  
       setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e)
{
               try
               {
                   if (getContactBook().getChangedSinceLastSave())
                       controller.doOfferSaveChanges(ContactBookGUI.this);

                   dispose();
                  
                   if (Frame.getFrames().length == 0)
                       ContactBookApplication.quitApplication();
               }
    catch(IOException exception)
   {
       reportError("Problem writing the file: " +
                   exception);
   }
   catch(InterruptedException exception)
   {
       // Thrown if user cancels a file dialog - can be ignored
   }
               catch(SecurityException exception)
               {
                   // Thrown if security manager disallows the operation -
                   // will always happen in an applet
                  
                   reportError("Operation disallowed: " + exception);
               }
              
}
});
  
        // The following is adapted from an example in the documentation
        // for class JList. It invokes the controller's doEdit method
        // if the user double clicks a name.
       
       nameList.addMouseListener(new MouseAdapter() {
           public void mouseClicked(MouseEvent e)
           {
               if (e.getClickCount() == 2)
               {
                   int index = nameList.locationToIndex(e.getPoint());
                   controller.doEdit(ContactBookGUI.this, index);
               }
           }
        });
       
        pack();   
}
  
   /** Accessor for the Contact book this GUI displays
   *
   *   @return the current Contact book for this GUI
   */
   public ContactBook getContactBook()
   {
       return ContactBook;
   }
  
   /** Mutator to change the Contact book this GUI displays
   *
   *   @param ContactBook the new Contact book for this GUI
   */
   public void setContactBook(ContactBook ContactBook)
   {
       if (this.ContactBook != null)
           this.ContactBook.deleteObserver(this);
          
       this.ContactBook = ContactBook;
       ContactBook.addObserver(this);
       update(ContactBook, null);
   }
  
/** Report an error to the user
*
* @param message the message to display
*/
public void reportError(String message)
{
JOptionPane.showMessageDialog(this, message, "Error message",
JOptionPane.ERROR_MESSAGE);
}
  
   /** Method required by the Observer interface - update the display
   *   in response to any change in the Contact book
   */
   public void update(Observable o, Object arg)
   {
       if (o == ContactBook)
       {
           setTitle(ContactBook.getTitle());
           saveItem.setEnabled(ContactBook.getChangedSinceLastSave());
           nameListModel.contentsChanged();
       }
   }
          
// GUI components and menu items
  
   private NameListModel nameListModel;
private JList nameList;
private JButton addButton, editButton, deleteButton, sortByNameButton, sortByZipButton;
private JMenuItem newItem, openItem, saveItem, saveAsItem, printItem, quitItem;
  
   // The controller that performs operations in response to user gestures
  
   private ContactBookController controller;
  
   // The Contact book this GUI displays / operates on
  
   private ContactBook ContactBook;
  
   /** Class used for the model for the list of persons in the Contact book
   */
   private class NameListModel extends AbstractListModel
   {
       /** Report that the contents of the list have changed
       */
       void contentsChanged()
       {
           super.fireContentsChanged(this, 0, 0);
       }
      
       // Implementation of abstract methods of the base class
      
       public Object getElementAt(int index)
       {
           return getContactBook().getFullNameOfPerson(index);
       }

       public int getSize()
       {
           return getContactBook().getNumberOfPersons();
       }
   }
}