No on this lineAddress 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 ...)
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.
No on this lineAddress 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 ...)
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.
Gamb1t (August 25th, 2011)
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; }
Ok that will solve part of the problem.
Now how will you put the Postcode object into the Address object?
Gamb1t (August 25th, 2011)
Is this in the address class again?
Yes the Address object is created by using the Address class definition.
Gamb1t (August 25th, 2011)
So in the address class i need to create a new object which is a combination of the address object and the postcode object?
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.
Gamb1t (August 25th, 2011)
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; }
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?
Gamb1t (August 25th, 2011)
i'm really confused, the data stays in the address class surely?
Yes that is where the data is saved.
How does the data get there?
Gamb1t (August 25th, 2011)
Through the set methods and the user input
If the data is making it from the user to the Address class, then are you done with it?
Gamb1t (August 25th, 2011)
Well the data then needs to be combine with the data from the name class in the contact class.
You must be more specific. What is "the data" that you use twice?
Gamb1t (August 25th, 2011)
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
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.
Gamb1t (August 25th, 2011)
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()
From post#1
2. address class - holds address details as string together with postcode.
There is no collection of contacts.
Gamb1t (August 25th, 2011)
I'm meant the addressbook class sorry
Sorry, I thought we were trying to finish up the Address class.
Finish that first before doing another class.
Gamb1t (August 25th, 2011)
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); } }
Ok. Move on to the next class.
Gamb1t (August 25th, 2011)
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"; } }