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 2 of 9 FirstFirst 1234 ... LastLast
Results 26 to 50 of 209

Thread: Address Book Program Issues

  1. #26
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,974
    Thanks
    52
    Thanked 2,269 Times in 2,241 Posts

    Default Re: Address Book Program Issues

    Your constructor call (= new...) is not correct. You don't specify the datatype in the call, only the variable name.

    Why do you have the change and set methods? What do you need to do after the constructor creates the new Contact object?
    Last edited by Norm; August 24th, 2011 at 10:57 AM.

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

    Gamb1t (August 25th, 2011)

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

    Default Re: Address Book Program Issues

    Ahh i see, erm i need to invoke the methods from the other 2 classes?

  4. #28
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,974
    Thanks
    52
    Thanked 2,269 Times in 2,241 Posts

    Default Re: Address Book Program Issues

    What methods? For what reason? From what classes?

    I have no idea what you are trying to do.
    I would think a copy method would create and return a new object with the contents of the current object.

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

    Gamb1t (August 25th, 2011)

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

    Default Re: Address Book Program Issues

    I need to have a method createContact i presume that then lets you enter all the variables for the name and for the address and hold it.
    Then the addressbook class will hold a collection of these contacts in an array.
    So i should scrap the copy method. I have a copy within my address class too

  7. #30
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,974
    Thanks
    52
    Thanked 2,269 Times in 2,241 Posts

    Default Re: Address Book Program Issues

    What methods you write depends on the project's requirements.
    What class is the createContact method in? Does it return a Contact object?
    Where does it get the data it needs to create the Contact object?

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

    Gamb1t (August 25th, 2011)

  9. #31
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    Well my project's requirements is to hold a name and an address in the contact class.
    Address Book class holds a collection of contacts.

    My thought is createContact method would be in the contact class, it would get the data from the user uses the variables setup by the other classes and hold all that information

  10. #32
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,974
    Thanks
    52
    Thanked 2,269 Times in 2,241 Posts

    Default Re: Address Book Program Issues

    createContact method would be in the contact class, it would get the data from the user
    That makes sense. The code to get the data to build an object could be in the object itself.
    I have no idea what the rest of your statement means.
    uses the variables setup by the other classes and hold all that information
    What other classes and what "all that information"?
    The contact class holds references to two objects. Is there more to it than that?
    Could those two classes have create methods that get the user input needed to create and return an object?

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

    Gamb1t (August 25th, 2011)

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

    Default Re: Address Book Program Issues

    I just mean all the information from the name and address classes i think i'm confusing myself

    public void createContact(Name forename, Name surname, Address street, Address city, Address county, Address country, Postcode post)
        {
            this.forename = forename;
            this.surname = surname;
            this.street = street;
            this.city = city;
            this.county = county;
            this.country = country;
            this.post = post;
        }

    Though it can't seem to find the variable forename

  13. #34
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,974
    Thanks
    52
    Thanked 2,269 Times in 2,241 Posts

    Default Re: Address Book Program Issues

    What is the createContact method supposed to do? Does it return any value?
    What class is it to be in?

    Until you answer those questions, you can NOT write the code for the method.

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

    Gamb1t (August 25th, 2011)

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

    Default Re: Address Book Program Issues

    Well my contact class askes to hold a name and address so i think i need to have this method so it asks for the users input and holds it all.

    I'm getting really confused i only have the rest of day and tomorrow to finish this program and getting really frustrated

  16. #36
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,974
    Thanks
    52
    Thanked 2,269 Times in 2,241 Posts

    Default Re: Address Book Program Issues

    contact class askes to hold a name and address
    Yes the Contact holds a Name object and an Address object.
    You still have not answered this question:
    What is the createContact method supposed to do? Does it return any value?
    What class is it to be in?
    Why do you need a createContact method?
    You can create a Contact class object by using its constructor:
    Name aName = ... (somehow get a Name object)
    Address anAddr = ... (somehow get an Address object)
    Contact aContact = new Contact(aName, anAddr); // create an instance of the Contact class

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

    Gamb1t (August 25th, 2011)

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

    Default Re: Address Book Program Issues

    Yeah i realised now the createContact method needs to be in my addressBook class,

    So this covers all of that then?
    So i know you must be getting really frustrated and have probably repeated yourself so many times.
    Really appreciate you trying to help

    public class Contact
    {
        private Address address;   
        private Name name;  
     
        public Contact(Name name, Address address)  
        {  
            this.name = name;
            this.address = address;
        }

  19. #38
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,974
    Thanks
    52
    Thanked 2,269 Times in 2,241 Posts

    Default Re: Address Book Program Issues

    That looks like what you had back at post#23
    It should be a start on defining the class.

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

    Gamb1t (August 25th, 2011)

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

    Default Re: Address Book Program Issues

    So do i add
    Name aName = ... (somehow get a Name object)
    Address anAddr = ... (somehow get an Address object)
    Contact aContact = new Contact(aName, anAddr); // create an instance of the Contact class

    into the constructor or i need the Name aName instead of the this.name that i currently have.

  22. #40
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,974
    Thanks
    52
    Thanked 2,269 Times in 2,241 Posts

    Default Re: Address Book Program Issues

    That code I posted is only a sample for the syntax. The names I chose are arbitrary.

    Your code looks OK for a constructor to build a new object given the two objects to be added.

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

    Gamb1t (August 25th, 2011)

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

    Default Re: Address Book Program Issues

    so is my contact class fine and done or do i need something else. Sorry i really would like to get this done. I just need explicitly telling exactly what i need for each class

  25. #42
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,974
    Thanks
    52
    Thanked 2,269 Times in 2,241 Posts

    Default Re: Address Book Program Issues

    It looks good for now. Look at the assignment requirements. What do they say?
    It's not unusual for classes to have methods added to them as you progress into a project. In fact it is rare for me not to have to add more code and methods to a class as a project develops.

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

    Gamb1t (August 25th, 2011)

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

    Default Re: Address Book Program Issues

    All my requirements say are what the classes should do:
    So contact class - holds a name and an address
    Address book class which holds a collection of contacts
    Text based user interface to enable user to interact with the address book

    The addressbook needs to, enable a user to add new contacts,delete contacts, search by last name and list all contacts

  28. #44
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,974
    Thanks
    52
    Thanked 2,269 Times in 2,241 Posts

    Default Re: Address Book Program Issues

    Is the Addressbook class the main class with a loop that displays the "menu" that asks the user what he wants to do?

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

    Gamb1t (August 25th, 2011)

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

    Default Re: Address Book Program Issues

    I had it so the textUI would display the menu and the options and then they would be the methods that are in the Addressbook class

  31. #46
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,974
    Thanks
    52
    Thanked 2,269 Times in 2,241 Posts

    Default Re: Address Book Program Issues

    Ok, that sounds like a good place for the main loop.

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

    Gamb1t (August 25th, 2011)

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

    Default Re: Address Book Program Issues

    The main loop to be in the addressbook class?

  34. #48
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,974
    Thanks
    52
    Thanked 2,269 Times in 2,241 Posts

    Default Re: Address Book Program Issues

    Sorry, I meant the TextUI class sounds like a good place for the user interface

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

    Gamb1t (August 25th, 2011)

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

    Default Re: Address Book Program Issues

    Yeah,

    My addressbook class atm:

    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];
        }
     
    }

    And do i want all the methods for add entry so on in this class?

  37. #50
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    20,974
    Thanks
    52
    Thanked 2,269 Times in 2,241 Posts

    Default Re: Address Book Program Issues

    You said:
    The addressbook needs to, enable a user to add new contacts,delete contacts, search by last name and list all contacts

    Then the addressbook class will need methods to do all that.

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

    Gamb1t (August 25th, 2011)

Page 2 of 9 FirstFirst 1234 ... 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