Results 1 to 2 of 2
  1. #1
    javahelp1234 is offline Member
    Join Date
    Mar 2012
    Rep Power

    Post Help! Project

    I am stuck on this problem. Below is the question and my code:

    Consider a program to enter codes of one to eight characters along with an associated telephone number and associated notes. A code can represent a person's name, a person's initials, a place, or anything.

    By using such a program, we could enter telephone numbers or notes and associate them with some brief code (i.e. string), which hopefully would be easy to remember. We could then retrieve a given telephone number or notes by entering the code. This might be a useful application for a simple cell phone.

    Codes are entered as 1 to 8 characters.
    Use "e" for enter, "f" for find, "l" to list, "q" to quit.

    Command: e Bill
    Enter number: 419-536-1234
    Enter notes:

    Command: e JB
    Enter number: 510-0114
    Enter notes: Charlie’s place

    Command: e Jones
    Enter number: 413-257-1234
    Enter notes: Karen and Jason

    Command: e wm
    Enter number: 419-257-1234
    Enter notes: Walmart

    Command: f JB
    -- JB
    -- 617-510-0114
    -- Charlie’s place

    Command: f Jane
    ** No entry with code Jane

    Command: . . .

    There is also an "l" command, which will list all entries on the screen.

    For the input to this program, upper and lower case letters are considered equivalent. For example, if a telephone number is entered with the code "Jones", then the codes "JONES", "jones", and "JONes" will all retrieve the telephone number entered with "Jones".

    The entries are to be stored in a file from run to run. When the program begins, the entries in the file are to be read into an array. The array should allow for up to 100 entries. The array MUST be kept in alphabetical order. You may use a simple sequential search to retrieve entries.

    When the program is exited, the entries should be stored back in a file for use when the program is run again.

    Required Program Characteristics: The assignment is to write a program that incorporates the above features. The entries in the phonebook are to be represented with a class:
    class Entry {
    public String name, number, notes;
    Use an array to store the entries. The array should allow for up to 100 entries.
    public Entry[] entryList = new Entry[100];
    As mentioned above, the array must be kept in alphabetical order. When a new entry is to be made, find the appropriate location in the array, move the entries at this location and higher up by one, and insert the new entry.
    Use a static method to read the entries into the program from a file, and a static method to store the entries back into the file when the program is exited.
    public static void readPhoneBook (String FileName)
    throws Exception
    public static void storePhoneBook (String FileName)
    throws Exception

    Also, use a static method to list all entries:
    public static void listAllEntriess()

    My Program:

    Java Code:
    import java.util.Scanner;
    public class PhoneBook {
      private PhoneBookEntry[] book;
      private int cur_entry;
      public PhoneBook() {
        book = new PhoneBookEntry[100];
        cur_entry = 0;
      public boolean full() {
        return (cur_entry == 100);
      public boolean add(PhoneBookEntry a) {
        if (cur_entry == 100) return false;
        book[cur_entry] = a;
        return true;
      public void printBook() {
        System.out.println("Here are all the current entries: ");
        for (int i=0; i<cur_entry; i++) 
          System.out.println(i+". "+book[i]);
      public void search(String name) {
        for (int i=0; i<cur_entry; i++) 
          if (book[i].sameName(name))
            System.out.println(i+". "+book[i]);
      public int searchNumMatches(String name){
    	  int count = 0;
    	  for (int i=0; i<cur_entry; i++)
    		  if (book[i].sameName(name))
    	  return count;
      public int getIndex(String name) {
        for (int i=0; i<cur_entry; i++) 
          if (book[i].sameName(name))
            return i;
        return -1;
      public static void menu() {
        System.out.println("Codes are entered as 1 to 8 characters.");
        System.out.println("'e' for enter");
        System.out.println("'l' to list");
        System.out.println("'f' for find");
        System.out.println("'q' to quit");
      public static void main(String[] args) throws IOException {
        Scanner stdin = new Scanner(;
        PhoneBook book = new PhoneBook();
        int command = stdin.nextInt();
        int q;
        while (command != q) {
          int e,l,f;
    	if (command == e ) 
            if (book.full()) 
              System.out.print("Sorry, the phonebook is full, no entry can be added!");  
              PhoneBookEntry a = PhoneBookEntry.getEntry();
              System.out.println("The entry has been added.");
          else if (command == l)
          else if (command == f) {
            System.out.println("Enter code you want to search: ");
            String last =;
            if (book.searchNumMatches(last) > 0) {
              System.out.println("Here are the entries the matched your search: ");
              System.out.println("Sorry, NO entries matched your search!");
          command = stdin.nextInt();
    Last edited by javahelp1234; 03-30-2012 at 12:15 AM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default Re: Help! Project

    Below is the question
    Sorry, I can not see your question. Can point it out or repeat it?
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Phonebook HashMap Example
    By forms in forum New To Java
    Replies: 3
    Last Post: 01-23-2012, 07:09 PM
  2. Creating a project in eclipse from existing project
    By Suraiya in forum New To Java
    Replies: 1
    Last Post: 10-08-2011, 09:14 AM
  3. Java Phonebook With Arrays // HELP! //
    By K-Scale in forum New To Java
    Replies: 9
    Last Post: 10-04-2011, 03:41 AM
  4. phonebook update
    By nanna in forum New To Java
    Replies: 5
    Last Post: 03-09-2009, 10:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts