Java Address Book
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Java Address Book

  1. #1
    Join Date
    Jun 2011
    Posts
    2

    Java Address Book

    Ok first off, yes I am a student and this is a project I am working on for class. Second, I am new to programming but so far I enjoy it and look forward to learning more. Third I am not looking for someone to do my work for me I just need help and feedback.*

    Now what I am stuck on is making my menu options work (add new entry, delete, search, display, and exit), a loop for the menu options, at least one method, and two looping methods. Again I am not looking for you to do this for me I just want feedback and tips because again I do like this and I want to get more into programming.*

    Here is my code:

    package address_book;
    import java.util.Scanner;


    *public class Address_book*
    {

    public static void main(String[] args)*
    {
    Scanner input = new Scanner(System.in);
    ** * **
    //create matrix table to hold information
    String[][] AddressBook = new String[100][8];
    ** * * **
    AddressBook[0][0]="Contact Number";
    AddressBook[0][1]="First Name";
    AddressBook[0][2]="Last Name";
    AddressBook[0][3]="Address";
    AddressBook[0][4]="City";
    AddressBook[0][5]="State";
    AddressBook[0][6]="Zip";
    AddressBook[0][7]="Telephone Number";
    ** * * *
    //pre populate address book for testing purposes and records
    AddressBook[1][0]="1";
    AddressBook[1][1]="Adam";
    AddressBook[1][2]="West";
    AddressBook[1][3]="1 Batcave Lane";
    AddressBook[1][4]="Gotham City";
    AddressBook[1][5]="NY";
    AddressBook[1][6]="12345";
    AddressBook[1][7]="123-456-7890";
    ** * * *
    AddressBook[2][0]="2";
    AddressBook[2][1]="John";
    AddressBook[2][2]="Doe";
    AddressBook[2][3]="1234 Any Street";
    AddressBook[2][4]="Anytown";
    AddressBook[2][5]="PA";
    AddressBook[2][6]="12345";
    AddressBook[2][7]="412-555-1234";
    ** * * * **
    //menu options
    System.out.print("Menu");
    System.out.print("\n1-Insert a New Contact \n2-Search Contact by Last Name \n3-Delete Contact \n4-Show All Contacts \n5-Exit " );*
    System.out.print("\nChoose your option: ");
    int option = input.nextInt();
    ** * * * * * *
    if (option ==1)
    ** * * * * *{
    ** * * * * *}
    ** * * *
    if (option ==2)
    ** * * * * *{
    ** * * * * *}
    ** * * *
    ** * * *if (option ==3)
    ** * * * * *{
    ** * * * * *}
    *
    if (option ==4)
    ** * * * * *{
    ** * * * * * * *System.out.println(AddressBook[1][0]+*
    "\t"+AddressBook[1][2]+ ", "+AddressBook[1][1]+*
    "\n\t"+AddressBook[1][3]+*
    "\n\t"+AddressBook[1][4]+ ", "+AddressBook[1][5]+ " "+AddressBook[1][6]+*
    "\n\t"+AddressBook[1][7]);
    ** * * * * *}
    ** * * *
    if (option ==5)
    ** * * * * *{
    ** * * * * *}
    ** * * *
    ** *}
    }

  2. #2
    Join Date
    Jun 1999
    Location
    SW Missouri
    Posts
    3,426

    Re: Java Address Book

    Code:
    stuck on is making my menu options work
    Take them one by one.
    What should the code do to insert a new Address?
    Here is how I do it with objects:
    1) get the data from the user
    2) create a new Address object
    3) add that new object to the container
    Since you are using an array, your approach will be different
    One thing I'd do with your code is to define final int values for the indexes to the array.
    For example:
    final int ContactNbrIx = 0;
    final int FirstNameIx = 1;
    ...
    final int PhoneNbrIx = 7;
    Then replace all the hardcoded magic numbers with these variables:

    AddressBook[2][PhoneNbrIx]="412-555-1234";

    Using variables you will be less likely to make a mistake later in the program when you want to see a particular value.
    You wouldn't code: AddressBook[ix][PhoneNbrIx] when you want the zip code,
    but you could code this: AddressBoox[ix][7] and not know what value you are referencing.
    Last edited by Norm; June 24th, 2011 at 08:38 AM.
    Norm

  3. #3
    Join Date
    Jun 2011
    Posts
    2

    Re: Java Address Book

    Thanks for the feed back Norm. I appreciate any and all help.

  4. #4
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: Java Address Book

    Quote Originally Posted by dmacpgh82 View Post
    I appreciate any and all help.
    You may not have covered this yet, but arrays, being a fixed size, are not best suited to handling variable amounts of data, such as an address book. They're best reserved for fixed size data, such as days-of-the-week, months-of-the-year, countries, states, colors, planets, etc. For variable amounts of data, one of the Collection classes should be used - e.g. ArrayList. These allow you to add and/or remove as many items as you need without worrying about their size.

    We flew down weekly to meet with IBM, but they thought the way to measure software was the amount of code we wrote, when really the better the software, the fewer lines of code...
    Bill Gates
    Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

Tags for this Thread

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center