Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 6 of 9 FirstFirst ... 45678 ... LastLast
Results 126 to 150 of 209

Thread: Address Book Program Issues

  1. #126
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Address Book Program Issues

    Before you post any code I expect you to have compiled it and corrected any compilation errors.
    If there are no errors, don't bother to post it.
    Move to the next class.

  2. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  3. #127
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    Okay well so far there are no errors. I have no errors in my AddressBook class but i don't think it is complete.

    public class AddressBook
    {
        //index of the last entry
        private int top = 0;
        //constant number that indicates the maximum
        //number of entries in the address book
        private static final int MAXENTRIES = 10;
        //array of Address Book Entries
        private Contact[] list;
     
        /**
         * Constructor for objects of class AddressBook
         */
        public AddressBook()
        {
            list = new Contact[MAXENTRIES];
        }
     
    }

  4. #128
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Address Book Program Issues

    For any class, you need to define what the data is it will hold and how you will manipulate that data.
    What does the AddressBook class hold (its variables) and how will you manipulate that data (its methods)?

  5. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  6. #129
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    Well the data the AddressBook holds i believe is all the data in the contact class but held as the object. I presume the methods are to set and return but i'm unsure as it just needs to hold a collection of contacts. Are the methods here meant to be the addentry and so on or are they left for the textui

  7. #130
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    On the same point in my contact class i don't have any methods just the constructor, to string and the equals so my contact class surely isn't finished

  8. #131
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Address Book Program Issues

    AddressBook holds i believe is all the data in the contact class but held as the object. I presume the methods are to set and return but i'm unsure as it just needs to hold a collection of contacts.
    What methods do you need to add to do the set and return?

    Leave out the TextUI stuff.

  9. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  10. #132
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Address Book Program Issues

    class surely isn't finished
    Classes often are not finished. You will probably have to go back and add more code as the need arises.
    That's normal.
    Programming is an iterative process. Do a little here, do a little there, go back, do some more here and then some there and again and again and again.

  11. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  12. #133
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    I need to add these :

    public AddressBook(Contact contact)
        {
            this.contact = contact;
        }
     
        public Contact getContact()
        {
            return contact;
        }
        public void setContact(Contact contact)
        {
            this.contact = contact;
        }

  13. #134
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Address Book Program Issues

    How are the Contact objects stored? How will the caller of the get method describe which Contact object he wants?
    Same for the set method. What is to be set?

  14. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  15. #135
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    I'm not sure, when you create a contact object it just ask's for you to enter name and address not any of the individual data.
    With this in addressbook it will just ask you to enter something in with contact which doesn't make sense

  16. #136
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Address Book Program Issues

    What do your program assignment specifications say?

  17. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  18. #137
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    Must provide the following functionality
    1. Enable user to add contacts
    2. User to delete existing contacts
    3. User search address details based on family name
    4. List all contacts in address book

    Requirements:
    To use these classes:
    1. name class - holds the family name and others.
    2. address class - holds address details as string together with postcode.
    3. postcode class - holds typical british post codes of the form AA11 22BB.
    4. contact class - holds name and an address.
    5. addressbook class - holds collection of contacts.
    6. text ui - enable user to interact.

  19. #138
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Address Book Program Issues

    Does reading what you posted answer your question?

  20. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  21. #139
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    Well it just wants you hold the data so it should be fine i think

  22. #140
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Address Book Program Issues

    Keep going. Come back when you have an error that you don't understand.

  23. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  24. #141
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    Okay well still being unsure of my AddressBook class.
    Looking at the textui and the method addEntry it doesnt actually add to the array

    public void addEntry()
        {
        BufferedReader keyIn = new BufferedReader(new InputStreamReader(System.in));
        String forename = "";
        String surname = "";
        String street = "";
        String city = "";
        String county = "";
        String country = "";
        String post = "";
        if(top == MAXENTRIES){
            System.out.println("Address Book is full");
            return;
        }
        //asks the user for the data of the address book
        try{
            System.out.print("Forename: ");
            forename = keyIn.readLine();
            System.out.print("Surname: ");
            surname = keyIn.readLine();
            System.out.print("Street: ");
            street = keyIn.readLine();
            System.out.print("City: ");
            city = keyIn.readLine();
            System.out.print("County: ");
            county = keyIn.readLine();
            System.out.print("Country: ");
            country = keyIn.readLine();
            System.out.print("Postcode: ");
            post = keyIn.readLine();
     
        }catch(Exception e){
            System.out.println(e);
            System.exit(0);
        }
        Name name = new Name(forename, surname);
        Postcode postcode = new Postcode(post);
        Address address = new Address(street, city, county, country);
     
     }

    So i need to add this i think to the method.
    AddressBook  entry = new AddressBook  ();
        list[top] = entry;
        top++;

    It compiles fine and when i bring up the menu it works, it asks for all the inputs but i get an error when you finish the last input

    "java.lang.String.NullPointerException: null" and the line of code is -
    list[top] = entry;

  25. #142
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Address Book Program Issues

    The TextUI class needs a reference to the AddressBook object that the addEntry method can use to call a method in the AddressBook class to add the entry the addEntry method has created.

  26. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  27. #143
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    Wow statements like that make me cry haha
    So
    private AddressBook addressbook;
    is a reference to the class but not the object.

    I'm got to need it breaking down a bit more its alot to take it

  28. #144
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Address Book Program Issues

    private AddressBook addressbook;
    That defines a reference variable but does NOT give it a value.

  29. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  30. #145
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    So i need to do use a constructor and have

    public AddressTextUi(AddressBook addressbook)
    { this.addressbook = addressbook;
    }

    right?

  31. #146
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Address Book Program Issues

    I don't know what you need. What are the program's requirements?
    What class creates the AddressTextUi class?

    Think about how a user will use this program.
    What class will first start and then what will happen?

  32. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  33. #147
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    The first class that kicks it off is

    AddressBookDriver,

    public class AddressbookDriver
    {
        public static void main(String [] args)
        {
            AddressTextUi ui = new AddressTextUi();
            ui.mainMenu();
        }
     
    }

    This connects to the AddressTextUi class and launches the main menu that is found within the class.
    The main menu displays the options to the user:

    [A] ADD ENTRY
    [D] DELETE ENTRY
    [U] UPDATE ENTRY
    [V] VIEW ALL ENTRIES
    [S] SEARCH ENTRIES BY SURNAME
    [Q] Quit
    Enter desired action:

    Like so, when the user types in Q and enters the program closes and displays a message that is fine.
    When the user types A and hits enter you get this:

    Enter Contact Details:
    Forename:
    Once the forename has been entered it asks for surname and so on.
    It Also should check whether the addressbook is full if so it should display a message and go back to the main menu

  34. #148
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Address Book Program Issues

    Ok. Have you answered the question you asked in post#145
    What happens when the user enters the other options:
    D
    U
    V
    S

  35. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

  36. #149
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    With the delete entry - it checks to see whether the addressbook is empty if so displays a message and returns to main menu.
    If not then it displays all the entries of the address book with the index number, and prompts the user to enter the index number of the contact they wish to delete it then deletes and goes back to the main menu.
    Update entry i dont require and am taking it out.
    View entries - checks to see if its empty first, if not displays all the contacts in the address book

    So far i have the view and delete entries in and i think they will work but i have this error at the end of typing in the data for the addentry method so i'm not sure and need to fix that first

  37. #150
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,067
    Thanks
    47
    Thanked 2,146 Times in 2,119 Posts

    Default Re: Address Book Program Issues

    Ok keep up the good work.

  38. The Following User Says Thank You to Norm For This Useful Post:

    Gamb1t (August 25th, 2011)

Page 6 of 9 FirstFirst ... 45678 ... LastLast

Similar Threads

  1. Source code for Email address book/contacts importer
    By jega004 in forum Java Theory & Questions
    Replies: 4
    Last Post: November 23rd, 2012, 11:49 AM
  2. Issues with ascending number program
    By newtojava2011 in forum What's Wrong With My Code?
    Replies: 21
    Last Post: June 30th, 2011, 06:23 PM
  3. Address Book Help
    By clevel211 in forum Object Oriented Programming
    Replies: 4
    Last Post: November 21st, 2010, 08:42 PM
  4. How to get your computer name and IP address?
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 6
    Last Post: November 11th, 2010, 04:06 AM
  5. Array of contacts (address book)
    By smush in forum Collections and Generics
    Replies: 11
    Last Post: April 29th, 2010, 03:08 AM