Phone List class


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: Phone List class

  1. #1
    Join Date
    Mar 2005
    Posts
    27

    Phone List class

    Can anyone help me write a PhoneList class.

    The class should have an instance method to insert names and phone numbers and a method to look up a phone number given a person's name. Since the calss will take care of looking things up, you don't have to worry about keeping the list in alphabetical order. Here is and example of such a directory.

    dad: 176-234-4676::gill g:879-243-4577::mary lancy:234-324-4567

    If anyone can help me write this then I would greatly appreciate it. Thanks.

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    What is your level of experience with programming? What do you know about the choice of and implementation of data structures? If this project is for a class, what level class is it?

  3. #3
    Join Date
    Mar 2005
    Posts
    27

    Not sure about data structures

    I am really uncertain about data structures. I am taking this java course but I really do not need it for my major. I am stuck with it since the date to drop a class passed. For this reason I would appreciate it if anyone could assist me. Is there anything else that you would like to know? Thanks!
    Last edited by none_none; 04-21-2005 at 10:31 PM.

  4. #4
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468

    Phone List class

    OK ... How much searching and sorting have you talked about?

    You are looking to design a class which holds, together, a name and a phone number - a "pair" with a "key" and "data" or "value". Frequently these objects are "nodes" in a list or a tree. If both data members are of the same data types (such as here, because you can save the phone number as a String) you can even use a 2-element array.The "nodes" can be stored in a structure of your choice - an array, a vector, an ArrayList, or another ... these structures have properties which make adding an element easy, or finding an element easy, or sorting the elements easier - - - while having problems or difficulties with other functions (arrays have difficulties adding elements at a place other than "the end") ... If reasonable, you can generate another structure which will make searching easier (faster) once created, such as a Binary Search Tree.

    The choice of how you store your data is strongly influenced by how your program is going to be used. Will your program be an address book which has all of the entries in it and your most frequent use will be searching and retrieving? Will you have a number of additions and deletions? If you're going to build your list once and search many more times, you want to maximize your ease of search. If you are going to add and delete alot and search too you will want to maximize the ease of adding/deleting, balanced with speed of searching. The "cost" of building some of these structures can pay off if you are going to build them only once but search them many times ... and don't make sense if you are going to build once and then search.

    So, based upon the likely structure of your program, it sounds to me that you will take input (from a file?) once and build your list, then find and output. If not, let us know and other formats can be suggested.

    A thought - produce a "node" class which holds a name and a phone number. You want this class implement the Comparable interface, based on the lexicographic order of names. Add the items to an array (if you know how many elements there will be) or ArrayList of NODES - if you are using 1.5, make it a generic ArrayList<Node> so that you don't have to cast objects when you add or read data. Use an insertion sort to create a lexicographic ordered sequence of nodes. Use a search of some sort ... your toString( name) or Node getPhoneNumber( name ) or String getPhoneNumber( name) method will return a a string of the data, a node (if you are returning both the name and the phone number) or the string of the phone number.

    If you want to have a much faster search, with what can be a faster build than an insertion sort if you have a large number of elements, build a Binary Search Tree.

    Do you think you can carry this off? This discussion may be overkill if you have not talked about these structures in the course. You can find a lot of info from the Java tutorials and documentation, especially the Collections classes, and even from Google searches ...
    Last edited by nspils; 04-21-2005 at 11:42 PM.

  5. #5
    Join Date
    Mar 2005
    Posts
    27

    Thanks!

    First and foremost, thank you for the reply. Most of the stuff you talk about in your reply we have not even looked at. We have not looked at nodes or most of the stuff you have posted on your reply. To be honest with you I am just trying to get through this class since it is not needed for my major. If you can assist me further then I would appreciate it much. Thanks once more. You really have been of great help.

  6. #6
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    So ... how are you going to start your class(es)? What data members? What methods? What functionality?

  7. #7
    Join Date
    Mar 2005
    Posts
    27

    Uncertain of how to start/complete this class

    To be honest with you I am really uncertain of how to start or even complete this class. I am really having so much problems with this and just want to get it over with. Hope you can assist me a little more. Thanks.

  8. #8
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    I can help you improve code you've written. I won't do your work for you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center