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 5 of 9 FirstFirst ... 34567 ... LastLast
Results 101 to 125 of 209

Thread: Address Book Program Issues

  1. #101
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    No on this line
    Address address = new Address(street, city, county, country);

    Inside the addEntry method it says "cannot find symbol - constructor address(java.lang.String, java.lang.String, java.lang.String ...)

  2. #102
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Address Book Program Issues

    Look at the definition for the Address class. Does it have a constructor that matches the one you are using here:
    Address address = new Address(street, city, county, country);

    You need to
    either change the above line to match an existing constructor in the Address class
    or add a new constructor to the Address class that matches the above.

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

    Gamb1t (August 25th, 2011)

  4. #103
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    Ahh i see it's becasue the constructor i had in my address class was:

    public Address(String street, String city, String county, String country, Postcode post)
        {
            this.street = street;
            this.city = city;
            this.county = county;
            this.country = country;
            this.post = post;
        }

    So i created another constructor
     public Address(String street, String city, String county, String country)
        {
            this.street = street;
            this.city = city;
            this.county = county;
            this.country = country;
        }

  5. #104
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Address Book Program Issues

    Ok that will solve part of the problem.
    Now how will you put the Postcode object into the Address object?

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

    Gamb1t (August 25th, 2011)

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

    Default Re: Address Book Program Issues

    Is this in the address class again?

  8. #106
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Address Book Program Issues

    Yes the Address object is created by using the Address class definition.

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

    Gamb1t (August 25th, 2011)

  10. #107
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    So in the address class i need to create a new object which is a combination of the address object and the postcode object?

  11. #108
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Address Book Program Issues

    No, the Address class holds data for the address. Part of that data is the Postcode.
    Where do you first get the data for creating the Postcode object?
    That is where you should create the Postcode object and then pass that Postcode object to the Address class via the Address class's constructor.

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

    Gamb1t (August 25th, 2011)

  13. #109
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    The data for the postcode object is within the postcode class.
    The postcode object is already being created in the class isn't it. And i thought i had passed it to the address class using

    private Postcode post;
    public Address(String street, String city, String county, String country, Postcode post)
        {
            this.street = street;
            this.city = city;
            this.county = county;
            this.country = country;
            this.post = post;
        }

  14. #110
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Address Book Program Issues

    What you show in post#109 is where the Address class RECEIVES that data.
    Where do you SEND the data to the Address class by calling its constructor with the new statement?

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

    Gamb1t (August 25th, 2011)

  16. #111
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    i'm really confused, the data stays in the address class surely?

  17. #112
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Address Book Program Issues

    Yes that is where the data is saved.
    How does the data get there?

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

    Gamb1t (August 25th, 2011)

  19. #113
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    Through the set methods and the user input

  20. #114
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Address Book Program Issues

    If the data is making it from the user to the Address class, then are you done with it?

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

    Gamb1t (August 25th, 2011)

  22. #115
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    Well the data then needs to be combine with the data from the name class in the contact class.

  23. #116
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Address Book Program Issues

    You must be more specific. What is "the data" that you use twice?

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

    Gamb1t (August 25th, 2011)

  25. #117
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    As you said the data is created from the user and saved in the address class. The same thing happens in the name class to store the data for the name. The contact class needs to store both sets of data too as well doesn't it?
    I'm going round in circles arn't i

  26. #118
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Address Book Program Issues

    I thought you were done with the Contact class and only had one small bit to do to finish the Address class.
    Why not finish one thing at a time. Finish the Address class.

    You need to get straight what goes into each class.
    Take a piece of paper and make a list for each of the classes of what data items go into that class.

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

    Gamb1t (August 25th, 2011)

  28. #119
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    I'd tried doing that this morning creating a class diagram with the what i need for each class but got stuck when it came to the contact, address and textui classes

    For contact i just had this:

    Contact

    -name: Name
    -address: Address

    +Contact(Name name, Address address)

    Address - I understand holds a collection of contacts so i require an array

    Address

    -list: Contact[]
    -contact: Contact

    +AddressBook()

  29. #120
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Address Book Program Issues

    From post#1
    2. address class - holds address details as string together with postcode.

    There is no collection of contacts.

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

    Gamb1t (August 25th, 2011)

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

    Default Re: Address Book Program Issues

    I'm meant the addressbook class sorry

  32. #122
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Address Book Program Issues

    Sorry, I thought we were trying to finish up the Address class.
    Finish that first before doing another class.

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

    Gamb1t (August 25th, 2011)

  34. #123
    Member
    Join Date
    Aug 2011
    Posts
    106
    Thanks
    81
    Thanked 0 Times in 0 Posts

    Default Re: Address Book Program Issues

    I thought it was finished, okay well it needs to hold the address details as a string together with a postcode.

    What have i missed or what is there that i don't need i really thought it was done

    public class Address
    {
        private String street;
        private String city;
        private String county;
        private String country;
        private Postcode post;
     
        public Address()
        {
     
        }
     
         public Address(String street, String city, String county, String country)
        {
            this.street = street;
            this.city = city;
            this.county = county;
            this.country = country;
        }
     
        public Address(String street, String city, String county, String country, Postcode post)
        {
            this.street = street;
            this.city = city;
            this.county = county;
            this.country = country;
            this.post = post;
        }
     
     
        public String getStreet()
        {
            return street;
        }
        public void setStreet(String street)
        {
            this.street = street;
        }
     
        public String getCity()
        {
            return city;
        }
        public void setCity(String city)
        {
            this.city = city;
        }
     
        public String getCounty()
        {
            return county;
        }
        public void setCounty(String county)
        {
            this.county = county;
        }
     
         public String getCountry()
        {
            return country;
        }
        public void setCountry(String country)
        {
            this.country = country;
        }
     
        public void setPost(Postcode post)  
        {  
            this.post = post;  
        }
        public Postcode getPost()
        {
            return post;
        }
     
     
     
        @Override
            public boolean equals(Object obj) {
                    if (this == obj)
                            return true;
     
                            if (obj == null)
                            return false;
     
                            if (getClass() != obj.getClass())
                            return false;
     
                            Address other = (Address) obj;
     
                            if (city == null) {
                            if (other.city != null)
                                    return false;
                    } else if (!city.equals(other.city))
                            return false;
     
                            if (county == null) {
                            if (other.county != null)
                                    return false;
                    } else if (!county.equals(other.county))
                            return false;
     
                                    if (country == null) {
                            if (other.country != null)
                                    return false;
                    } else if (!country.equals(other.country))
                            return false;
     
                            if (street == null) {
                            if (other.street != null)
                                    return false;
                    } else if (!street.equals(other.street))
                            return false;
     
                            if (post == null) {
                            if (other.post != null)
                                    return false;
                    } else if (!post.equals(other.post))
                            return false;
     
                    return true;
            }
     
        @Override
            public String toString() {
                    return String.format(
                                    "Street Address: %s, City: %s, County: %s, Country %s, Postcode: %s", street, city, county, country, post);
            }
     
        public Address copy() {
                    Address address = new Address();
                    address.setStreet(this.getStreet());
                    address.setCity(this.getCity());
                    address.setCounty(this.getCounty());
                    address.setCountry(this.getCountry());
                    address.setPost(this.getPost());
                    return address;
        }
     
        public void printAll() {
            System.out.println(this);
        }
     
    }

  35. #124
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Address Book Program Issues

    Ok. Move on to the next class.

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

    Gamb1t (August 25th, 2011)

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

    Default Re: Address Book Program Issues

    Okay the next is the Contact class - which needs to hold a name and an address

    public class Contact
    {
        private Address address;   
        private Name name;
     
        public Contact(Name name, Address address)  
        {  
            this.name = name;
            this.address = address;
        }     
     
        @Override  
        public boolean equals(Object obj) {  
            if (this == obj)  
                return true;  
            if (obj == null)  
                return false;  
            if (getClass() != obj.getClass())  
                return false;  
            Contact other = (Contact) obj;  
            if (address == null) {  
                if (other.address != null)  
                    return false;  
            } else if (!address.equals(other.address))  
                return false;  
     
            if (name == null) {  
                if (other.name != null)  
                    return false;  
            } else if (!name.equals(other.name))  
                return false;  
            return true;  
        }  
     
        @Override  
        public String toString() {  
            return super.toString() + "\n" + address + "\n" + name + "\n";  
        }  
     
    }

Page 5 of 9 FirstFirst ... 34567 ... 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, 12:49 PM
  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, 09: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, 05: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